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

Error on missing mimetype for attachments when parsing Outlook messages where mimeTag was not included #163

Closed
deeev opened this issue Aug 22, 2018 · 11 comments

Comments

@deeev
Copy link

deeev commented Aug 22, 2018

Hi guys,
I'm getting a "org.simplejavamail.converter.internal.msgparser.OutlookMessageException: Unable to parse Outlook message" exception when parsing a file, which is a msg file I save from outlook, using EmailConverter().outlookMsgToMimeMessage().

With another filepath (which seems wrong) I get a mimetype is required exception.

Could anyone help me troubleshooting?

Best regards
Deeev

@deeev deeev changed the title mimetype exception when converting msg files to mimemessage unable to parse outlook message exception when converting msg files to mimemessage Aug 22, 2018
@deeev
Copy link
Author

deeev commented Aug 22, 2018

i looked a bit into it, the exception comes after the EmailPopulatingBuilder parses attachments, and a valid attachment has the mimTag=null

Line 318 of the EmailConverter builder.withAttachment

@deeev deeev closed this as completed Aug 22, 2018
@bbottema
Copy link
Owner

I'm unsure what to do since you closed the issue. Was it a user problem or a problem with the library?

@deeev deeev reopened this Aug 22, 2018
@deeev
Copy link
Author

deeev commented Aug 22, 2018

Oops, I mixed up the issue with one of my own projects, sorry!!

I think the problem is with the library. When I parse an msg file without any attachments the converting itself throws no exception. Convertable msg files still show some issues, for example not parsing the sender correctly (field is null, although there is a sender).

@bbottema
Copy link
Owner

Hi @deeev, could you please try to reproduce this problem with https://github.com/bbottema/outlook-message-parser 1.1.17? That's the library being used under water (nearly the same API).

If you can provide a sample .msg and the code you use to convert it, I'll dive into the problem and get it sorted out. Thanks so much!

@bbottema bbottema added this to the 6.0.0 milestone Aug 23, 2018
@deeev
Copy link
Author

deeev commented Aug 24, 2018

Sure, I'll dive right into it later today!

@bbottema
Copy link
Owner

Hi @deeev, had any luck with this yet? An example with Simple Java Mail would also be fine as long as I can reproduce it!

@stephan-merkli
Copy link

Hi @bbottema

I was able to reproduce the issue from @deeev, with outlook-message-parser and with simplejavamail, only throws in simplejavamail due to precondition for mime type.

Sample code below, msg as attachment (sample-email.zip)

The msg was created in Outlook by creating a new email with subject, recipient, body and a .txt file as attachment, then saving it as msg.

public static void outlookMessageParser() throws Exception { // version 1.1.17, poi-scratchpad 4.0.1
  String inputFile = "c:/temp/lorem.msg";
  try (FileInputStream fis = new FileInputStream(inputFile)) {
    OutlookMessageParser parser = new OutlookMessageParser();
    OutlookMessage outlookMessage = parser.parseMsg(fis);
    for (OutlookAttachment outlookAttachment : outlookMessage.getOutlookAttachments()) {
      OutlookFileAttachment fileAttachment = (OutlookFileAttachment) outlookAttachment;
      System.out.println("Filename: " + fileAttachment.getFilename()); // output "Filename: ipsum.txt"
      System.out.println("Mime tag: " + fileAttachment.getMimeTag()); // output "Mime tag: null"
    }
  }
}

public static void emailConverter() throws Exception { // version 5.1.1, poi-scratchpad 4.0.1
  String inputFile = "c:/temp/lorem.msg";
  try (FileInputStream fis = new FileInputStream(inputFile);
      FileOutputStream fos = new FileOutputStream("c:/temp/lorem.eml")) {
    MimeMessage message = org.simplejavamail.converter.EmailConverter.outlookMsgToMimeMessage(fis);
    // Throws
    // Exception in thread "main" java.lang.IllegalArgumentException: mimetype is required
    // at org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument(Preconditions.java:15)
    // at org.simplejavamail.email.EmailPopulatingBuilder.withAttachment(EmailPopulatingBuilder.java:1212)
    // at org.simplejavamail.converter.EmailConverter.buildEmailFromOutlookMessage(EmailConverter.java:318)
    // at org.simplejavamail.converter.EmailConverter.outlookMsgToEmailBuilder(EmailConverter.java:101)
    // at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:92)
    // at org.simplejavamail.converter.EmailConverter.outlookMsgToMimeMessage(EmailConverter.java:142)
    // at ...
    message.writeTo(fos);
  }

Kind regards and thanks
Stephan

@bbottema
Copy link
Owner

bbottema commented Apr 5, 2019

That was very helpful, @stephan-merkli! So what you have is an Outlook email with an attachment that is missing a mimetype. I don't think that is technically valid!

Can you try with your version of Outlook if this happens for files other than text files as well? If an image or zip for example are stored correctly with mimetype, try the following: take an image or a zip or something, and give it the extension .txt. Is it stored with or without mimetype?

I'm not sure how to deal with this; I suppose when opening the email, Outlook tries to guess the mimetype by the file's extension?

/edit: seems like it: https://stackoverflow.com/a/44907420/441662

@bbottema
Copy link
Owner

bbottema commented Apr 5, 2019

Some methods to determine mimetype based on filetype using the JDK:

@bbottema bbottema changed the title unable to parse outlook message exception when converting msg files to mimemessage Error on missing mimetype for attachments when parsing Outlook messages where mimeTag was not included Apr 5, 2019
@bbottema bbottema modified the milestones: 6.0.0, 5.1.4 Apr 5, 2019
@bbottema
Copy link
Owner

bbottema commented Apr 5, 2019

Implemented enhancement in bbottema/outlook-message-parser#6 release 1.1.18. Updated Simple Java Mail accordingly in 5.1.4.

@deeev, @stephan-merkli, can you please verify the issue is solved?

@bbottema bbottema closed this as completed Apr 5, 2019
@stephan-merkli
Copy link

Tested with outlook-message-parser 1.1.18, Output is Filename: ipsum.txt; Mime tag: text/plain.
And tested with simple-java-mail 5.1.4 and it doesn't fail anymore while converting the msg to eml.
Thank you for the fix.

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