Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses with quoted string with a folding white space fail validation #39

Closed
JakubJanowski opened this issue Jul 22, 2022 · 2 comments
Labels

Comments

@JakubJanowski
Copy link

Hi, I've noticed that these addresses fail to validate but should be allowed under RFC 5322:

EmailValidator.Validate("\"FWS\r\n test\"@iana.org");
EmailValidator.Validate("\"FWS\r\n\ttest\"@iana.org");

I've gathered the necessary definitions from sections 3.4.1

addr-spec       =   local-part "@" domain

local-part      =   dot-atom / quoted-string / obs-local-part

3.2.4

qtext           =   %d33 /             ; Printable US-ASCII
                    %d35-91 /          ;  characters not including
                    %d93-126 /         ;  "\" or the quote character
                    obs-qtext

qcontent        =   qtext / quoted-pair

quoted-string   =   [CFWS]
                    DQUOTE *([FWS] qcontent) [FWS] DQUOTE
                    [CFWS]

3.2.2

FWS             =   ([*WSP CRLF] 1*WSP) /  obs-FWS
                                       ; Folding white space

and RFC 5234 Appendix B.1

CR             =  %x0D
                       ; carriage return

CRLF           =  CR LF
                       ; Internet standard newline
(...)
DQUOTE         =  %x22
                       ; " (Double Quote)
(...)
HTAB           =  %x09
                       ; horizontal tab

LF             =  %x0A
                       ; linefeed
(...)
SP             =  %x20
(...)
WSP            =  SP / HTAB
                       ; white space

This shows that the local-part of an address can be a quoted-string that contains a FWS (Folding white space) anywhere, separated by qcontent. Right now only spaces inside quotes are considered valid by the validator. Spaces alone also form a Folding white space but it can also consist of horizontal tabs and a single Windows-style newline .

I've prepared a few test cases for this. These should validate:

EmailValidator.Validate("\"FWS\ttest\"@iana.org");
EmailValidator.Validate("\" \t\"@iana.org");
EmailValidator.Validate("\" \t\r\n \t\"@iana.org");
EmailValidator.Validate("\"FWS\r\n x\r\n test\"@iana.org");

These should fail:

EmailValidator.Validate("\"FWS\r\ntest\"@iana.org");
EmailValidator.Validate("\"FWS\r test\"@iana.org");
EmailValidator.Validate("\"FWS\n test\"@iana.org");
EmailValidator.Validate("\"FWS\r\n \r\n test\"@iana.org");
@jstedfast
Copy link
Owner

No, they should not validate. You are looking at the wrong spec.

@JakubJanowski
Copy link
Author

Right, my mistake. I think it would be useful to mention in the readme that this is a validator for SMTP envelope type email address instead of IMF type address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants