import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
@ -17,22 +16,19 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: EmailAddress.php 8985 2008-03-21 21:37:24Z matthew $
|
||||
* @version $Id: EmailAddress.php 14560 2009-03-31 14:41:22Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Hostname
|
||||
*/
|
||||
require_once 'Zend/Validate/Hostname.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
@ -41,13 +37,13 @@ require_once 'Zend/Validate/Hostname.php';
|
||||
*/
|
||||
class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
{
|
||||
|
||||
const INVALID = 'emailAddressInvalid';
|
||||
const INVALID_HOSTNAME = 'emailAddressInvalidHostname';
|
||||
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord';
|
||||
const DOT_ATOM = 'emailAddressDotAtom';
|
||||
const QUOTED_STRING = 'emailAddressQuotedString';
|
||||
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
|
||||
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -58,7 +54,8 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
|
||||
self::DOT_ATOM => "'%localPart%' not matched against dot-atom format",
|
||||
self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format",
|
||||
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'"
|
||||
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'",
|
||||
self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length"
|
||||
);
|
||||
|
||||
/**
|
||||
@ -73,6 +70,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
* Local object for validating the hostname part of an email address
|
||||
*
|
||||
* @var Zend_Validate_Hostname
|
||||
* @depreciated
|
||||
*/
|
||||
public $hostnameValidator;
|
||||
|
||||
@ -111,6 +109,16 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
$this->setHostnameValidator($hostnameValidator, $allow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set hostname validator
|
||||
*
|
||||
* @return Zend_Validate_Hostname
|
||||
*/
|
||||
public function getHostnameValidator()
|
||||
{
|
||||
return $this->hostnameValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
|
||||
* @param int $allow OPTIONAL
|
||||
@ -162,11 +170,14 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
public function isValid($value)
|
||||
{
|
||||
$valueString = (string) $value;
|
||||
$matches = array();
|
||||
$length = true;
|
||||
|
||||
$this->_setValue($valueString);
|
||||
|
||||
// Split email address up
|
||||
if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
|
||||
// Split email address up and disallow '..'
|
||||
if ((strpos($valueString, '..') !== false) or
|
||||
(!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches))) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
@ -174,6 +185,11 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
$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);
|
||||
@ -181,16 +197,14 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
$this->_error(self::INVALID_HOSTNAME);
|
||||
|
||||
// Get messages and errors from hostnameValidator
|
||||
foreach ($this->hostnameValidator->getMessages() as $message) {
|
||||
$this->_messages[] = $message;
|
||||
foreach ($this->hostnameValidator->getMessages() as $code => $message) {
|
||||
$this->_messages[$code] = $message;
|
||||
}
|
||||
foreach ($this->hostnameValidator->getErrors() as $error) {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
|
||||
// MX check on hostname via dns_get_record()
|
||||
if ($this->_validateMx) {
|
||||
} 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) {
|
||||
@ -212,8 +226,8 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
|
||||
// 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';
|
||||
// "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
|
||||
$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 {
|
||||
@ -235,11 +249,10 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
}
|
||||
|
||||
// If both parts valid, return true
|
||||
if ($localResult && $hostnameResult) {
|
||||
if ($localResult && $hostnameResult && $length) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user