0

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.

0fnt
  • 8,211
  • 9
  • 45
  • 62
  • 1
    https://java.net/projects/javamail/sources/mercurial/content/mail/src/main/java/javax/mail/internet/InternetAddress.java?rev=557 Line 1268 looks like it tests for this possibility and throws an exception if it finds it. So you're right, it shouldn't be valid. Just a silly question, does it matter if you use validate() instead of validate? Or could this be a Unicode vs. ASCII issue? – Duston Sep 16 '15 at 19:25
  • I am using this in Scala, hence wrote `validate` without the `()`. Its the same thing though. I think you mean 1286 for the line, and yes it does look like that is the case. Although looking at the code, I am no longer confident of my usage of this library, it looks very badly written. – 0fnt Sep 16 '15 at 19:42

1 Answers1

1

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)
jmehrens
  • 10,580
  • 1
  • 38
  • 47