Saturday, December 20, 2008

Script to import mail from existing email account into google

I am writing a script to help our customers migrate from their current mail to google apps' gmail. Found a host of scripts on the net but finding one that works correctly not to mention even work proved a challenge. Too many of the script just fell short of what I needed. There were perl scripts, ruby scripts and also python scripts.

All of them just did not have the one thing I needed that is to convert the imap folders into gmail's labels. What about folders that have more than one level? Well I came up with the idea to convert them this way:

Original structure:
Level 1
=> Level2
Into a label : Level1_Level2

The normal mail migrate script that comes with gmail does not seem to convert imap folders into labels. Currently I am looking into using the libgmail library to do what I want. Ran into some trouble installing the source copy because it was looking for python-mechanize and one of the dependancy of python-mechanize is python < 2.5! Sheesh! Well poking around using google I found an older package of libgmail that did not need python-mechanize. Hopefully to be able to come up with early prototype by tomorrow. Has anyone built something similar?

7 comments:

whit537 said...

Is there a reason not to just mount the Google account as IMAP and copy folders/messages using a desktop client? Or for that matter, why not interact with Google via imaplib?

schmichael said...

I just used Evolution to copy my email from my old IMAP server to Gmail.

Something, I assume Gmail, automatically converted Level1 => Level2 nested folders into labels like "Level1/Level2".

I know you probably need to script this process, but I have a hard time believing Evolution did anything magical that other IMAP client utilities would not... *shrug*

lowks said...

whit537: Haven't tried that yet I wanted to make this an automatic process. Suits are going to use this.

schmichael: did not try evolution. Trying dragging on thunderbird did not work as gmail did not convert the folders into labels.

angch said...

imapsync has been very good to me so far. Perl, so easy for me to hack on.

cowmix said...

yeah.. I went through this hell YEARS ago.. now that IMAP is supported on Gmail this whole exercise is easy-peasy.

lowks said...

Yeah it's supported some clients gets bent out of shape because their folders do not get re-created or transformed into labels :P.

skyleecm said...

using imaplib to create folder will also create the label.