Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parsing recipients from EML file more lenient #227

Closed
josdejong opened this issue Sep 26, 2019 · 5 comments
Closed

Make parsing recipients from EML file more lenient #227

josdejong opened this issue Sep 26, 2019 · 5 comments

Comments

@josdejong
Copy link

josdejong commented Sep 26, 2019

I'm working on an application that has to read emails. The API of simple-java-mail looks great, I use it (in Kotlin) like:

val email = EmailConverter.emlToEmail(emailEml)

When actually reading an email though, I get the following error:

26-Sep-2019 16:13:19.159 ERROR [http-nio-8080-exec-1] org.apache.juli.logging.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.simplejavamail.converter.internal.mimemessage.MimeMessageParseException: Error getting [To] recipient types] with root cause
javax.mail.internet.AddressException: Illegal semicolon, not in group
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:921)
	at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:658)
	at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:702)
	at javax.mail.internet.MimeMessage.getRecipients(MimeMessage.java:534)
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.retrieveRecipients(MimeMessageParser.java:393)
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.parseToAddresses(MimeMessageParser.java:374)
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.parseMimeMessage(MimeMessageParser.java:102)
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:64)
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmail(EmailConverter.java:55)
	at org.simplejavamail.converter.EmailConverter.emlToEmail(EmailConverter.java:111)

This is because the emails I have to read contain from and to addresses which use semicolons ; as separator (the TO field ends with a semicolon in the following example):

...
X-MS-Exchange-Organization-Network-Message-Id:  ********
X-MS-Exchange-Organization-AuthSource:  ********
X-MS-Exchange-Organization-AuthAs:  Anonymous
TO: [email protected];
From: "Fake Sender" <[email protected]>
CKX-Bounce-Address: ********
...

It looks like javax.mail.internet.InternetAddress expects addresses to be comma separated. Is there a way to configure this?

@bbottema
Copy link
Owner

Yikes, I think that's not RFC-compliant! That or it is a bug in the underlying Jakarta JavaMail (unlikely). The mimemessage tries to parse the header in strict mode which doesn't work. I have found a way around basically by duplicating the internal JavaMail code and forcing strict=false :/

I'd release to Maven Central soon, but OSS Sonatype is currently experiencing network issues.

@bbottema bbottema added this to the 5.4.0 milestone Sep 27, 2019
bbottema pushed a commit that referenced this issue Sep 27, 2019
@bbottema bbottema changed the title javax.mail.internet.AddressException: Illegal semicolon, not in group Make parsing recipients from EML file more lenient Sep 27, 2019
@josdejong
Copy link
Author

Thanks Benny! Makes sense if there is a strict mode into play. I'm quite confused, doubting whether there is something odd with the mails I try to parse. I can hardly believe that a matured library like JavaMail would have trouble with it. I can open the mails without problem in various mail applications and with some other libraries to parse eml files.

@bbottema
Copy link
Owner

I agree, quite surprising.

@bbottema
Copy link
Owner

5.4.0 released.

@josdejong
Copy link
Author

Thanks, I can confirm that I can now parse my emails :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants