bbottema / email-rfc2822-validator

The world's only Java-based rfc2822-compliant email address validator and parser
64 stars 13 forks source link

"Bob" <bob@hi.com> is parsed to "bob@hi.com" <Bob> #12

Closed ben-manes closed 5 years ago

ben-manes commented 5 years ago
var address = EmailAddressParser.getInternetAddress(
    "\"Bob\" <bob@hi.com>", DEFAULT, /* cfws */ true);
System.out.println(l.getAddress());

results in Bob, not the expected bob@hi.com. This means if the personal name is not provided then the email is null, which is what caused my code to NPE unexpectedly :)

ben-manes commented 5 years ago

This worked in v1.0.1 and v1.1.0, and broke in v1.1.1.

chconnor commented 5 years ago

Whoa, weird. @bbottema -- thoughts?

bbottema commented 5 years ago

I'll look into it asap.

bbottema commented 5 years ago

Hey guys, I'm terribly sorry. I had cleaned up the code a bit for a fix I later reverted, but I left in the cleanup. Somehow I mixed up the argument order of the InternetAddress constructor:

return new InternetAddress(parts[0], parts[1] + "@" + parts[2]);
// instead of:
return new InternetAddress(parts[1] + "@" + parts[2], parts[0]);

I guess I assumed the name came first (maybe because that's how it is in Simple Java Mail as well).

Anyway I fixed it and released 1.1.2.

ben-manes commented 5 years ago

Thanks for the speedy fix! Does this prompt a new release of simple-java-mail since this is a transitive dependency?

bbottema commented 5 years ago

Indeed, I just released 5.1.3! Thanks for the reminder ;)

chconnor commented 5 years ago

Awesome, thanks!