Skip to content

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

Closed

Description

@bbmedia

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.

Activity

  1. Faelean commented on Jun 22, 2022

    @Faelean

    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
    
  2. bbmedia commented on Jun 23, 2022

    @bbmedia
    Author

    @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();

  3. bbottema commented on Jul 12, 2022

    @bbottema
    Owner

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

  4. bbmedia commented on Jul 13, 2022

    @bbmedia
    Author

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

  5. added this to the 7.2.1 milestone on Jul 13, 2022
  6. changed the title [-]outlookMsgToEmail fails with unsuccessful Exchange delivery receipts[/-] [+]Enhancement: outlookMsgToEmail fails with unsuccessful Exchange delivery receipts[/+] on Jul 13, 2022
  7. changed the title [-]Enhancement: outlookMsgToEmail fails with unsuccessful Exchange delivery receipts[/-] [+]Enhancement: make Outlook support tolerant of invalid/empty nested Outlook message attachments[/+] on Jul 13, 2022
  8. added a commit that references this issue on Jul 13, 2022
  9. bbottema commented on Jul 13, 2022

    @bbottema
    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.

  10. bbottema commented on Jul 13, 2022

    @bbottema
    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.

  11. bbmedia commented on Jul 19, 2022

    @bbmedia
    Author

    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.

  12. bbmedia commented on Jul 21, 2022

    @bbmedia
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions