From ebaaf5be6c0286928352e054f2d5125608e5405e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Fri, 6 Oct 2023 08:47:41 +0200 Subject: [PATCH] perform AAAA check separately (fixes #301) (#376) --- src/Validation/DNSCheckValidation.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Validation/DNSCheckValidation.php b/src/Validation/DNSCheckValidation.php index 214d4f4..469e87d 100644 --- a/src/Validation/DNSCheckValidation.php +++ b/src/Validation/DNSCheckValidation.php @@ -13,10 +13,6 @@ use Egulias\EmailValidator\Warning\Warning; class DNSCheckValidation implements EmailValidation { - /** - * @var int - */ - protected const DNS_RECORD_TYPES_TO_CHECK = DNS_MX + DNS_A + DNS_AAAA; /** * Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2), @@ -149,7 +145,7 @@ class DNSCheckValidation implements EmailValidation */ private function validateDnsRecords($host): bool { - $dnsRecordsResult = $this->dnsGetRecord->getRecords($host, static::DNS_RECORD_TYPES_TO_CHECK); + $dnsRecordsResult = $this->dnsGetRecord->getRecords($host, DNS_A + DNS_MX); if ($dnsRecordsResult->withError()) { $this->error = new InvalidEmail(new UnableToGetDNSRecord(), ''); @@ -158,6 +154,13 @@ class DNSCheckValidation implements EmailValidation $dnsRecords = $dnsRecordsResult->getRecords(); + // Combined check for A+MX+AAAA can fail with SERVFAIL, even in the presence of valid A/MX records + $aaaaRecordsResult = $this->dnsGetRecord->getRecords($host, DNS_AAAA); + + if (! $aaaaRecordsResult->withError()) { + $dnsRecords = array_merge($dnsRecords, $aaaaRecordsResult->getRecords()); + } + // No MX, A or AAAA DNS records if ($dnsRecords === []) { $this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');