MAPI properties

edit

Every object of a file is a set of MAPI properties, identified by a 16-bit identifier and typed: the members of MapiMessage and of the other types read some of them. Properties gives all of them, as a MapiPropertyCollection:

using var file = PstFile.Open(path);
var appointment = file.GetFolder("Calendar")!.EnumerateItems().Single();

// A property from its identifier (PidTagMessageClass, 0x001A), whatever its type
Assert.Equal("IPM.Appointment", appointment.Properties.GetValueOrDefault<string>(0x001A));

// A named property from its property set and its identifier (PidLidLocation of PSETID_Appointment)
var location = new MapiNamedProperty(MapiPropertySets.Appointment, 0x8208);
Assert.NotNull(appointment.Properties.Find(location));

// All the properties, with their tags, their names and their values
foreach (var property in appointment.Properties)
{
    Assert.NotEqual(MapiPropertyType.Unspecified, property.Type);
}
  • Find returns a property from its identifier, its tag or its name; GetValueOrDefault and TryGetValue convert its value.
  • The Value of a property is read when it is first accessed, as the .NET type that MapiPropertyType documents: strings, dates in UTC, bytes for the binary values, arrays for the multi-valued properties. OpenRead reads a large value block by block.
  • The 8-bit strings of an ANSI file (and of some properties of the Unicode files) are decoded with the code page of the message (PidTagMessageCodepage), or 1252 when it does not have one.
  • The subject a property stores can start with the characters 0x01 and the length of its prefix (such as RE: ): Subject removes them.

Named properties

The identifiers from 0x8000 are named properties: the file maps each one to a name, made of a property set (a GUID) and either a numeric identifier or a string. The identifiers differ from one file to another, so a named property is looked up by its MapiNamedProperty, and NamedProperty gives the name of a property. MapiPropertySets lists the common property sets. The names and the types of the properties Outlook uses are in the [MS-OXPROPS] specification.