Skip to content

Enhancement: Process all Outlook message headers, either copying the as-is or translating them to respective Simple Java Mail API calls #407

Closed

Description

@rehollman

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.

Activity

  1. bbottema commented on Jul 18, 2022

    @bbottema
    Owner

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

  2. added 2 commits that reference this issue on Jul 19, 2022
  3. bbottema commented on Jul 19, 2022

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

  4. 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[/+] on Jul 19, 2022
  5. added this to the 7.4.0 milestone on Jul 19, 2022
  6. bbottema commented on Jul 19, 2022

    @bbottema
    Owner

    Released in 7.4.0

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