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

Line feed in address string will return null #36

Open
lnedry opened this issue Nov 8, 2017 · 1 comment
Open

Line feed in address string will return null #36

lnedry opened this issue Nov 8, 2017 · 1 comment

Comments

@lnedry
Copy link

lnedry commented Nov 8, 2017

Lately I've been seeing emails that have a line feed separating the user name and email address. This causes email-addresses to return null, even though the email address is valid.

$ node
> var addrs = require("email-addresses")
> addrs.parseOneAddress('"Jack Bowman"\n<jack@fogcreek.com>')
parseString = "Jack Bowman"
<jack@fogcreek.com>
parsed = null
null
@jackbearheart
Copy link
Owner

Unfortunately, the rules for whitespace in email addresses (as laid out in rfcs) are arcane and bizarre. It is my understanding that this isn't technically a valid email address, even though to the observer's eye it is obvious how to interpret it as an email address.

The issue is that in the rfcs, only a certain kind of "folding whitespace" is allowed when CRLFs are involved. (see RFC 5322 section 3.2.2, and places where it is used.) The rule is that the whitespace has to be a CRLF, not just LF, and have spaces/tabs on each side. This is silly but there you have it.

> const addrs = require('./lib/email-addresses');
undefined
> addrs.parseOneAddress('"Foo Bar"\n<foo@bar.qux>') != null;
false
> addrs.parseOneAddress('"Foo Bar"\r\n<foo@bar.qux>') != null;
false
> addrs.parseOneAddress('"Foo Bar" \r\n <foo@bar.qux>') != null;
true

I'm sure you have resorted to some reasonable thing like stripping out what you consider whitespace first :)

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

No branches or pull requests

2 participants