Friday, 18 May 2012

Exporting PST and Importing into IMAP

a.k.a How I learned to stop worrying and ditch lookOut

A customer has asked me to migrate the company mail from POP3 to IMAP. After setting up the server settings, I was left to import 15GB of email from two .pst onto the IMAP server. One .pst was current mail and was 5GB and the archive was 10GB.

I attempted to copy the folders across using MS Outlook but it was pretty hopeless. Despite having a fast machine with plenty of RAM and Disk space and a 20Mb upload speed, it crapped out multiple times with failed to update headers. I was only copying small folders across (100MB or so at a time). This left the folders in a state. I decided to abandon Outlook.

I looked around and found the excellent blog post by Leo Antunes here:


This requires the readpst binary which is part of the libpst package. The readpst bundled with debian squeeze ( $ apt-get install readpst) does not support PST files which are created using >Outlook 2003. It is necessary to use readpst built from source:

I downloaded, configured; make; make installed as normal and ran 

tng@danny $ readpst -r Outlook/outlook.pst

I then used the script in the blog post with a minor tweak. The customers IMAP server didn't use a secure connection, so I changed the imap connection string below:


    imap = imaplib.IMAP4(args.imap_server)
    #imap = imaplib.IMAP4_SSL(args.imap_server)

Tweaked script is here . 

I moved the mbox directory inside a work in progress directory (WIP):

./readmbox.py -s myimapservername.foo -u myusername -p mypassword Outlook/
WIP

The WIP has an advantage of creating a subdirectory inside the IMAP folder which protects the existing IMAP folder structure.

It did a good job of uploading the mbox to the IMAP server. However, some data failed (1%) to import. In this case, I manually imported those mboxes from the directories made using readpst. To do this I used IceDove and the Import/Export AddOn to open individual mbox files.

3 comments:

frsj said...

Hi. I am getting this error:
File "./readmbox.py", line 14, in
from twisted.mail import imap4 # for their imap4-utf7 implementation
ImportError: No module named mail

What can be done in this case?

Tim Gibbon said...

$ sudo apt-get install python-twisted-mail

Hope this helps,

tng

frsj said...

It did work. Thank you very much!