MboxReader Class

Reads the messages of an mbox file, the format of the mailboxes of Unix mail tools and of Thunderbird: messages one after the other, each one after a line that starts with From . The messages are read one at a time.

public static class MboxReader

Example

foreach (var entry in MboxReader.ReadMessages(path, new MboxReadOptions { Format = MboxFormat.Mboxrd }))
{
    // The envelope sender and the date of the "From " line, then the message, read when it is accessed
    var sender = entry.Sender;
    var subject = entry.Message.Subject;
    Assert.NotNull(sender);
    Assert.NotNull(subject);
}

Methods

NameDescription
ReadMessages(Stream, MboxReadOptions?)Reads the messages of an mbox stream, until its end.
ReadMessages(string, MboxReadOptions?)Reads the messages of an mbox file.

ReadMessages overloads

ReadMessages(Stream, MboxReadOptions?)

MboxReader.cs

Reads the messages of an mbox stream, until its end.

public static IEnumerable<MboxMessage> ReadMessages(Stream stream, MboxReadOptions? options = null)
Parameters
stream Stream
The stream.
options MboxReadOptions?
The options, or null for the default options.
Returns

IEnumerable<MboxMessage> The messages, read as they are enumerated.

Exceptions
InvalidEmailDataException
The stream does not start with a From line, or a Content-Length header does not end a message.
EmailResourceLimitException
A message is larger than MimeReadOptions.MaxSize.

ReadMessages(string, MboxReadOptions?)

MboxReader.cs

Reads the messages of an mbox file.

public static IEnumerable<MboxMessage> ReadMessages(string path, MboxReadOptions? options = null)
Parameters
path string
The path of the file.
options MboxReadOptions?
The options, or null for the default options.
Returns

IEnumerable<MboxMessage> The messages, read as they are enumerated.

Exceptions
InvalidEmailDataException
The file does not start with a From line, or a Content-Length header does not end a message.
EmailResourceLimitException
A message is larger than MimeReadOptions.MaxSize.