idn have to be converted before being used
This commit is contained in:
parent
abdc823bb6
commit
fb7f3008d3
2 changed files with 47 additions and 0 deletions
|
@ -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);
|
||||
|
@ -125,6 +126,22 @@ class OC_Mail {
|
|||
* @return bool
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
30
tests/lib/mail.php
Normal file
30
tests/lib/mail.php
Normal file
|
@ -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 a new issue