Importing PST files into Thunderbird using libpst

For a number of reasons, I've finally switched from the hopeless Outlook Express to Mozilla Thunderbird... and so far, I really like the change. However, now that I've got Thunderbird, I find myself wanting to import my old Outlook PST file from a couple of years ago...

Now, its worth pointing out that if you have Outlook installed on your PC, then PST importing is very easy - Thunderbird simply uses Outlook's MAPI interface to request all mail folders. However, if, like me, you don't have Outlook installed, and don't want to install it either, then you need to do a bit more work.

First of all, you need something that will extract the emails from the PST file, and save them in a "standard" format. In this case, I decided to use the excellent readpst utility (part of the libpst project). So the first step is to download, make, and install the libpst package, using the standard steps as described in that package's INSTALL notes.

$> wget
$> tar xzf libpst-0.5.2.tar.gz
$> cd libpst-0.5.2
$> make
$> su - root
$> make install

Now that's done, it's pretty simple to extract the contents of the PST file... just create a new output directory, and run the readpst command.

$> mkdir out
$> readpst -r c815601.pst - out

If all went well, then you will have a hierarchy of files and folders in the out directory. The hierarchy will look something like this:

out/folder 1/mbox
out/folder 1/sub folder 1a/mbox
out/folder 1/sub folder 1b/mbox
out/folder 2/mbox
... etc.

So each folder contains a single filed called "mbox", which contains all of that folder's email in a standard mbox format. Of course, each folder can also contain sub-folders.

Now, the thing to note here, is that Mozilla Thunderbird also uses the mbox format. So, now our data is in the right format, but not the right structure.... for Mozilla Thunderbird to make use of these mbox files, they need to be re-organised into a structure like this:

out/folder 1
out/folder 1.sbd/sub folder 1a
out/folder 1.sbd/sub folder 1b
out/folder 2
... etc.


That's how Thunderbird stores your email within your local profile folder.

So, how do we rearrange the readpst output into Thunderbird's... well, I'm glad you asked ;)

First, we need to rename all of the sub-directories to include the .sbd extension.

$> find out -type d | tac | grep -v '^out$' | xargs -d '\n' -I{} mv {} {}.sbd

That was easy :) Now, we rename the mbox files, and move then to their parents' folders.

$> find out -name mbox -type f | xargs -d '\n' -I{} echo '"{}" "{}"' | sed -e 's/\.sbd\/mbox"$/"/' | xargs -L 1 mv

Okay, so that was a little bit harder ;) And finally, we can remove any now-empty sub-directories.

$> find out -empty -type d | xargs -d '\n' rmdir

So that's it! Our folder hierachy now matches that used by Thunderbird. All that remains is to close Thunderbird, copy the folder hiearachy into the profile directory, and re-start Thunderbird.

You can check out for more information on where you profile directory is, but for typical Windows users, you can just copy the folders into: C:\Documents and Settings\[username]\Application Data\Thunderbird\Profiles\[random].default\Mail\local (see for more information regarding your profile).

I hope that helps! :)

comments powered by Disqus