feat: add Email Length validation#430
Conversation
thinkingserious
left a comment
There was a problem hiding this comment.
Thank you for the PR, we greatly appreciate it!
What prompted this PR, did you run into this limitation in practice?
| } | ||
| } | ||
|
|
||
| func TestParseInvalidEmailLength(t *testing.T) { |
There was a problem hiding this comment.
Please provide the happy path test, thanks!
There was a problem hiding this comment.
@thinkingserious I have added new tests for the happy path :)
Thank you so much @thinkingserious for looking at this PR! Yes, We have this limitation in our product as it's under best practices. We were using SMTP and I am happy to say that we recently integrated The technical limit for an email address is 64 characters before the @ sign and 255 after, allowing for a total length of 320 characters (including the @ sign). Reference: https://tools.ietf.org/html/rfc3696#section-3 Also, According to Sendgrid's best practices described in this blog https://sendgrid.com/blog/email-marketing-length-best-practices", it also states the same thing. We have added these checks already in our codebase as its standard and have been followed by the industry. Also stated in the RFCs. Please let me know if you have any doubts. Thank you so much! :) |
thinkingserious
left a comment
There was a problem hiding this comment.
This LGTM, just have one more piece of feedback regarding the error message. Thank you!
| local, domain := parts[0], parts[1] | ||
|
|
||
| if len(domain) > maxEmailDomainLength || len(local) > maxEmailLocalLength { | ||
| return nil, errors.New("invalid email length") |
There was a problem hiding this comment.
I think we should specify a bit more detail about the violation. Something like: "Invalid email length, you have used X out of Y characters )
There was a problem hiding this comment.
I agree. Error message should have more information.
There was a problem hiding this comment.
@thinkingserious I have improved the error messages. Please take a look :)
| } | ||
| } | ||
|
|
||
| func TestParseInvalidEmailLength(t *testing.T) { |
Fixes #429
Add Email Length validation according to best practices and RFCs
Checklist
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.