Free Support Forum - aspose.com

Order of Extracted Email Headers is Different from that Displayed in Outlook

Samples.zip (34.6 KB)

Aspose Team,

We use the Aspose Email java package to get the properties of msg files. We found out that the order of the extracted email headers in recent releases is slightly different from that in version 19.6.

With the attached sample file (Sample.msg), the following is part of the email headers extracted with version 19.6 (Headers_19.6.txt):

Content-Transfer-Encoding
Content-Type

The following is part of the email headers extracted with version 20.8 (Headers_20.8.txt):

X-OriginatorOrg
x-ms-exchange-organization-authsource
Content-Type

And the following is part of the email headers displayed in Outlook (Open the sample file with Outlook in Windows, select File, Click Properties, find the Internet headers section in the Properties dialog) (Headers_outlook.txt).

Content-Transfer-Encoding: 7bit
Content-Type: multipart/alternative;

Note that the positions of Content-Type are different, and the position in email headers extracted with version 19.6 agrees with that displayed in Outlook.

An additional entry (x-ms-exchange-organization-authsource) is found in the email headers extracted with version 20.8. It is the lower case of X-MS-Exchange-Organization-AuthSource.

Following is the sample code that reproduces the problem.
The operating system is Ubuntu 18.04. Java version is 1.8. Aspose Email java packages are 19.6 and 20.8.

import com.aspose.email.*;

public class GetEmailHeaders {

public static void main(String[] args) {
    try {
        String filepath = "/home/ubuntu/testdir_email_headers/Sample.msg";
        MailMessage mailMessage = MailMessage.load(filepath, new MsgLoadOptions());
        String headers = parseHeaders(mailMessage.getHeaders());
        System.out.println("headers = ");
        System.out.println(headers);
    }
    catch(Throwable ex) {
        ex.printStackTrace();
    }
}

private static String parseHeaders(HeaderCollection headers) {
    StringBuilder sb = new StringBuilder();
    String newLine = "";
    for (String header : headers) {
        sb.append(newLine).append(header);
        newLine = System.lineSeparator();
    }
    return sb.toString();
}

}

@xyang

I have created an issue with ID EMAILJAVA-34737 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.