Saturday, June 05, 2010

Importing mh mail into gmail

From 1990 until approx. 2004 I used the UNIX based mail client "mh". Around 2004 I got an invitation from my friend who worked at Google to try out gmail.

I had never used any web-based email service for a number of reasons:
  • I had assiduously collected all my personal email across a period of more than fifteen years and wanted the security of knowing that all my email would always be available to me even if the "free" email provider were to close down
  • As an mh user I was accustomed to the power of being able to do stuff such as "scan +inbox | wc -l" and no web based email would allow me to do that
  • I did not care to read email accompanied by flashing advertisements etc.
The downside of my intransigence of course was that I could not take advantage of the universal access to my email that web based email providers offered besides having to ensure secure storage all my email myself.

gmail was a refreshing change however since it was the first email provider to also allow pop-based access to email stored there. With gmail I now had the choice of accessing my email anytime I had internet access while still permitting me to retain control over my email since I could always download it onto my local machine and I opened an email account (which was then "invitation only" :-).

The reality turned out to be different however. While it was true that I could download my mail in gmail using POP that had its own problems since all my emails got downloaded (including once I had already downloaded) every time I fetched mail from my gmail server. Furthermore gmail had added a number of cool features such as keyboard shortcuts, tagging, searching etc. that I was fast getting addicted to. Also I had taken up a job that involved working in a Windows environment so that it was no longer very feasible for me to use my Linux laptop at work. Before I knew it, I had already accumulated a substantial amount of mail in my gmail account in addition to my substantial mail on my home machine. Furthermore with the evolution of email I have to regretfully acknowledge that mh (or its graphical successor exmh) no longer cuts it and I have accepted that I have to move on from my past love ...

I am now trying to import my old mail from mh into gmail and here is how I was able to successfully achieve this:
  • download the python script "gml" from http://marklyon.org/gmail/old/gml.tar using "wget http://marklyon.org/gmail/old/gml.tar"
  • Extract the file gml.py - "tar xvf gml.tar"
I then wrote a bash script to upload all my old email to gmail and here is what it looks like:


folders -noverbose -all -recurse -fast -noheader -nototal | while read folder
do
#Remove the old mbox file
/bin/rm ./msgbox
#Pack this folder into an mbox format file
packf +$folder
#Mail the contents of this file one mail at a time while preserving
#original headers and simultaneously add folder-related information
#for use in gmail
python gml.py mbox ./msgbox address+$folder@gmail.com outgoing_smtp_server_address
done


Just in case you were not aware of this, gmail allows you to create multiple aliases for the same email address e.g. (messages to foo@gmail.com, foo+bar@gmail.com, foo+baz@gmail.com are all delivered to foo@gmail.com) - see http://mail.google.com/support/bin/answer.py?hl=en&answer=12096 for more details.

As a result I can now (theoretically) transfer all my old email to my gmail account. I will now need to figure out how to automatically label them based on the old source folder name (which I am embedding into my "To:" address field. I have not yet figured out how I can do that. Watch this space ...

No comments: