Several ruminations on this topic can be found on the Internet. None (that is easily found) answers the question though, especially for those not familiar with both formats in detail.

The relevant article on Mozilla wiki notes in its first paragraph: “Thunderbird's maildir implementation allows a single unique filename per email (EML). HOWEVER, note this is NOT full maildir in the sense that most people, particularly linux users or mail administrators, know as maildir.” So, presumably, Thunderbird's stock converter does not offer the proper solution.

Dovecot recommends dsync but it is presumably developed for dovecot specifically. I want to quit using Thunderbird but I don't intend to use Dovecot right now, with its wiki mentioning some “Maildir++”. Dovecot also recommends (ibid.) mb2md.pl with some patches of Dovecot's own. mb2md seems to be what's recommended in general.

However, there are two implementations of mb2md: a sh+Python script and a Perl script. The former is the original implementation, and its page says literally the following about the Perl version: “if you encounter this particular [seemingly absurdly trivial environment-related] issue with my script, give it [the Perl implementation] a try”, and nothing else. It's not clear whether those two scripts operate the same way or even support the same syntax. (Brief inspection suggests it doesn't; why use the same name then?) Python version is reportedly from 2006 which makes it more than 10 years old as of today. It also so happens that the distribution I use (Gentoo) does not seem to have mb2md in its repository. I could install Dovecot and use its converter but this doesn't feel right.

Even though the matter might be trivial (mbox is nothing but string concatenation of eml's, right?), all the above is alarming: for a more than 10 year old format (Maildir), widely considered superior to mbox, there apparently is no standard migration mechanism. I don't want to convert blindly, only to find out later that some data was lost, as the mb2md page warns, or that I can't add more messages to the new Maildir storage without losing consistency, as mentioned in mbsync man page (search for the phrase “native scheme is faster”).

For the record, I intend to use mbsync with the new Maildir storage. Hopefully, the answer would not depend on this.

  1. Will the 10 year old sh+Python mb2md converter work as fine with modern mboxen as it did with 2006 ones?
  2. Thunderbird directory contains Mail, ImapMail, News and Feeds subdirectories, which, in turn, contain other files. Are INBOX files the only mbox files, or I might miss some others?
  3. Should I convert each mbox file with mb2md separately and do I have to somehow manually connect or group them in Maildir storage?
  4. In the past, Thunderbird offered “compacting” folders, whatever that means, and the user said yes. Does it affect the conversion process?
  5. What should I take into account when choosing between different mb2md versions? Assume, for the sake of completeness, that tags, PGP encryption and signatures in various forms were heavily used in Thunderbird.
  • 1
    "Python version is reportedly from 2006 which makes it more than 10 years old as of today." - I can point to code that exists that is 30 years old and in production use. Does code expire like milk? I am pointing this out because, the age of the program shouldn't matter, unless flat out doesn't work anymore. The fact it doesn't work also woudln't have anything to do with its age, because to be honest, it likely never worked or better stated "worked well". You will have to answer most of these questions for us.
    – Ramhound
    Commented Jan 19, 2017 at 19:57
  • Script did not expire. Mail could change though. That's why I said “work with mboxen” and not “run”.
    – akater
    Commented Jan 19, 2017 at 22:42

6 Answers 6


The answer by wbob is useful and detailed. However, I had used a different solution before wbob suggested dovecot conversion. Besides, I ended up with notmuch storage. I have to accept my own answer because that's what got used after all.

I employed a simple Python script making use of mailbox library. (Thanks to notmuch IRC channel on freenode.)

import mailbox
import sys
import os
mbox_filename = sys.argv[1]
maildir_root_dir_name = sys.argv[2]
mbox = mailbox.mbox(mbox_filename, create=False)
mailbox_name = os.path.basename(mbox_filename)
maildir_dir_name = "/".join((maildir_root_dir_name, mailbox_name))
os.mkdir(maildir_dir_name, mode=0o750)
mdir = mailbox.Maildir(maildir_dir_name, create=True)
os.mkdir("/".join((maildir_dir_name, "cur")), mode=0o750)
os.mkdir("/".join((maildir_dir_name, "new")), mode=0o750)
os.mkdir("/".join((maildir_dir_name, "tmp")), mode=0o750)
count = 0
for x in mbox:
    count += 1
    if count % 1000 == 0:

Some messages were broken; the script stopped with error and a line number, so I had to use emacs (with vlf to open large files, I believe) to fix the problematic messages in mbox file.

The question deserves more elaborate answer, as it's quite troublesome to accomplish the task for most users. Hopefully, I'll expand this in future.


For Thunderbird users, version 60 brought experimental bidirectional mbox to Maildir conversion support. See meta ticket for open issues. Personally I can recommend the dovecot dsync method.

Having recently converted largish Thunderbird mbox folders to Maildir and evaluated your mentioned links, I cannot recommend any of the helper-scripts. There was a 'From:' split one script missed and the message count pre/post migration didn't match, other issues were text-encoding or timestamps with other conversion scripts found on github.

Instead, dsync gave fast (1-2 min on 25k messages) and consistent results, see your mentioned Migration/MailFormat Wiki page: dsync -Dv mirror mbox:~/.thunderbird/<profile/popMail/Account>:INBOX=Inbox. As noted, configure the mail_location=maildir:~/Maildir beforehand at /etc/dovecot/conf.d/10-mail.conf. Start with an empty folder and later make it the Account Folder for the Maildir-enabled Thunderbird with some manual cleanup. {cur,new,tmp} in the basedir have to move into "Inbox" and the folder .dot-prefix can be removed. Having a second Maildir-enabled profile will give directions what Thunderbird expects.

  • What's the simplest way to get dysnc? Do I need the entire dovecot server install on my laptop? Is it a standalone script or do I need to essentially install dovecot, import the Thunderbird mbox file into dovecot, then export it using dsync? Commented Apr 18, 2022 at 3:47
  • 1
    in Debian dsync is part of dovecot-core, it's a small and quick install, you can remove it afterwards. I think export/import terms are misleading: you convert directly from the mbox Path (any path) into the mail_location target given. You use dovecot code, but you end up with a Maildir
    – wbob
    Commented Apr 19, 2022 at 13:52

Thanks to wbob for the information on dsync. Extremely helpful. However, I found that converting a Thunderbird 'mbox' to Maildir was slightly more convoluted and I first had to run dsync on the ~/.thunderbird/path/to/folder/.

It still resulted in a single mbox file per folder. But I could then run mb2md (Debian Bullseye package) on the resultant root folder. (Without running dsync first, mb2md would only produce 2 files in the resultant folder. One of which was the contents of the huge preceding mbox file.)

It's worth noting also that I could not get Thunderbird to correctly use Maildir format when setting it to "File per message (maildir)".

The resulting 9000+ emails were then moved to the actual user's ~/Maildir and everything was migrated across (from GMail to a local server) without any apparent errors.

Here are the exact steps:

sudo dsync -u username mirror mbox:~/.thunderbird/o9oln6fe.default-default/ImapMail/
mb2md -s ~/mail/imap.gmail.com/ -R```
  • hi wcweb! did you have mail_location at /etc/dovecot/conf.d/10-mail.conf set to something prefixed with maildir:? dsync should have no other choice but to convert directly to Maildir, skipping any other tool like mb2md
    – wbob
    Commented Jul 10, 2022 at 9:40
  • Ah, thank you. It was unclear what you meant by "configure the mail_location=maildir:~/Maildir beforehand", and I assumed it was a bash variable. And I didn't realise a fresh Dovecot install on Debian defaulted to mbox and ~/mail/ directory. Tested again and result was perfect.
    – wcweb
    Commented Jul 12, 2022 at 6:12
  • I added the path to the config file to make the context of the config option clear for future readers
    – wbob
    Commented Jul 12, 2022 at 21:42

While this is a programming question, the practical answer to get data exported from Thunderbird is to use the alternative addon "alternative import/export" and you can export to eml format among others


Dovecot Migration has some support for mbox -> maildir.

This famous mb2md.py script (I guess short for "mbox to maildir") is somewhat lost (link broken) and anyway outdated (Python 2.3...), but I found a more recent version (Python 3, from 2019) here.

But as akatar mentioned, the official Python mailbox module maybe can do that, also seems somewhat broken.


I had the same question few months ago and I prepared a script on my github for that (https://github.com/pbies/python-scripts/blob/main/inbox-parser.py):

#!/usr/bin/env python3

# Parse Thunderbird Inbox or Sent files consisting of many emails and put them in subfolder email per file

import sys
import os
from os import path

if not path.exists("out"):
filein = open('./Inbox', 'r', errors='ignore');
fileout = open('/dev/null', 'r');
i = 0
while True:
    l = filein.readline();
    if not l:
    ss = l[0:7];
    if ss == "From - ":
        i = i + 1;
        t = "%05d" % (i,);
        fileout = open('out/' + t + '.eml', 'a');
        print('.', end='');

What is happening here is:

  • input is one inbox file with all emails (sent and other folders are the same format)
  • output is in subfolder in which will be stored all emails one by file

If you adapt the script or put some work into converting all mailboxes manually - you will be done with conversion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .