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: Process all Outlook message headers, either copying the as-is or translating them to respective Simple Java Mail API calls #407

Closed
rehollman opened this issue Jul 18, 2022 · 3 comments

Comments

@rehollman
Copy link

rehollman commented Jul 18, 2022

When using the EmailConverter.outlookMsgToEmail method, the headers are missing in the Email object returned. Below is a sample which shows the headers are retrieved when using OutlookMessageParser's parseMsg however using the same input file with EmailConverter shows no headers are retrieved.

package com.test;

import java.io.File;
import java.io.IOException;

import org.simplejavamail.api.email.Email;
import org.simplejavamail.converter.EmailConverter;
import org.simplejavamail.outlookmessageparser.OutlookMessageParser;

public class TestEmailHeaders {

  public static void main(String[] args) {
    OutlookMessageParser msgp = new OutlookMessageParser();
    org.simplejavamail.outlookmessageparser.model.OutlookMessage msg;
    
    String inputFileName = "YourEmailFile.msg"; //  <--- Update this with the name of an Outlook email file (.msg) on your system.

    try {
      msg = msgp.parseMsg(inputFileName);
      System.out.println(">>> Headers from msg: " + msg.getHeaders());
      
      Email email = EmailConverter.outlookMsgToEmail(new File(inputFileName));
      System.out.println(">>> Headers from email: " + email.getHeaders());
      
    } catch (IOException e) {
      // This should never occur during this test.
      e.printStackTrace();
    }

  }
}

In the output from the above, you will notice that the ">>> Headers from msg:" is followed by a number of headers but the ">>> Headers from email: {}" indicates that there are no headers returned from the Email's getHeaders() method.

The problem may stem from the buildEmailFromOutlookMessage method in org/simplejavamail/internal/outlooksupport/converter/OutlookEmailConverter which does not appear to copy the headers from the OutlookMessage to the Email object after converting them from a string.

@bbottema
Copy link
Owner

Correct you are... hmm, I wonder why I left it out.

@bbottema
Copy link
Owner

So as I started adding the proper headers to both outlook-message-parser and mapping the to Email objects, I realized they should be processed exactly the same way as headers from MimeMessage are. Which is that some headers should not be copied as-is, but translated to the Simple Java Mail version of it. Examples of this are dispositionNotificationTo, bounceToRecipient and some others.

On top of that I ran into CRLF injection detection issues due to headers coming back differently from Outlook and MimeMessages (having to do with MimeUtility.encoding/folding).

It was quite a challenge to get everything working finally, but I think I nailed it now. Going to release soon.

@bbottema bbottema changed the title Headers are missing in Email object when using EmailConverter.outlookMsgToEmail Enhancement: Process all Outlook message headers, either copying the as-is or translating them to respective Simple Java Mail API calls Jul 19, 2022
@bbottema bbottema added this to the 7.4.0 milestone Jul 19, 2022
@bbottema
Copy link
Owner

Released in 7.4.0

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

2 participants