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

Allow long email addresses per rfc 5322 #8

Merged
merged 1 commit into from
Jun 23, 2015

Conversation

denis-sokolov
Copy link
Contributor

The addresses are not only theoretical,
I have recently received emails from Trello and Peerby that exceed the 64 octet limit for the local part already.

@denis-sokolov denis-sokolov force-pushed the long-email branch 5 times, most recently from dc2dbd9 to 154dc03 Compare June 10, 2015 09:33
$this->hostname = $this->idnToUtf8($this->hostname);

// https://tools.ietf.org/html/rfc5322#section-2.1.1
if ((strlen($this->localPart) + strlen($this->hostname)) > 994) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess @ sign should be included to the length too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually subtracted 4 from 998 to account for To: and @, but did not document it properly.
Thanks for noticing.

@denis-sokolov denis-sokolov force-pushed the long-email branch 2 times, most recently from a767c9e to c593863 Compare June 10, 2015 09:49
@Maks3w
Copy link
Member

Maks3w commented Jun 10, 2015

@denis-sokolov The length of 998 is not applicable here. It's just the maximum line length in the SMTP protocol and it's not applicable to email address. (In fact there is no any length limit in the content, just fold the header in multiple lines and content is allowed to exceed 998 characters)

Please choose a better RFC as reference, if you can't find a reference just remove the local part constraint.

// 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead use 'line length MM' => str_repeat('x', NN) . '@x',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NN will be make more clear what is the expected length (MM)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updating.

@denis-sokolov denis-sokolov force-pushed the long-email branch 2 times, most recently from e071c29 to 38d2097 Compare June 10, 2015 09:55
@denis-sokolov
Copy link
Contributor Author

Thanks for the correction, @Maks3w.

@denis-sokolov
Copy link
Contributor Author

Finally, a passing test! Sorry for the noise - it passed locally initially, because I had no idn extension.

Please disregard the coveralls check, it's dumb. I removed 4 covered lines and the overall coverage now "fell". Stupid algorithm is stupid.

@Maks3w
Copy link
Member

Maks3w commented Jun 10, 2015

@denis-sokolov Please read my comment above. Your length limit assumption is wrong. RFC 5321 is not a reference for this.

@denis-sokolov
Copy link
Contributor Author

@Maks3w, I did read it, it was helpful, thank you.
I think you were referring to the 998 limit of RFC 5322 that I did remove from the PR.

The remaining PR is about RFC 5321 (Internet Message Format) stating "To the maximum extent possible, implementation techniques that impose no limits on the limits of these objects should be used.".

@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve the trailing comma

@Maks3w
Copy link
Member

Maks3w commented Jun 10, 2015

Yes. I was talking about the 998 line length limit

@Maks3w
Copy link
Member

Maks3w commented Jun 10, 2015

right now I have a couple of concerns:

  1. Seems we have two options of perform a validation. A relaxed one with length limits removal and strict one with the recommended length limits.
  2. The IDN to UTF-8 failure is enough for mark the address as invalid. Otherwise please open a bug ticket on PHP bug tracker.

So disable length limit changes should be a validator option.

@denis-sokolov
Copy link
Contributor Author

Seems we have two options of perform a validation. A relaxed one with length limits removal and strict one with the recommended length limits.

The distinction between strict and lax validation is important and is unfortunate.
I am using Zend mail module to parse emails, and that's the use case when I need lax validation.
The documentation seems to suggest it's a normal use case.
If I was to send emails, I would expect the validation to be strict.

The IDN to UTF-8 failure is enough for mark the address as invalid. Otherwise please open a bug ticket on PHP bug tracker.

The same class a few lines above already uses the fallback:

return (idn_to_ascii($email) ?: $email);

If anything, the new change ensures consistency.

@Maks3w
Copy link
Member

Maks3w commented Jun 10, 2015

I was suspecting this come from Zend\Mail :)

I think this is almost done.

Please add a option named strict => true for toggle on/off length validation.

Then we can create a PR against Zend\Mail turning the option to false.

@denis-sokolov
Copy link
Contributor Author

Done, @Maks3w.

@weierophinney weierophinney merged commit b55aaa0 into zendframework:master Jun 23, 2015
weierophinney added a commit that referenced this pull request Jun 23, 2015
Allow long email addresses per rfc 5322
weierophinney added a commit that referenced this pull request Jun 23, 2015
weierophinney added a commit that referenced this pull request Jun 23, 2015
weierophinney added a commit that referenced this pull request Jun 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants