bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)
http://www.simplejavamail.org
Apache License 2.0
1.23k stars 270 forks source link

Content-Transfer-Encoding Ends With Space Bug #551

Closed ozkanogun closed 1 month ago

ozkanogun commented 2 months ago

Hello,

If in mail Content-Transfer-Encoding ends with a space character, EmailConverter.mimeMessageToEmailBuilder method throws an error. Is it fixable?

Example code : MimeMessage message = EmailConverter.emlToMimeMessage(emailfile);

EmailPopulatingBuilder pop = EmailConverter.mimeMessageToEmailBuilder(message);

Example Email

Content-Type: multipart/alternative; boundary="2cu1j27uX5Y7=_?:"

--2cu1j27uX5Y7=_?: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit

text plain --2cu1j27uX5Y7=_?: Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit

text html --2cu1j27uX5Y7=_?:--

Exception stack trace :

Exception in thread "main" java.lang.IllegalArgumentException: unknown content transfer encoder: 7bit at org.simplejavamail.api.email.ContentTransferEncoding.lambda$byEncoder$1(ContentTransferEncoding.java:55) at java.base/java.util.Optional.orElseThrow(Optional.java:403) at org.simplejavamail.api.email.ContentTransferEncoding.byEncoder(ContentTransferEncoding.java:55) at org.simplejavamail.converter.EmailConverter.buildEmailFromMimeMessage(EmailConverter.java:758) at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:139) at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:125) at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:117)

bbottema commented 2 months ago

Do you have an EML file for me to download? The EML text you posted seems incomplete.

ozkanogun commented 1 month ago

test.zip

Here it is, i added the test EML file, as i said the problem is at the "Content-Transfer-Encoding: 7bit " lines 7bit ends with a space character. If you trim it at EmailConverter.buildEmailFromMimeMessage or at ContentTransferEncoding.byEncoder the problem must be fixed.

bbottema commented 1 month ago

Well, the message parsed just fine with the latest version. But then we did fix this in https://github.com/bbottema/simple-java-mail/pull/546, I think.