| blog |
Tuesday, September 28, 2004
gMail import

I’ve been looking for a way to get all my old e-mail into gMail for a while now. I tried out =http://www.marklyon.org/gmailGML[/url] and gExodus, but neither of them worked quite right for me. I couldn’t get GML to run (though I didn’t try all that hard), and gExodus would keep aborting after sending the first 17 messages. I also tried using =http://www.aaltonen.us/archive/2004/04/26/tip-batch-forward-emailpine[/url] to forward it, but that didn’t work right either.

So, I finally gave up, and did it myself. It was surprisingly easy, and I should have just done it this way in the first place. First, I created a procmailrc file that looked like this:

VERBOSE=off

PMDIR=$HOME/.procmail
PATH=$PATH:$HOME/local/bin/
LOGFILE=$PMDIR/log-forward

#Get the subject
#Discard some dangerous special chars + any leading and trailing blanks
SUBJECT=`formail -xSubject:
| sed -e ‘s/[;`]/ /g’
| expand | sed -e ‘s/^[ ]*//g’ -e ‘s/[ ]*$//g’`

# SPAM STUFF
:0fw
|/usr/bin/spamassassin -c /usr/share/spamassassin -p $HOME/.spamassassin/user_prefs

:0:
* ^X-Spam-Status: Yes
/dev/null

:0fw
|formail -I”Subject: [old] $SUBJECT”

:0
![my username]@gmail.com

Then, I just ran: cat old_archive | formail -Y -s procmail procmailrc. That’s it. formail splits the mbox file, and runs each one through procmail, which adds [old] to the subject, and forwards it along to gMail. Nice and simple. It even runs all my old stuff through my current spam filter, which catches a lot of stuff that was still lying around.

Updates: It didn’t work quite right the first time. It was merging some messages together, and doing weird stuff. The -Y option to formail fixes that, at least with my mbox file. Also, it goes MUCH faster if I disable the spamassassin stuff, so that’s what I’m doing the second time around. I’ll let Google catch the spam for me.

gMail Usage

ShareTweet about this on TwitterShare on Google+Share on FacebookEmail this to someone
Posted by alan to general at 5:20 pm PT | Link | Comments (4)

RSS feed | Trackback URI

4 Comments »

Comment by David Nicol
2005-06-30 09:00:12

I have tried using your script and get this warning:
procmail: Suspicious rcfile “/fuse1/56/gte339f/procmailrc”
procmail: Couldn’t read “/fuse1/56/gte339f/procmailrc”

here is the modified script. Any help is very much appreciated

VERBOSE=off

PMDIR=$HOME/.procmail
PATH=$PATH:$HOME/local/bin/
LOGFILE=$PMDIR/log-forward

#Get the subject
#Discard some dangerous special chars + any leading and trailing blanks
SUBJECT=`formail -xSubject:
| sed -e ‘s/[;`]/ /g’
| expand | sed -e ‘s/^[ ]*//g’ -e ‘s/[ ]*$//g’`

# SPAM STUFF
:0fw
|/usr/bin/spamassassin -c /usr/share/spamassassin -p $HOME/.spamassassin/user_prefs

:0:
* ^X-Spam-Status: Yes
/dev/null

:0fw
|formail -I”Subject: [old] $SUBJECT”

:0
dbnicol@gmail.com

 
Comment by Jonathan
2006-06-20 07:44:07

Is there a way to make this work with Maildir format?

 
Comment by Albert
2006-10-25 21:57:44

Worked for me like a charm, I’m glad to have found a bash script which dealt directly with unix email capabilities. I’m used to working with Postfix and maildrop, so seeing how you used procmail here was cool.

 
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

All content Copyright © 2002-2009 Alan Penner
Powered byWordPress, Penner Hosting and Superb Internet
Some Rights Reserved
penner42
Redistribution is permitted under the terms of
this Creative Commons License