From aecbe5892dda23f0092b7ba087a819ba2f58cd95 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Sat, 29 Nov 2014 16:55:04 +0100 Subject: [PATCH] Zend_Validate_EmailAddress: IDN domains are converted to punnycode if possible Fixes #62 --- library/Zend/Validate/EmailAddress.php | 9 ++++++++- tests/Zend/Validate/EmailAddressTest.php | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library/Zend/Validate/EmailAddress.php b/library/Zend/Validate/EmailAddress.php index fd6701d4b6..4a33527f46 100644 --- a/library/Zend/Validate/EmailAddress.php +++ b/library/Zend/Validate/EmailAddress.php @@ -449,7 +449,14 @@ private function _validateLocalPart() private function _validateMXRecords() { $mxHosts = array(); - $result = getmxrr($this->_hostname, $mxHosts); + $hostname = $this->_hostname; + + //decode IDN domain name if possible + if (function_exists('idn_to_ascii')) { + $hostname = idn_to_ascii($this->_hostname); + } + + $result = getmxrr($hostname, $mxHosts); if (!$result) { $this->_error(self::INVALID_MX_RECORD); } else if ($this->_options['deep'] && function_exists('checkdnsrr')) { diff --git a/tests/Zend/Validate/EmailAddressTest.php b/tests/Zend/Validate/EmailAddressTest.php index b9c64f50b6..439de5f84b 100644 --- a/tests/Zend/Validate/EmailAddressTest.php +++ b/tests/Zend/Validate/EmailAddressTest.php @@ -622,6 +622,19 @@ public function testNotSetHostnameValidator() $hostname = $this->_validator->getHostnameValidator(); $this->assertTrue($hostname instanceof Zend_Validate_Hostname); } + + /** + * @group GH-62 + */ + public function testIdnHostnameInEmaillAddress() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->markTestSkipped('idn_to_ascii() is available in intl in PHP 5.3.0+'); + } + $validator = new Zend_Validate_EmailAddress(); + $validator->setValidateMx(true); + $this->assertTrue($validator->isValid('testmail@detrèsbonsdomaines.com')); + } } if (PHPUnit_MAIN_METHOD == 'Zend_Validate_EmailAddressTest::main') {