Table of Contents

OutlookMailStore Class

Definition

Namespace
Bodu.Formats.Outlook
Assembly
Bodu.Formats.Outlook.Pst.dll
Package
Bodu.Formats.Outlook.Pst 0.7.1
Source
OutlookMailStore.NamedProperties.cs

Provides a disposable, read-only session over an Outlook personal-folders mail store (a .pst file, MS-PST Unicode or ANSI format): the store properties, the folder hierarchy, and the messages within it, decoded into the shared MAPI value model.

public sealed class OutlookMailStore : IDisposable
Inheritance
OutlookMailStore
Implements
Inherited Members
Extension Methods

Remarks

The session owns its PstFile container (and the source stream unless it is left open); every OutlookMailFolder and OutlookMailMessage obtained from it is a view bound to the session's lifetime - disposing the store invalidates them all. Reads are lazy and streaming-first: opening parses only the container header, folder and message enumerations stream table rows, and each object decodes its properties once on first access.

The session is single-threaded, matching the container's documented contract: its members - and the members of every view obtained from it - must not be called concurrently.

using Bodu.Formats.Outlook;

using var store = OutlookMailStore.OpenRead("archive.pst");

foreach (OutlookMailFolder folder in store.RootFolder.EnumerateSubfolders())
{
    Console.WriteLine(folder.DisplayName);
    foreach (OutlookMailMessage message in folder.EnumerateMessages())
        Console.WriteLine($"  {message.Subject} - {message.SenderName}");
}

Properties

DisplayName

Gets the store display name.

public string? DisplayName { get; }

Property Value

string

The PidTagDisplayName value, or null when absent.

Exceptions

ObjectDisposedException

The session has been disposed.

Properties

Gets every decoded property of the store object.

public MapiPropertyCollection Properties { get; }

Property Value

MapiPropertyCollection

The tag-addressed property collection, decoded once on first access.

Exceptions

ObjectDisposedException

The session has been disposed.

PstFileException

The container is malformed.

RootFolder

Gets the root of the store's folder hierarchy.

public OutlookMailFolder RootFolder { get; }

Property Value

OutlookMailFolder

The root folder view, created once on first access.

Remarks

The root folder itself is structural - user folders (the IPM subtree) hang beneath it. Walk EnumerateSubfolders() to reach them.

Exceptions

ObjectDisposedException

The session has been disposed.

PstFileException

The container is malformed.

Methods

Dispose()

Releases the session and its container (and source stream, unless it was left open).

public void Dispose()

IsPstFile(Stream)

Determines whether a stream begins with the PST magics; its position is restored before returning.

public static bool IsPstFile(Stream stream)

Parameters

stream Stream

The readable, seekable stream to sniff.

Returns

bool

true when the stream looks like a PST file of any variant.

Exceptions

ArgumentNullException

Thrown if stream is null.

Open(Stream, OutlookMailStoreReaderOptions, bool)

Opens a mail store from a stream with explicit options.

public static OutlookMailStore Open(Stream stream, OutlookMailStoreReaderOptions options, bool leaveOpen = false)

Parameters

stream Stream

The readable, seekable stream positioned at the file start.

options OutlookMailStoreReaderOptions

The reader options.

leaveOpen bool

true to leave the stream open when the session is disposed.

Returns

OutlookMailStore

The open session.

Exceptions

ArgumentNullException

Thrown if stream or options is null.

ArgumentException

The stream is not readable and seekable.

PstFileFormatException

The stream is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

OpenRead(Stream, bool)

Opens a mail store from a stream with default options.

public static OutlookMailStore OpenRead(Stream stream, bool leaveOpen = false)

Parameters

stream Stream

The readable, seekable stream positioned at the file start.

leaveOpen bool

true to leave the stream open when the session is disposed.

Returns

OutlookMailStore

The open session.

Exceptions

ArgumentNullException

Thrown if stream is null.

ArgumentException

The stream is not readable and seekable.

PstFileFormatException

The stream is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

OpenRead(string)

Opens a mail store from a path with default options.

public static OutlookMailStore OpenRead(string path)

Parameters

path string

The file path.

Returns

OutlookMailStore

The open session.

Exceptions

ArgumentNullException

Thrown if path is null.

PstFileFormatException

The file is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

TryGetNamedPropertyId(MapiNamedProperty, out ushort)

Attempts to resolve the property identifier a named property maps to in this store.

public bool TryGetNamedPropertyId(MapiNamedProperty name, out ushort id)

Parameters

name MapiNamedProperty

The named-property identity.

id ushort

When this method returns true, the file-specific identifier (at or above 0x8000) the name maps to; combine it with the expected MapiPropertyType to address an object's properties.

Returns

bool

true when the store maps the name.

Remarks

The mapping is store-wide (MS-PST keeps one name-to-id map per file), so a single resolution applies to every message and attachment of the session.

Exceptions

ObjectDisposedException

The session has been disposed.

PstFileException

The container is malformed.

OutlookPstFormatException

Under strict validation, the mapping streams are malformed.

TryGetPropertyName(MapiPropertyTag, out MapiNamedProperty)

Attempts to resolve the named-property identity behind a property tag.

public bool TryGetPropertyName(MapiPropertyTag tag, out MapiNamedProperty name)

Parameters

tag MapiPropertyTag

A tag whose identifier is in the named range (at or above 0x8000).

name MapiNamedProperty

When this method returns true, the identity.

Returns

bool

true when the store maps the tag's identifier.

Exceptions

ObjectDisposedException

The session has been disposed.

PstFileException

The container is malformed.

OutlookPstFormatException

Under strict validation, the mapping streams are malformed.

Applies to

ProductVersions
.NET8, 10