For my research, the string is [docxa]l.hri@txwt.org not a syntactically valid email address , since the square brackets are not quoted.
However, the class javax.mail.internet.InternetAddressaccepts this address as valid because it simply splits the part [docxa]into an address in the method .parse(..)that is called by the constructor.
The code comment in InternetAddress.parse(String, boolean, boolean)indicates that the developers themselves are not sure:
case '[':
So that the test that I created to test the problem fails:
@Test
public void givenUnquotedEmailAddressWithSquareBracketsInLocalPartThenValidationShouldFail() {
try {
new InternetAddress("[docxa]l.hri@txwt.org", true).validate();
fail("address should be invalid");
} catch (AddressException e) {
}
}
So, is this a mistake InternetAddress, or is my research or my understanding of this incomplete?
source
share