OutlookMailStore Class
Definition
- Assembly
- Bodu.Formats.Outlook.Pst.dll
- Package
- Bodu.Formats.Outlook.Pst 0.7.1
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
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
streamStreamThe readable, seekable stream to sniff.
Returns
Exceptions
- ArgumentNullException
Thrown if
streamis 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
streamStreamThe readable, seekable stream positioned at the file start.
optionsOutlookMailStoreReaderOptionsThe reader options.
leaveOpenbooltrue to leave the stream open when the session is disposed.
Returns
- OutlookMailStore
The open session.
Exceptions
- ArgumentNullException
Thrown if
streamoroptionsis 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
streamStreamThe readable, seekable stream positioned at the file start.
leaveOpenbooltrue to leave the stream open when the session is disposed.
Returns
- OutlookMailStore
The open session.
Exceptions
- ArgumentNullException
Thrown if
streamis 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
pathstringThe file path.
Returns
- OutlookMailStore
The open session.
Exceptions
- ArgumentNullException
Thrown if
pathis 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
nameMapiNamedPropertyThe named-property identity.
idushortWhen 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
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
tagMapiPropertyTagA tag whose identifier is in the named range (at or above
0x8000).nameMapiNamedPropertyWhen this method returns true, the identity.
Returns
Exceptions
- ObjectDisposedException
The session has been disposed.
- PstFileException
The container is malformed.
- OutlookPstFormatException
Under strict validation, the mapping streams are malformed.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |