Merge pull request #7861 from owncloud/idn-domains-support-on-emails-master
idn have to be converted before being used
This commit is contained in:
commit
531c9564b3
|
@ -73,6 +73,7 @@ class OC_Mail {
|
|||
$mailo->FromName = $fromname;;
|
||||
$mailo->Sender = $fromaddress;
|
||||
try {
|
||||
$toaddress = self::buildAsciiEmail($toaddress);
|
||||
$mailo->AddAddress($toaddress, $toname);
|
||||
|
||||
if($ccaddress<>'') $mailo->AddCC($ccaddress, $ccname);
|
||||
|
@ -124,7 +125,23 @@ class OC_Mail {
|
|||
* @param string $emailAddress a given email address to be validated
|
||||
* @return bool
|
||||
*/
|
||||
public static function ValidateAddress($emailAddress) {
|
||||
public static function validateAddress($emailAddress) {
|
||||
$emailAddress = self::buildAsciiEmail($emailAddress);
|
||||
return PHPMailer::ValidateAddress($emailAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDN domains will be properly converted to ascii domains.
|
||||
*
|
||||
* @param string $emailAddress
|
||||
* @return string
|
||||
*/
|
||||
public static function buildAsciiEmail($emailAddress) {
|
||||
|
||||
list($name, $domain) = explode('@', $emailAddress, 2);
|
||||
$domain = idn_to_ascii($domain);
|
||||
|
||||
return "$name@$domain";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ class Util {
|
|||
$host_name = \OC_Config::getValue('mail_domain', $host_name);
|
||||
$defaultEmailAddress = $user_part.'@'.$host_name;
|
||||
|
||||
if (\OC_Mail::ValidateAddress($defaultEmailAddress)) {
|
||||
if (\OC_Mail::validateAddress($defaultEmailAddress)) {
|
||||
return $defaultEmailAddress;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ OCP\JSON::callCheck();
|
|||
$l=OC_L10N::get('core');
|
||||
|
||||
// Get data
|
||||
if( isset( $_POST['email'] ) && filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL) ) {
|
||||
if( isset( $_POST['email'] ) && OC_Mail::validateAddress($_POST['email']) ) {
|
||||
$email=trim($_POST['email']);
|
||||
OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email);
|
||||
OC_JSON::success(array("data" => array( "message" => $l->t("Email saved") )));
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
class Test_Mail extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider buildAsciiEmailProvider
|
||||
* @param $expected
|
||||
* @param $address
|
||||
*/
|
||||
public function testBuildAsciiEmail($expected, $address) {
|
||||
$actual = \OC_Mail::buildAsciiEmail($address);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
function buildAsciiEmailProvider() {
|
||||
return array(
|
||||
array('info@example.com', 'info@example.com'),
|
||||
array('info@xn--cjr6vy5ejyai80u.com', 'info@國際化域名.com'),
|
||||
array('info@xn--mller-kva.de', 'info@müller.de'),
|
||||
array('info@xn--mller-kva.xn--mller-kva.de', 'info@müller.müller.de'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue