bbottema/simple-java-mail

NullPointer when parsing Outlook Message with nested empty Outlook message

Faelean opened this issue · 5 comments

Hi,
when I run the following code I get a NullPointer for some msg files. Parsing the file with the OutlookMessageParser and then calling the getDate() method doesn't produce the error so the problem appears to be related to converting the OutlookMessage to an Email.
This doesn't affect the majority of mails and I haven't figured out what's special about the example mails I have.
I can't publish these mails here, but if you want I can send them to you.

	public static void main(String[] args) throws IOException {
		String msgFileName = ".\\files\\example.msg";
		
		try (FileInputStream fileInputStream = new FileInputStream(msgFileName)) {

			Email email = EmailConverter.outlookMsgToEmail(fileInputStream);
			
			//OutlookMessageParser outlookMessageParser = new OutlookMessageParser();
			//OutlookMessage outlookMessage = outlookMessageParser.parseMsg(fileInputStream);
			//outlookMessage.getDate();
		}
	}
Exception in thread "main" java.lang.NullPointerException
	at org.simplejavamail.outlookmessageparser.model.OutlookMessage.getDate(OutlookMessage.java:856)
	at org.simplejavamail.internal.outlooksupport.converter.OutlookEmailConverter.buildEmailFromOutlookMessage(OutlookEmailConverter.java:102)
	at org.simplejavamail.internal.outlooksupport.converter.OutlookEmailConverter.buildEmailFromOutlookMessage(OutlookEmailConverter.java:123)
	at org.simplejavamail.internal.outlooksupport.converter.OutlookEmailConverter.outlookMsgToEmailBuilder(OutlookEmailConverter.java:85)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmailBuilder(EmailConverter.java:230)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:212)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:204)

I can understand the exception bug when date is null somehow, but I cannot explain the difference between converting it with EmailConverter vs OutlookMessageParser. I would actually like to reproduce it with the debugger, so if you could send your problem email, I would really appreciate it.

It turns out that outlook-message-parser identifies a nested Outlook message attached, which is completely empty (which is invalid). I'm not sure why it finds a nested Outlook attachment, but I need some criteria by which I can ignore such an attachment.

image

This use case is resolved if I reject nested Outlook messages when their ID is empty, but I have no idea if this is always the case. At least all the existing junit tests still pass, including the ones with nested message attachments, but I would like to have more confidence in this solution.

I fixed the issue which will be in release 7.0.0. It might take some time for this fix to go public because of that. In the meantime, you can fix it by forcing the outlook-message-parser dependency to version >= 1.7.12.

<dependencyManagement>
  <dependencies>
    <dependency><!-- fixes #326 (workaround until SJM 7.0.0 is released) -->
      <groupId>org.simplejavamail</groupId>
      <artifactId>outlook-message-parser</artifactId>
      <version>1.7.12</version>
    </dependency>
 </dependencies>
</dependencyManagement>

7.0.0 just released with the fix for this.