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

Enhancement: make Outlook support tolerant of invalid/empty nested Outlook message attachments #396

Closed
bbmedia opened this issue Jun 21, 2022 · 8 comments

Comments

@bbmedia
Copy link

bbmedia commented Jun 21, 2022

If you work with Outlook/Exchange you can request delivery receipts for your emails. After sending an email, you'll get a receipt if the email has been successfully delivered to the recipient's server.

If the recipient's server supports these confirmations, the returning email can successfully be parsed and converted by Simple-Java-Mail's Outlook to email converter.

If the recipient's server doesn't support this feature, you'll get a different email from your Exchange server. This message contains an attached email without body (empty text, empty html, empty rtf). Therefore the OutlookEmailConverter.buildEmailFromOutlookMessage recursive call fails on line 111 because the mime-body of the attached mail is empty and the whole conversion is stopped with an IllegalStateException (InternalEmailConverterImpl.java:42).

final byte[] mimedata = internalEmailConverter.mimeMessageToEMLByteArray(message);

I would suggest to make this conversion more fault-tolerant to support the mentioned Exchange messages.

Unfortunately, I can't attach a sample email because of privacy issues but I would be happy to help resolving this issue.

BTW: Because of some dependency issues, I still have to work with version 6.7.5.

@Faelean
Copy link

Faelean commented Jun 22, 2022

It seems like I've ran into the same/a similar issue

I have an example mail that states that the recipient's server did not send a receipt for successfully delivering the mail so I thought this might be the same base use case. If not sorry for hijacking this issue, I'll open a new one then. I can't publish the mail here, but if you wand I can send it to you directly.

I've tested this with version 7.1.1, but the original problem was discovered on a system using 6.6.1.

Using the EmailConverter I get two warnings and finally the IllegalStateException.
Doing the same with the OutlookMessageParser works as expected.

public static void main(String[] args) throws IOException {
	String msgFileName = ".\\files\\Mittels Relay umgeleitet test.msg";
	
	try (FileInputStream fileInputStream = new FileInputStream(msgFileName)){
		EmailConverter.outlookMsgToEmail(fileInputStream);
		
		//OutlookMessageParser outlookMessageParser = new OutlookMessageParser();
		//OutlookMessage outlookMessage = outlookMessageParser.parseMsg(fileInputStream);
	}
}
14:01:43 [main] WARN  OutlookMessage - Skipping nested Outlook message as file attachment, writing Outlook messages back as data is not supported!
14:01:43 [main] WARN  OutlookMessage - To access the nested Outlook message as parsed Java object, refer to .getAttachments() instead.
Exception in thread "main" java.lang.IllegalStateException: This should never happen
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEMLByteArray(EmailConverter.java:559)
	at org.simplejavamail.converter.internal.InternalEmailConverterImpl.mimeMessageToEMLByteArray(InternalEmailConverterImpl.java:41)
	at org.simplejavamail.internal.outlooksupport.converter.OutlookEmailConverter.buildEmailFromOutlookMessage(OutlookEmailConverter.java:126)
	at org.simplejavamail.internal.outlooksupport.converter.OutlookEmailConverter.outlookMsgToEmailBuilder(OutlookEmailConverter.java:85)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmailBuilder(EmailConverter.java:239)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:221)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:213)
	at ParseP7s.main(ParseP7s.java:30)
Caused by: java.io.IOException: No MimeMessage content
	at jakarta.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:92)
	at jakarta.activation.DataHandler.writeTo(DataHandler.java:278)
	at jakarta.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1670)
	at jakarta.mail.internet.MimeMessage.writeTo(MimeMessage.java:1888)
	at jakarta.mail.internet.MimeMessage.writeTo(MimeMessage.java:1862)
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEMLByteArray(EmailConverter.java:555)
	... 7 more
Caused by: jakarta.mail.MessagingException: No MimeMessage content
	at jakarta.mail.internet.MimeMessage.getContentStream(MimeMessage.java:1395)
	at jakarta.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:78)
	... 12 more

@bbmedia
Copy link
Author

bbmedia commented Jun 23, 2022

@Faelean I'm pretty sure you're mentioning the exact same issue. I could temporary fix it by doing a null check on nestedMsg's html, text and rtfText properties. If none of these properties are set, I skip the recursive call to ignore the nested (empty) email.

See

final OutlookMessage nestedMsg = ((OutlookMsgAttachment) attachment).getOutlookMessage();

@bbottema
Copy link
Owner

@bbmedia, would you be able to share the email privately with me? I would like to see the error and investigate.

@bbmedia
Copy link
Author

bbmedia commented Jul 13, 2022

@bbottema Just sent you an example by email. Thanks a lot!

@bbottema bbottema added this to the 7.2.1 milestone Jul 13, 2022
@bbottema bbottema changed the title outlookMsgToEmail fails with unsuccessful Exchange delivery receipts Enhancement: outlookMsgToEmail fails with unsuccessful Exchange delivery receipts Jul 13, 2022
@bbottema bbottema added enhancement and removed bug labels Jul 13, 2022
@bbottema bbottema changed the title Enhancement: outlookMsgToEmail fails with unsuccessful Exchange delivery receipts Enhancement: make Outlook support tolerant of invalid/empty nested Outlook message attachments Jul 13, 2022
bbottema added a commit that referenced this issue Jul 13, 2022
@bbottema
Copy link
Owner

Fixed in 7.2.1. I'm just ignoring this very specific exception cause. Might be good to ignore any and all exceptions here, but for now I rather take it case by case, so we slowly build up a catalogue of known Outlook issues.

@bbottema
Copy link
Owner

About 6.x.x version range, I'm not sure I want to support it there. You can't move to 7.x.x? 6 is really old school.

@bbmedia
Copy link
Author

bbmedia commented Jul 19, 2022

Thanks a lot for solving this issue!

We are currently bound to 6.x.x because of the javax/jakarta dependency. But I do completely understand your point.

@bbmedia
Copy link
Author

bbmedia commented Jul 21, 2022

We finally managed to fully migrate to 7.4.0.

You can forget about V6 regarding this issue.

Thanks a lot for all your work!

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

3 participants