MSG files unable to open generated from PST

We are currently using Aspose Email for Java 19.3 to save items from a PST as MSGs. Using the PersonalStorage.saveMessageToFile API we are able to save a given item to a temporary file on disk. For the most part this works as expected–the files on disk are valid MSG files and can be opened individually in Outlook. However, we are seeing in some cases the files written to disk are valid OLE32 objects but not valid MSGs according to Outlook. We have tried using Outlook 2010 and Outlook 2016–both fail to open.

Following are some observations that we’ve collected in troubleshooting this issue:

Double-click: Cannot start Microsoft Outlook. Cannot read the item.

Viewing in lower-level tools such as hex viewers and CFB structured storage readers confirm that at least some of the data is there and in the expected format. For instance, I can see a stream named “__substg1.0_001A001F” which contains the bytes for “IPM Note” however attempting to open this item with anything that seemingly tries to parse a message from the streams and storages throws an error such as the Outlook dialog referenced above. Another application, MFCMapi (GitHub - microsoft/mfcmapi: MFCMAPI) gives the following error:

0x131c 03:57:32.782AM  10-25-2019 0x00000001: MyStgOpenStorage: Opening "D:\path\aspose_exploded.msg", bBestAccess == True

0x131c 03:57:32.800AM  10-25-2019 0x00080000: Enter GetPrivateMAPI

0x131c 03:57:32.801AM  10-25-2019 0x00080000: Exit GetPrivateMAPI, hinstPrivateMAPI = 72100000

0x131c 03:57:32.803AM  10-25-2019 0x00080000: Enter GetPrivateMAPI

0x131c 03:57:32.804AM  10-25-2019 0x00080000: Exit GetPrivateMAPI, hinstPrivateMAPI = 72100000

0x131c 03:57:32.805AM  10-25-2019 0x40000000: Function call: c:\projects\mfcmapi\core\mapi\mapifile.cpp@65: OpenIMsgOnIStg( nullptr, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, lpMalloc, nullptr, pStorage, nullptr, 0, 0, &lpMessage)

0x131c 03:57:32.808AM  10-25-2019 0x00000040: Error: 

Code: MAPI_E_CORRUPT_DATA == 0x8004011B

Function OpenIMsgOnIStg( nullptr, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, lpMalloc, nullptr, pStorage, nullptr, 0, 0, &lpMessage)

File c:\projects\mfcmapi\core\mapi\mapifile.cpp Line 65

If I locate the message within the PST (I am able to match the entry id) and drag out to the desktop, Outlook is able to create an openable MSG file.

I also noticed that the Outlook-created version contains two 0-byte streams “__substg1.0_0E02001F” and “__substg1.0_0E03001F” (BCC, CC I believe) that are missing from the Aspose-created MSG. Manually creating these streams in a modified version of the Aspose message did NOT yield an openable item.

I feel like there are either missing fields or some kind of internal consistency error, but have not been able to prove it as of yet. Unfortunately, we are unable to provide a sample unless we can reproduce it with non-sensitive data. If it’s helpful, I can provide a listing of the streams/storages and their sizes so you can get a sense for the internal structure of the items.

1 Like

@tucker.barbour,

Can you please share source file along with sample project so that we may further investigate to help you out.

Adnan,

I’ve been helping out with some analysis on this issue. We are still trying to get clearance to share a sample file, but I did some across something that I think I can share in the meantime. I found the following data in the main __properties_version1.0 stream of the MSG.

hex.png (7.6 KB)

I can overwrite this field’s tag/data with the data from another field, and the file becomes openable within Outlook. It looks like this field is “PidTagSentMailSvrEID” and the field type is [MS-OXCDATA]: PtypServerId Type | Microsoft Learn.

I don’t get enough feedback from Outlook to determine if the presence of the field is causing the crash or if the data is bad, but I’m wondering if that helps with any diagnosis on your side.

Adnan,

I’ll also add that we’ve seen similar behavior with other MSG files that were saved out of other PSTs. It’s not one specific field in every case. As I’ve looked at examples, I’ve seen different properties which seem to cause issues, including “PidTagSentMailSvrEID”, “BigFunnelCorrelationID”, “NetworkMessageId”. In every case we’ve tested, the MSG file with problematic properties were generated with the following code (paraphrased):

PersonalStorage pst = PersonalStorage.fromFile(pstPath, false);
pst.saveMessageToFile(entryId, msgPath);

we’ve been able to re-open and re-save corrected versions of these problematic messages by running:

MapiMessage message = MapiMessage.fromFile(msgPath);
message.save(newMsgPath);

This is able to readproblematic properties and either suppress them on the re-save or output data that Outlook 2016 is better able to read.

Perhaps there’s some key difference in the code path between “pst.saveMessageToFile” and “mapi_message.save”?

@adamjreilly,

Can you please share complete working project reproducing issue so that we may further investigate to help you out. Also please share complete environment details along with version details that you are using on your end. The actual issue you created PST which are unable to open please inform me if i understood your issue correct.