InternetAddress allows you to use a square bracket in localpart - error?

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 '[':   // a domain-literal, probably

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) {
        // expected
    }
}

 

So, is this a mistake InternetAddress, or is my research or my understanding of this incomplete?

+4
source share
1

, , - InternetAddress "[docxa]".

+1

Source: https://habr.com/ru/post/1693571/


All Articles