As far as my research went, the string [docxa][email protected]
is not a syntactically valid email-address, as the square brackets are not in a quoted-string.
However, the class javax.mail.internet.InternetAddress
accepts this address as a valid one, because it simply strips the [docxa]
part from the address in its .parse(..)
method, which is invoked by the constructor.
Code comment in InternetAddress.parse(String, boolean, boolean)
indicates, the implementers weren't sure themselves:
case '[': // a domain-literal, probably
That's the test I created to verify the problem, it's failing:
@Test
public void givenUnquotedEmailAddressWithSquareBracketsInLocalPartThenValidationShouldFail() {
try {
new InternetAddress("[docxa][email protected]", true).validate();
fail("address should be invalid");
} catch (AddressException e) {
// expected
}
}
So, is this a bug in InternetAddress
, or is my research or my understanding of it incomplete?
Yes, it's a bug that InternetAddress strips off the leading "[docxa]".