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 5322
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov committed Jun 10, 2015
1 parent a001a9f commit 154dc03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ public function isValid($value)

$this->hostname = $this->idnToUtf8($this->hostname);

if ((strlen($this->localPart) > 64) || (strlen($this->hostname) > 255)) {
// https://tools.ietf.org/html/rfc5322#section-2.1.1
if ((strlen($this->localPart) + strlen($this->hostname)) > 994) {
$length = false;
$this->error(self::LENGTH_EXCEEDED);
}
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 154dc03

Please sign in to comment.