Introduction
An .msg file is a single item saved from
Microsoft Outlook on
Windows: usually an email, but it can also be a meeting request, a contact or a task.
It is what Outlook writes when a message is dragged out to a folder or saved with
“Save As”. Unlike an EML file, which holds the message
as it was sent, an .msg file holds Outlook’s own list of the item’s
properties, so it keeps details such as flags and categories.
Microsoft publishes the format as [MS-OXMSG] in its Open Specifications.
Structure
The file is a Compound File Binary file, the same container as old Word and Excel
files, so it starts with D0 CF 11 E0 A1 B1 1A E1. Inside are storages and
streams, like folders and files:
__properties_version1.0: a table of the item’s fixed-size properties, such as flags, dates and sizes__substg1.0_XXXXYYYY: one stream per variable-size property, whereXXXXis the property ID andYYYYits type in hexadecimal; for example__substg1.0_0037001Fis the subject as UTF-16 text__recip_version1.0_#00000000and so on: one storage per recipient__attach_version1.0_#00000000and so on: one storage per attachment, which can hold another whole message__nameid_version1.0: the mapping for named properties
The body may be stored as plain text, as HTML, or as compressed RTF, often more than one of these. The compound file container and storages and properties pages give the details.
Viewer
Drop an .msg file on the viewer. The Structure tree is the compound file as it sits in
the file: the header, then runs of sectors (FAT, directory, mini stream, each stream), and inside each stream what
[MS-OXMSG] says it holds, for example the 32-byte header of the property stream and its 16-byte entries (tag, flags,
value or size), the value of each variable length property, the lengths of a multiple-valued one, and the named
property mapping.
The tabs show the item. Overview: the message class and what kind of item it is, the subject, people, dates, string encoding and counts. Properties: every property of the message, its recipients, its attachments and its embedded messages, by tag, name, type, flags, size and value; a tag the viewer has no name for is shown by its hex tag and type. Recipients, Attachments (each one held by value opens as a file) and Embedded messages. Body: the plain text, the HTML and the compressed RTF, which is decompressed with [MS-OXRTFCP] and its CRC checked; the RTF tab shows the header and the result. Named properties: each mapping, with its property set, its LID or name, and whether its entry is in the name-to-ID stream the equations give. Streams: every storage and stream of the file and what it is for.
Every problem is listed, labelled Structure, Conformance (a MUST of [MS-OXMSG]) or Warning: a missing property stream or value stream, a size or count that disagrees, a stream with no property entry, a named property with no mapping, strings of the wrong kind for the file, a damaged compound file, a compressed RTF whose CRC does not match.
Not described
The pages follow [MS-CFB], [MS-OXMSG], [MS-OXCDATA], [MS-OXPROPS], [MS-OXCMSG], [MS-OXOMSG] and [MS-OXRTFCP]. The full property list of [MS-OXPROPS] is on three pages (577 PidTag, 365 PidLid and 139 PidName properties: identity, type and area), and the binary property structures of [MS-OXCDATA] (entry IDs, property rows, recipient rows, restrictions) are laid out.
Known, not yet covered
- Viewer: the viewer names 106 tagged and 54 named properties, written by hand from
[MS-OXPROPS] (the ones a
.msgfile most often holds). Every other property is shown with its hex tag and type, never dropped; the three property pages above name them all, but the viewer does not read those pages. - Viewer: the binary property structures (recurrence patterns, time zones, entry IDs, property rows, laid out on their page) are shown as bytes, not decoded.
- Viewer: a compressed RTF body is decompressed and its CRC checked, and the RTF source is shown; it is not rendered, and HTML carried inside the RTF is not extracted.
- Viewer: an embedded message is read in full (its properties, recipients and attachments are in
the tabs, and its attachments open as files) but cannot be opened as a file of its own. A storage attachment
(
afStorage) is listed as the application’s own streams and not interpreted. - Viewer: an HTML body is decoded with the item’s code page property (UTF-8 when there is none);
a
meta charsetinside the HTML is not read. - Viewer: only compound files of version 3 were checked against real messages; no real version 4
(4,096-byte sector)
.msgfile was available.
Unknown
- Reference: [MS-OXMSG] 2.2.3.2.2.1 says the string named properties are hashed with “CRC-32” of the Unicode name and does not give the variant. In every file read (the Apache POI test messages) it is the CRC-32 polynomial 0xEDB88320 with an initial value of 0 and no final inversion, over the UTF-16LE bytes of the name, the same CRC as [MS-OXRTFCP]. Viewer: it checks that every named property has its entry in the stream the stream ID equation names, trying the name as stored and lower-cased (the specification says Outlook lower-cases PS_INTERNET_HEADERS names).
- Reference: for a PtypString8 or PtypString property, [MS-OXMSG] 2.4.2.2 says the size in the property entry is 1 or 2 plus the size of the stream. In the Apache POI test messages saved without Unicode the size equals the stream size, whose last byte is the end of the string. Viewer: both are accepted, the second with a warning; a zero-length string stream (which the specification forbids) is also a warning, because Outlook-made files hold them.
- Viewer: a stream such as
Olk10SideProps_0001, found in one of the Apache POI test messages, which [MS-OXMSG] does not define, is listed as raw bytes with a warning. - Reference: for each of the roughly 1,080 properties the specification also gives a description, a WebDAV name,
defining and consuming references and alternate names (the old
PR_anddispidnames); the property pages give identity, type and area only, and the meaning of the ones not on the storages and properties page is in [MS-OXPROPS] and the document that defines each one. The general error and warning codes (sections 2.4 and 2.4.3) of [MS-OXCDATA] are not listed.
Links
Software
- Microsoft Outlook – Microsoft’s email program, which saves and opens .msg items (Windows)
Developers
- extract-msg – reads
.msgfiles and their attachments (Python) - MSGReader – reads
.msgfiles (.NET)
Reference
- [MS-OXMSG]: Outlook Item (.msg) File Format – Microsoft’s published specification, in its Open Specifications