MailboxConverter Class

Converts a mailbox from one format to another, with its tree of folders: an Outlook data file, a folder of mbox files (Thunderbird) or a Maildir folder. The messages of mbox and Maildir folders are copied as they are between these formats (an mbox file has LF line breaks), and converted through EmailMessage to and from Outlook data files. A mailbox can also be exported to a directory of message files (MailboxFormat.Eml, MailboxFormat.Msg).

public static class MailboxConverter

Example

// An Outlook data file to the folders of Thunderbird, then to a Maildir folder
var result = MailboxConverter.Convert(pstPath, mboxPath, MailboxFormat.Mbox);
Assert.Empty(result.Errors);
Assert.True(File.Exists(Path.Combine(mboxPath, "Inbox")));

var copy = MailboxConverter.Convert(mboxPath, maildirPath, MailboxFormat.Maildir);
Assert.Equal(result.MessageCount, copy.MessageCount);
Assert.Equal(MailboxFormat.Maildir, MailboxConverter.DetectFormat(maildirPath));

Methods

NameDescription
Convert(string, string, MailboxFormat, MailboxConversionOptions?)Converts a mailbox, whose format is detected (see MailboxConverter.DetectFormat), to another format.
DetectFormat(string)Returns the format of a mailbox: a directory with cur, new and tmp is a Maildir folder, another directory a folder of mbox files, and a file is detected from its content.

Convert(string, string, MailboxFormat, MailboxConversionOptions?)

MailboxConverter.cs

Converts a mailbox, whose format is detected (see MailboxConverter.DetectFormat), to another format.

public static MailboxConversionResult Convert(string sourcePath, string destinationPath, MailboxFormat destinationFormat, MailboxConversionOptions? options = null)

Parameters

sourcePath string
The path of the mailbox to read.
destinationPath string
The path of the mailbox to write: the file of an Outlook data file, or the directory of an mbox or a Maildir mailbox. It must not exist, or be an empty directory.
destinationFormat MailboxFormat
The format of the mailbox to write.
options MailboxConversionOptions?
The options, or null for the default options.

Returns

MailboxConversionResult The number of folders and messages written, and the messages that could not be converted.

Exceptions

InvalidOperationException
The source is not a mailbox the converter reads.
IOException
The destination exists, or a file cannot be read or written.
EmailException
The source is malformed, beyond the messages the converter skips.

DetectFormat(string)

MailboxConverter.cs

Returns the format of a mailbox: a directory with cur, new and tmp is a Maildir folder, another directory a folder of mbox files, and a file is detected from its content.

public static MailboxFormat? DetectFormat(string path)

Parameters

path string
The path of the file or of the directory.

Returns

MailboxFormat? The format, or null when the path is not a mailbox the converter reads.

Exceptions

IOException
The file cannot be read.