Convert mailboxes
editMailboxConverter.Convert converts a mailbox, with its tree of folders, to another format: to migrate from Outlook to Thunderbird, to archive a Maildir folder in an Outlook data file...
// 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));| Format | Source | Folders |
|---|---|---|
| Outlook data file | A .pst or .ost file | The folders under the top of the personal folders; the search folders are skipped |
| mbox | A directory, or a single mbox file | A file per folder, and the subfolders of a folder in a directory <name>.sbd, as Thunderbird stores them; the summaries (.msf) and the other files are skipped |
| Maildir | A directory with cur, new and tmp | The root is the inbox, and the subfolders are Maildir++ folders: .Archive.2026 is the subfolder 2026 of Archive |
DetectFormat gives the format of the source. The destination must not exist, or be an empty directory.
Export the messages to files
Two more formats are only destinations. They export a mailbox to a directory of message files, with one subdirectory per folder (Inbox, Archive/2026):
| Format | Files |
|---|---|
| MailboxFormat.Eml | An email message (.eml) per message. The messages of mbox and Maildir folders are copied as they are |
| MailboxFormat.Msg | An Outlook item (.msg) per item. As in an Outlook data file, the contacts, appointments and other items are kept, and a message keeps its read state |
A file is named after the subject of its message, with the characters a file name cannot have replaced with _. A message without a subject is named Message, and two messages of a folder with the same name get _2, _3...: Hello.eml, Hello_2.eml. An .eml file has no read state.
What is kept
- The messages of mbox and Maildir folders are copied as they are between these formats, with the LF line breaks of the mbox files. They are converted to and from the items of an Outlook data file through EmailMessage: what one of the formats cannot store is lost (see Getting started).
- The read state is kept: the
Seenflag of Maildir, the read flag of Outlook, and in mbox files theX-Mozilla-Statusheader of Thunderbird or theStatusheader (Status: RO), which the converter adds to the messages that are read. An mbox message with neither header is read in an Outlook data file, and unread in a Maildir folder. - An Outlook data file has items that are not emails: contacts, appointments, tasks, notes... An Outlook data file destination keeps them; an mbox or Maildir destination skips them and counts them in SkippedItemCount, unless IncludeNonMailItems writes them as email messages. Meeting requests are emails.
- A message that cannot be read or written is skipped, and the next messages are converted. It is reported in Errors with its folder.
- An Outlook data file the converter writes has the folders Outlook requires, such as Deleted Items. Its folders keep the type of the folders of a source Outlook data file (calendar, contacts, tasks...), and are folders of emails otherwise.
- The folders of mbox and Maildir destinations have valid file names: the characters a file name or a Maildir++ name cannot have, such as
.and/, are replaced with_. Two folders that would get the same name, such asProject.AandProject_A, or names that differ only in case, get different names:Project_AandProject_A_2. The names of the devices of Windows, such asCONorNUL, get a leading_.