[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/egulias/email-validator/EmailValidator/Validation/ -> DNSCheckValidation.php (source)

   1  <?php
   2  
   3  namespace Egulias\EmailValidator\Validation;
   4  
   5  use Egulias\EmailValidator\EmailLexer;
   6  use Egulias\EmailValidator\Exception\InvalidEmail;
   7  use Egulias\EmailValidator\Warning\NoDNSMXRecord;
   8  use Egulias\EmailValidator\Exception\NoDNSRecord;
   9  
  10  class DNSCheckValidation implements EmailValidation
  11  {
  12      /**
  13       * @var array
  14       */
  15      private $warnings = [];
  16  
  17      /**
  18       * @var InvalidEmail
  19       */
  20      private $error;
  21      
  22      public function __construct()
  23      {
  24          if (!extension_loaded('intl')) {
  25              throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
  26          }
  27      }
  28  
  29      public function isValid($email, EmailLexer $emailLexer)
  30      {
  31          // use the input to check DNS if we cannot extract something similar to a domain
  32          $host = $email;
  33  
  34          // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
  35          if (false !== $lastAtPos = strrpos($email, '@')) {
  36              $host = substr($email, $lastAtPos + 1);
  37          }
  38  
  39          return $this->checkDNS($host);
  40      }
  41  
  42      public function getError()
  43      {
  44          return $this->error;
  45      }
  46  
  47      public function getWarnings()
  48      {
  49          return $this->warnings;
  50      }
  51  
  52      protected function checkDNS($host)
  53      {
  54          $variant = INTL_IDNA_VARIANT_2003;
  55          if ( defined('INTL_IDNA_VARIANT_UTS46') ) {
  56              $variant = INTL_IDNA_VARIANT_UTS46;
  57          }
  58          $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
  59  
  60          $Aresult = true;
  61          $MXresult = checkdnsrr($host, 'MX');
  62  
  63          if (!$MXresult) {
  64              $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord();
  65              $Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA');
  66              if (!$Aresult) {
  67                  $this->error = new NoDNSRecord();
  68              }
  69          }
  70          return $MXresult || $Aresult;
  71      }
  72  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1