diff --git a/EmailValidator/Validation/DNSCheckValidation.php b/EmailValidator/Validation/DNSCheckValidation.php index 830cc57..ee602c9 100644 --- a/EmailValidator/Validation/DNSCheckValidation.php +++ b/EmailValidator/Validation/DNSCheckValidation.php @@ -27,10 +27,10 @@ public function isValid($email, EmailLexer $emailLexer) { // use the input to check DNS if we cannot extract something similar to a domain $host = $email; + // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email - $pattern = "/^[a-z'0-9]+([+._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+)+)+$/"; - if (preg_match($pattern, $email, $result)) { - $host = $this->extractHost($result); + if (false !== $lastAtPos = strrpos($email, '@')) { + $host = substr($email, $lastAtPos + 1); } return $this->checkDNS($host); @@ -46,16 +46,6 @@ public function getWarnings() return $this->warnings; } - private function extractHost(array $result) - { - foreach ($result as $match) { - $onlyDomainPattern = "/^([a-z0-9]+([._-][a-z0-9]+))+$/"; - if (preg_match($onlyDomainPattern, $match, $domainResult)) { - return $domainResult[0]; - } - } - } - protected function checkDNS($host) { $Aresult = true; @@ -63,7 +53,7 @@ protected function checkDNS($host) if (!$MXresult) { $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord(); - $Aresult = checkdnsrr($host, 'A'); + $Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'); if (!$Aresult) { $this->error = new NoDNSRecord(); } diff --git a/Tests/EmailValidator/Validation/DNSCheckValidationTest.php b/Tests/EmailValidator/Validation/DNSCheckValidationTest.php index b75c2c6..105de80 100644 --- a/Tests/EmailValidator/Validation/DNSCheckValidationTest.php +++ b/Tests/EmailValidator/Validation/DNSCheckValidationTest.php @@ -12,8 +12,17 @@ class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase public function validEmailsProvider() { return [ - ["example@example.com"], - ["example+foo@example.com"], + // dot-atom + ['Abc@example.com'], + ['ABC@EXAMPLE.COM'], + ['Abc.123@example.com'], + ['user+mailbox/department=shipping@example.com'], + ['!#$%&\'*+-/=?^_`.{|}~@example.com'], + + // quoted string + ['"Abc@def"@example.com'], + ['"Fred\ Bloggs"@example.com'], + ['"Joe.\\Blow"@example.com'], ]; }