Exemple #1
0
 /**
  * Get data for email provider.
  *
  * @param $email
  * @return array|null
  * @throws Exception
  */
 public function search($email)
 {
     if (!$this->validEmail($email)) {
         throw new Exception("Email format is not valid.", 201);
     }
     $domain = $this->getDomain($email);
     $mxHosts = [];
     dns_get_mx($domain, $mxHosts);
     if (!count($mxHosts)) {
         throw new Exception("Email domain does not exist.", 202);
     }
     return $this->mxProviderManager->getProviderLoginData($this->extractMXDomain($mxHosts[0]));
 }
Exemple #2
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid email address
  * according to RFC2822
  *
  * @link   http://www.ietf.org/rfc/rfc2822.txt RFC2822
  * @link   http://www.columbia.edu/kermit/ascii.html US-ASCII characters
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $valueString = (string) $value;
     $this->_setValue($valueString);
     // Split email address up
     if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_localPart = $matches[1];
     $this->_hostname = $matches[2];
     // Match hostname part
     $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())->isValid($this->_hostname);
     if (!$hostnameResult) {
         $this->_error(self::INVALID_HOSTNAME);
         // Get messages and errors from hostnameValidator
         foreach ($this->hostnameValidator->getMessages() as $message) {
             $this->_messages[] = $message;
         }
         foreach ($this->hostnameValidator->getErrors() as $error) {
             $this->_errors[] = $error;
         }
     }
     // MX check on hostname via dns_get_record()
     if ($this->_validateMx) {
         if ($this->validateMxSupported()) {
             $result = dns_get_mx($this->_hostname, $mxHosts);
             if (count($mxHosts) < 1) {
                 $hostnameResult = false;
                 $this->_error(self::INVALID_MX_RECORD);
             }
         } else {
             /**
              * MX checks are not supported by this system
              * @see Zend_Validate_Exception
              */
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
         }
     }
     // First try to match the local part on the common dot-atom format
     $localResult = false;
     // Dot-atom characters are: 1*atext *("." 1*atext)
     // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
     //        "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
     $atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
     if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
         $localResult = true;
     } else {
         // Try quoted string format
         // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
         // qtext: Non white space controls, and the rest of the US-ASCII characters not
         //   including "\" or the quote character
         $noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
         $qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
         $ws = '\\x20\\x09';
         if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $this->_localPart)) {
             $localResult = true;
         } else {
             $this->_error(self::DOT_ATOM);
             $this->_error(self::QUOTED_STRING);
             $this->_error(self::INVALID_LOCAL_PART);
         }
     }
     // If both parts valid, return true
     if ($localResult && $hostnameResult) {
         return true;
     } else {
         return false;
     }
 }
Exemple #3
0
 /**
  * Get MX records for the email
  *
  * @return array
  */
 public function mxRecords()
 {
     $mxRecords = array();
     dns_get_mx($this->domainName(), $mxRecords);
     return $mxRecords;
 }
Exemple #4
0
    #exit(44);
} else {
    echo 'Current script owner: ' . get_current_user();
    #exit(88);
}
#$mailContent = "Date:".date("D, j M Y H:i:s +0008 (UTC)")." \r\n". $mailContent;
#$mailContent = "Delivered-for: eai@localhost \r\n". $mailContent;
//receiving mail server
$isSMTPUTF8 = true;
//server is known to be not EAI enabled
if ($isNotEAIenabled) {
    $isSMTPUTF8 = false;
}
//outgoing mail AND  not known to be {EAI enabled/not enabled} AND  ASCII
if (!$isLocalMail && !$isEAIenabled && !$isNotEAIenabled && $isToAscii) {
    if (dns_get_mx($toDomain, $mxhosts, $weights)) {
        foreach ($mxhosts as $key => $host) {
            $host = strtolower($host);
            //@TODO sort by lesser weight
            //should check all MX server
            //currently just break upon the first check
            //echo "Hostname: $host (Weight: {$weights[$key]}<BR/>\n";
            if (!in_array($host, $eaiEnabledMX)) {
                break;
            }
            $stream = @fsockopen($host, '25');
            if (!$stream) {
                exit(1);
            }
            //"Can't open SMTP stream."
            $tmp = fgets($stream, 1024);
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid email address
  * according to RFC2822
  *
  * @link   http://www.ietf.org/rfc/rfc2822.txt RFC2822
  * @link   http://www.columbia.edu/kermit/ascii.html US-ASCII characters
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_messages = array();
     $valueString = (string) $value;
     // Split email address up
     if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
         $this->_messages[] = "'{$valueString}' is not a valid email address in the basic format local-part@hostname";
         return false;
     }
     $localPart = $matches[1];
     $hostname = $matches[2];
     // Match hostname part
     $hostnameResult = $this->hostnameValidator->isValid($hostname);
     if (!$hostnameResult) {
         $this->_messages[] = "'{$hostname}' is not a valid hostname for email address '{$valueString}'";
         // Get messages from hostnameValidator
         foreach ($this->hostnameValidator->getMessages() as $message) {
             $this->_messages[] = $message;
         }
     }
     // MX check on hostname via dns_get_record()
     if ($this->_validateMx) {
         if ($this->validateMxSupported()) {
             $result = dns_get_mx($hostname, $mxHosts);
             var_dump($result, $mxHosts);
             if (count($result) < 1) {
                 $hostnameResult = false;
                 $this->_messages[] = "'{$hostname}' does not appear to have a valid MX record for the email address" . "'{$valueString}'";
             }
         } else {
             /**
              * MX checks are not supported by this system
              * @see Zend_Validate_Exception
              */
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
         }
     }
     // First try to match the local part on the common dot-atom format
     $localResult = false;
     // Dot-atom characters are: 1*atext *("." 1*atext)
     // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
     //        "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
     $atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
     if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $localPart)) {
         $localResult = true;
     } else {
         $this->_messages[] = "'{$localPart}' not matched against dot-atom format";
     }
     // If not matched, try quoted string format
     if (!$localResult) {
         // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
         // qtext: Non white space controls, and the rest of the US-ASCII characters not
         //   including "\" or the quote character
         $noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
         $qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
         $ws = '\\x20\\x09';
         if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $localPart)) {
             $localResult = true;
         } else {
             $this->_messages[] = "'{$localPart}' not matched against quoted-string format";
         }
     }
     if (!$localResult) {
         $this->_messages[] = "'{$localPart}' is not a valid local part for email address '{$valueString}'";
     }
     // If both parts valid, return true
     if ($localResult && $hostnameResult) {
         return true;
     } else {
         return false;
     }
 }
Exemple #6
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid email address
  * according to RFC2822
  *
  * @link   http://www.ietf.org/rfc/rfc2822.txt RFC2822
  * @link   http://www.columbia.edu/kermit/ascii.html US-ASCII characters
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $valueString = (string) $value;
     $matches = array();
     $length = true;
     $this->_setValue($valueString);
     // Split email address up and disallow '..'
     if (strpos($valueString, '..') !== false or !preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_localPart = $matches[1];
     $this->_hostname = $matches[2];
     if (strlen($this->_localPart) > 64 || strlen($this->_hostname) > 255) {
         $length = false;
         $this->_error(self::LENGTH_EXCEEDED);
     }
     // Match hostname part
     $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())->isValid($this->_hostname);
     if (!$hostnameResult) {
         $this->_error(self::INVALID_HOSTNAME);
         // Get messages and errors from hostnameValidator
         foreach ($this->hostnameValidator->getMessages() as $code => $message) {
             $this->_messages[$code] = $message;
         }
         foreach ($this->hostnameValidator->getErrors() as $error) {
             $this->_errors[] = $error;
         }
     } else {
         if ($this->_validateMx) {
             // MX check on hostname via dns_get_record()
             if ($this->validateMxSupported()) {
                 $result = dns_get_mx($this->_hostname, $mxHosts);
                 if (count($mxHosts) < 1) {
                     // the address may can accept email even if there's no MX record but A or A6 or AAAA record found
                     if ($this->_deepMxCheck && $this->validateDnsSupported()) {
                         if ($this->isReservedIpAddress($this->_hostname)) {
                             $hostnameResult = false;
                             $this->_error(self::INVALID_NETWORK_SEGMENT);
                         } else {
                             if (checkdnsrr($this->_hostname, "A") === false && checkdnsrr($this->_hostname, "AAAA") === false && checkdnsrr($this->_hostname, "A6") === false) {
                                 $hostnameResult = false;
                                 $this->_error(self::INVALID_MX_RECORD);
                             }
                         }
                     } else {
                         $hostnameResult = false;
                         $this->_error(self::INVALID_MX_RECORD);
                     }
                 } else {
                     // must check every MX record for at least one valid address
                     if ($this->_deepMxCheck && $this->validateDnsSupported()) {
                         $hasOneValidAddress = false;
                         foreach ($mxHosts as $key => $hostname) {
                             if (!$this->isReservedIpAddress($hostname) && (checkdnsrr($hostname, "A") !== false || checkdnsrr($hostname, "AAAA") !== false || checkdnsrr($hostname, "A6") !== false)) {
                                 $hasOneValidAddress = true;
                                 break;
                             }
                         }
                         if ($hasOneValidAssress === false) {
                             $hostnameResult = false;
                             $this->_error(self::INVALID_MX_RECORD);
                         }
                     }
                 }
             } else {
                 /**
                  * MX checks are not supported by this system
                  * @see Zend_Validate_Exception
                  */
                 require_once 'Zend/Validate/Exception.php';
                 throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
             }
         }
     }
     // First try to match the local part on the common dot-atom format
     $localResult = false;
     // Dot-atom characters are: 1*atext *("." 1*atext)
     // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
     //        "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
     $atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d\\x7e';
     if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
         $localResult = true;
     } else {
         // Try quoted string format
         // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
         // qtext: Non white space controls, and the rest of the US-ASCII characters not
         //   including "\" or the quote character
         $noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
         $qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
         $ws = '\\x20\\x09';
         if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $this->_localPart)) {
             $localResult = true;
         } else {
             $this->_error(self::DOT_ATOM);
             $this->_error(self::QUOTED_STRING);
             $this->_error(self::INVALID_LOCAL_PART);
         }
     }
     // If both parts valid, return true
     if ($localResult && $hostnameResult && $length) {
         return true;
     } else {
         return false;
     }
 }