Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Allow long email addresses per rfc 5321
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov committed Jun 10, 2015
1 parent 5d4a86e commit e071c29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class EmailAddress extends AbstractValidator
const DOT_ATOM = 'emailAddressDotAtom';
const QUOTED_STRING = 'emailAddressQuotedString';
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded';

/**
* @var array
Expand All @@ -32,8 +31,7 @@ class EmailAddress extends AbstractValidator
self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address should not be resolved from public network",
self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format",
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for the email address",
self::LENGTH_EXCEEDED => "The input exceeds the allowed length",
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for the email address"
];

/**
Expand Down Expand Up @@ -499,11 +497,6 @@ public function isValid($value)
return false;
}

if ((strlen($this->localPart) > 64) || (strlen($this->hostname) > 255)) {
$length = false;
$this->error(self::LENGTH_EXCEEDED);
}

// Match hostname part
if ($this->options['useDomainCheck']) {
$hostname = $this->validateHostnamePart();
Expand Down
12 changes: 10 additions & 2 deletions test/EmailAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ public function testComplexLocalValid()
'/Bob.Jones@domain.com',
'#Bob.Jones@domain.com',
'Bob.Jones?@domain.com',
'Bob~Jones@domain.com'
'Bob~Jones@domain.com',
// RFC 5321 does mention a limit of 64 for the username,
// but it also states "To the maximum extent possible,
// implementation techniques that impose no limits on the
// length of these objects should be used.".
// http://tools.ietf.org/html/rfc5321#section-4.5.3.1
str_repeat('BobJones', 120).'@domain.com'
];
foreach ($emailAddresses as $input) {
$this->assertTrue($this->validator->isValid($input));
Expand Down Expand Up @@ -451,7 +457,9 @@ public function testHostnameValidatorMessagesShouldBeTranslated()
public function testEmailsExceedingLength()
{
$emailAddresses = [
'thislocalpathoftheemailadressislongerthantheallowedsizeof64characters@domain.com',
// RFC 5322 mentions a limit of 998 per header line.
// https://tools.ietf.org/html/rfc5322#section-2.1.1
str_repeat('bob', 330) . '@i.com',
'bob@verylongdomainsupercalifragilisticexpialidociousspoonfulofsugarverylongdomainsupercalifragilisticexpialidociousspoonfulofsugarverylongdomainsupercalifragilisticexpialidociousspoonfulofsugarverylongdomainsupercalifragilisticexpialidociousspoonfulofsugarexpialidociousspoonfulofsugar.com',
];
foreach ($emailAddresses as $input) {
Expand Down

0 comments on commit e071c29

Please sign in to comment.