I have some .eml and some .msg mail files that contain date headers in a non-standard format:
Date: Thu Sep 30 18:58:24 UTC 2021
Good old AI has suggested that I can use this technique for .msg files:
// Create load options for the email
MsgLoadOptions options = new MsgLoadOptions();
// Access the decoding options
options.getDecodingOptions().setCustomDateFormats(new String[] {
“EEE MMM dd HH:mm:ss zzz yyyy”, //the non standard date to process
“yyyy/MM/dd HH:mm:ss”,
“EEE, dd MMM yyyy HH:mm:ss z” // Standard, but good to include if overridden
});
// Load the message with the custom options
MailMessage message = MailMessage.load(“path/to/email.msg”, options);
But the getDecodingOptions method does not exist.
For .eml files I am able to read the file line-by-line until I get that Date header and then inject it into the MailMessage or MapiMessage object’s header set.
Is there a valid way to do this in Aspose Mail for Java?
@mbeedell
You are trying to handle non-standard email date formats in .msg and .eml files using Aspose.Email for Java. You found that getDecodingOptions() doesn’t exist for MsgLoadOptions , and you’re also dealing with MSG to EML conversion overriding missing dates with the current timestamp .
Here’s how to approach this:
-
For .msg files:
Aspose.Email for Java does not currently support setting custom date formats directly through MsgLoadOptions . You may need to load the message first and then manually adjust the Date header if necessary after loading, although this is not a built-in feature.
-
For .eml files:
You can continue with your current approach of parsing the file line-by-line to extract and inject the Date header into the MailMessage object’s headers . This gives you full control over how the header is interpreted and inserted.
If you’re converting MSG to EML, be aware that Aspose.Email may override missing dates with the current timestamp , which is a known behavior you might want to avoid depending on your use case.
A support engineer will follow up in this thread if needed.
Hello @mbeedell,
There is currently no mechanism in the Aspose.Email for Java to define custom date parsing formats during message loading.