fixed some problems in DNSCheckValidation (#116)

This commit is contained in:
Issei.M
2016-06-25 07:43:29 +09:00
committed by Eduardo Gulias Davis
parent afde3d3874
commit 7701238433
2 changed files with 15 additions and 16 deletions
@@ -27,10 +27,10 @@ class DNSCheckValidation implements EmailValidation
{
// 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 @@ class DNSCheckValidation implements EmailValidation
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 @@ class DNSCheckValidation implements EmailValidation
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();
}
@@ -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'],
];
}