Class MboxStorageReader

MboxStorageReader class

Represents an MBOX file and provides methods for reading and extracting messages. The MBOX file format is used for storing a collection of email messages.

public abstract class MboxStorageReader : IDisposable

Properties

NameDescription
BaseStream { get; }Gets the base stream.
CurrentDataSize { get; }Gets the number of bytes that is read by ReadNextMessage method.

Methods

NameDescription
static CreateReader(Stream, MboxLoadOptions)Creates the instance of reader.
static CreateReader(string, MboxLoadOptions)Creates the instance of reader.
Dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
EnumerateMessageInfo()Exposes the enumerator, which supports an iteration of messages in storage.
EnumerateMessageInfo(MailQuery)Enumerates the message information that matches the specified query.
EnumerateMessageInfo(int, int)Enumerates a specified number of message information entries, starting from the given index.
EnumerateMessages()Exposes the enumerator, which supports an iteration of messages in storage.
EnumerateMessages(EmlLoadOptions)Exposes the enumerator, which supports an iteration of messages in storage.
EnumerateMessages(MailQuery)Enumerates the mail messages that match the specified query.
EnumerateMessages(EmlLoadOptions, MailQuery)Enumerates the mail messages that match the specified query, using the provided load options.
EnumerateMessages(int, int)Enumerates a specified number of mail messages, starting from the given index.
EnumerateMessages(EmlLoadOptions, int, int)Enumerates a specified number of mail messages, starting from the given index, using the provided load options.
ExtractMessage(string, EmlLoadOptions)Get the message from MBOX.
abstract GetTotalItemsCount()Returns the number of messages in a storage.
abstract NextMessage()Gets the next message info.
abstract ReadNextMessage()Reads the next message from underlying storage stream.
abstract ReadNextMessage(EmlLoadOptions)Reads the next message from underlying storage stream.
abstract ReadNextMessage(out string)Reads the next message from underlying storage stream.
abstract ReadNextMessage(out string, EmlLoadOptions)Reads the next message from underlying storage stream.
SplitInto(long, string)Splits the mbox storage into less sized parts.
SplitInto(long, string, string)
SplitIntoAsync(long, string, CancellationToken)Splits the mbox storage into less sized parts.
SplitIntoAsync(long, string, string, CancellationToken)Splits the mbox storage into less sized parts.
static CreateReaderAsync(Stream, MboxLoadOptions, CancellationToken)Creates the instance of reader.
static CreateReaderAsync(string, MboxLoadOptions, CancellationToken)Creates the instance of reader.

Events

NameDescription
event EmlCopiedEvent that occurs after successful copy of a MailMessage object within the SplitInto method.
event EmlCopyingEvent that occurs before the MailMessage object copy process, within the SplitInto method.
event MboxFileCreatedEvent that occurs when a new MBOX file is created during the SplitInto method.
event MboxFileFilledEvent that occurs after filling an MBOX file with data within the SplitInto method.

Examples

The following code provided is intended for processing email messages stored in an MBOX file using the MboxStorageReader class.

[C#]

// Create an instance of the MboxStorageReader using the factory method 'CreateReader'.
var mbox = MboxStorageReader.CreateReader("storage.mbox", new MboxLoadOptions());

// Iterate through each message info object in the mbox storage.
foreach (var mboxMessageInfo in mbox.EnumerateMessageInfo())
{
    Console.WriteLine($"Subject: {mboxMessageInfo.Subject}");
    Console.WriteLine($"From: {mboxMessageInfo.From}");
    Console.WriteLine($"To: {mboxMessageInfo.To}");

    // Extract the full MIME message object from the MBOX storage using the message's unique entry ID.
    var eml = mbox.ExtractMessage(mboxMessageInfo.EntryId, new EmlLoadOptions());
    
    // Save the extracted MIME message as an .eml file.
    eml.Save($"{eml.Subject}.eml");
}

[Visual Basic]

' Create an instance of the MboxStorageReader using the factory method 'CreateReader'.
Dim mbox As MboxStorageReader = MboxStorageReader.CreateReader("storage.mbox", New MboxLoadOptions())

' Iterate through each message info object in the mbox storage.
For Each mboxMessageInfo As var In mbox.EnumerateMessageInfo()
    Console.WriteLine($"Subject: {mboxMessageInfo.Subject}")
    Console.WriteLine($"From: {mboxMessageInfo.From}")
    Console.WriteLine($"To: {mboxMessageInfo.To}")

    ' Extract the full MIME message object from the MBOX storage using the message's unique entry ID.
    Dim eml As var = mbox.ExtractMessage(mboxMessageInfo.EntryId, New EmlLoadOptions())

    ' Save the extracted MIME message as an .eml file.
    eml.Save($"{eml.Subject}.eml")
Next

See Also