Convert mailboxes

edit

MailboxConverter.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));
FormatSourceFolders
Outlook data fileA .pst or .ost fileThe folders under the top of the personal folders; the search folders are skipped
mboxA directory, or a single mbox fileA 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
MaildirA directory with cur, new and tmpThe 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):

FormatFiles
MailboxFormat.EmlAn email message (.eml) per message. The messages of mbox and Maildir folders are copied as they are
MailboxFormat.MsgAn 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 Seen flag of Maildir, the read flag of Outlook, and in mbox files the X-Mozilla-Status header of Thunderbird or the Status header (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 as Project.A and Project_A, or names that differ only in case, get different names: Project_A and Project_A_2. The names of the devices of Windows, such as CON or NUL, get a leading _.