Import Mails from Thunderbird to Apple's OS X

I'm sure this post is boring for my regular readers, but it's about a workaround for a bug that kept me busy for some hours, and I didn't find any solution on the web that worked for me. I found some people that had the same problem, but the workaround that worked for them didn't work for me - which actually almost freaked me out. So, I hope this post is useful to anybody who has the same problem. I tried to write it as detailed as possible, in case there are people that aren't very familiar with a command shell and all that stuff.
If this post was helpful, please leave a note. Thanks. :)

A friend of mine bought a macbook recently, and he wanted to import mails from his outlook on his old PC to which came with his mac. We figured out that there's no way to do that directly. But you can import the mails into Thunderbird (which is my favourite mail program, by the way), and then you can import those to apple's mail.

At least that's what we were thinking. But it didn't work. Each folder contained only one big mail, it didn't create seperate entries for each mail. First I thought its a matter of line ending, since Unix and Windows use different characters to indicate the end of a line. Recoding Thunderbird's mail files didn't work.

I knew that the mbox file format that Thunderbird uses to store the mails is like this: Each folder is one file that contains all mails of the folder, and the beginning of a mail is marked by a line that starts with "From " and then some additional information. (Mind the space after "From", it's very important).

Most programs that use mbox files don't care about the data in the line after the "From ". A typical line in Thunderbird would look like that:
From - Mon 29 Dec 1997 23:45:58

Googling showed that is picky about the format of the From-Line, and there were some posts where people said that you need to replace the "-" by the address of the sender. I wrote a perl program that changed the From lines to something like this:
From sender@host.tld Mon 29 Dec 1997 23:45:58

But still, it didn't work. Still only one HUGE mail in each folder. It seemed like this worked for everybody except me. But I figured out that the date was not correctly formatted. seems to expect the date in another format. It needs to look like this (mind the different order of the fields in date):
From sender@host.tld Mon Dec 29 23:45:58 1997

So, I wrote this perl program that fixes the mbox files, and finally it worked. This script changes the From line to the format that needs. It adds the actual email address of the sender, and changes the date (if neccessary).

If anybody has the same problem, here's how it works:

  1. Save the file mboxfix to your desktop. But you probably want to skip this step after you've read the update at the bottom of this post.
  2. Go to your Thunderbird mail dir (on windows it's probably c:\Documents and Settings\ YourUsername\ Applications\ Thunderbird\ Profiles\ default\ StrangeChars\ Mail, and on Mac its most likely /Users/ YourUsername/ Library/ Thunderbird/ Profiles/ default/ StrangeChars/ Mail. (I've inserted blanks for better line wrapping results))
  3. For each mail folder there are three files or folders, e.g. Inbox, Inbox.msf, Inbox.sbd. Only the Inbox (without extensions) is important. Copy those files (one for each mail folder) to your desktop as well.
  4. Open a Terminal on your Mac. (Applications -> Accessories (probably, I don't know the English name) -> Terminal).
  5. Type cd Desktop and hit enter.
  6. Type chmod 755 mboxfix and hit enter.
  7. Now do this with each mailbox file (this example uses the mail folders Inbox, Sent, Private and Office. If you have different names, and/or more mail folders, alter the command to your needs:
    ./mboxfix Inbox Sent Private Office
  8. This creates the files Inbox.mbox, Sent.mbox, Private.mbox and Office.mbox
  9. Open Mail, go to "Import Messages", select "Import from Other", and point it to your desktop. Make sure to import only the files with the ending .mbox.
  10. You're done. Clean up your desktop and say "thank you, Rian". :-)

Update (March, 25th): (see also post from March 25th, 2007)
Lars Kobbe created a Droplet out of my perl script. Just download my script wrapped up in Lars' Droplet here (i.e. skip step 1), and replace step 4 to step 7 by just dragging your mbox files on this Droplet.


I don't have a Mac, but "thank you Rian." :)

When did you start speaking Chinese? I am glad you solved your problem but I have no idea what you are talking about!

I don't have a mac either but I have had issues with Firefox which is related to the Thunderbird program. Here at work and at home. The one at home won't let me save the changes to my toolbar. Once I change them they work fine, but then when I shut down my firefox window, and bring up a new one, it reverts to the old way. No text, and nothing I add on like "New Tab" button, etc... The on eat work is weird because any window pop up ends up "Centering" so if I try to make comments like in this window it skews to the right and I can't read all of what I am writing... It can get annoying at times.

Blah, blah, blah! Speak English!

Thanks Rian, it helped a lot.
But some might be interested to know that my procedure had to be just slightly different:
Mail refused to import the generated .mbox file. Instead, I was only able to select folders in the import process. I just created a folder named newmailbox.mbox, in which I put the newly created files, for which I had to strip the .mbox extension. From there, everything went fine!

You saved me! Thank you!

not being as amazingly gay as the other guys (is that a cowboy hat?)

well actually not being gay at all


And here I would kiss you in a very ungaylike manner.

Thanks a bunch. I'd seen a couple of different solutions to this problem on the Net, but this is the first that's worked for me.

well, THANK YOU! saved my day, and probably my week. THANKS THANKS THANKS

PLEASE HELP ME! When I read your explanations I thought "this is it! My pain is over!" Unfortunately, I still have problems getting all my emails from Thunderbird to Mail on my Mac: Even if I use your tool, just very few of my emals in Thunderbird make it through to Mail. What else can I do? many thanks