0fnt
0fnt

Reputation: 8681

javax.mail.internet.InternetAddress RFC 822 validation

I would assume that the following would throw but it doesn't.

new javax.mail.internet.InternetAddress( "a@b......." ).validate

My javax.mail version is 1.4. (and java version 8 if it matters). Is this a valid email address according to RFC822 which validate() purports to conform to? http://sphinx.mythic-beasts.com/~pdw/cgi-bin/emailvalidate says that the above is not a valid RFC822 email address.

Upvotes: 0

Views: 2360

Answers (1)

jmehrens
jmehrens

Reputation: 11065

From the documentation:

The current implementation checks many, but not all, syntax rules.

If you can, upgrade your JavaMail version.

public static void main(String[] args) throws Exception {
    Session.getInstance(new Properties()).setDebug(true);
    new javax.mail.internet.InternetAddress("a@b......." ).validate();
}

Outputs:

DEBUG: setDebug: JavaMail version 1.5.4
Exception in thread "main" javax.mail.internet.AddressException: Domain contains dot-dot in string ``a@b.......''
     at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1282)
     at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1099)
     at javax.mail.internet.InternetAddress.parse(InternetAddress.java:638)
     at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:111)

Upvotes: 1

Related Questions