Misbehavior in parsing OLE2 Messages/Storages

Hello
There’s a problem reading OLE2 messages/storages causing some headers to return null/empty values.
A ready to run project with a sample OST is attached to see the effect, using v22.9 with recent bug fixes applied.
Run and check all the ComboBox items to se they exist in any folder!
From/To/CC/BCC fields are affected, plus I found incorrect Date.Min for some messages’ date field (reported in a separate thread)
Please consider this description:

OLE2 format saves sender and recipients in two places: Internet headers and separate properties. Usually, they match. Sometimes, they don’t.

Condition 1 :: If the OLE2 message/storage doesn’t have Internet headers at all (i.e. it’s a draft which has never been sent), it won’t have Internet headers anyway and From/To/CC/BCC MUST be obtained from their designated properties only.

Condition 2 :: If the .MSG message does have Internet headers but doesn’t have From/To/CC/BCC in separate properties, only values from Internet headers MUST be used.

Condition 3 :: If both exist and are different for each field (From/To/CC/BCC) should take the proper decision for each one, I’ve no idea on choose which one or add a property for use to choose.
(if this happens, must be effective only when both exists and are different, to specify prefer which one.

BUG :: You are ONLY reading From/To/CC/BCC from separate properties, and not from Internet headers, not only for this OST file, for all the OLE2 Outlook based messages like MSG.
I think should consider this to assign the following fields from Internet headers if their properties are null / empty:

MessageInfo.SenderRepresentativeName
MessageInfo.DisplayTo
MessageInfo.DisplayCC
MessageInfo.DisplayBCC << W8, does not exists, hope it can be added :frowning:

WindowsApplication1.zip (9.9 MB)

@australian.dev.nerds

We have logged this problem in our issue tracking system as EMAILNET-40757. We will inform you once there is an update available on it. We apologize for your inconvenience.

@australian.dev.nerds

The capabilities of MessageInfo are limited. PST has a table which is a list of messages in a folder. In this list, each line is information about the message: mainly its identifier and a limited set of properties. In order to quickly understand what the message is, without extracting the entire message. We will have to extract all additional properties not presented in this table from the message, and this is already an additional performance cost.

You can see what properties MessageInfo contains - [MS-PST]: Contents Table Template | Microsoft Learn
As you can see, DisplayBcc is not there, which means we will have to get it from the message data.

Therefore, if you need other properties, you can download the full message.

FolderInfo folder = pst.RootFolder.GetSubFolder("Inbox");
foreach (MessageInfo messageInfo in folder.EnumerateMessages())
{
    MapiMessage msg = pst.ExtractMessage(messageInfo);
    string bcc = msg.DisplayBcc;
    string from = msg.Headers["From"];
}

or use the pst.ExtractProperty method to get one property.

FolderInfo folder = pst.RootFolder.GetSubFolder("Inbox");
foreach (MessageInfo message in folder.EnumerateMessages())
{
    MapiProperty displayBcc = pst.ExtractProperty(
        message.EntryId, MapiPropertyTag.PR_DISPLAY_BCC);
    if (displayBcc != null)
    {
        string bcc = displayBcc.ToString();
    }
}
1 Like