0. delete old emails if necessary, turn off convo view (Settings > General) since this lumps everything together. (note, you can do things like “before:2014/4/29″)
1. Use getmail to pull all emails as mbox or Maildir format from your old email account. I initially did maildir hence why below I convert them to mbox for thunderbird.
I configured like this for pulling from our corporate exchange server:
type = SimpleIMAPSSLRetriever
server = exchange.herpderp.net
username = email@example.com
password = secret
mailboxes = ("Inbox", "Sent Items")
type = Maildir
path = /home/merry0/mail/
verbose = 2
message_log = ~/.getmail/log
# do not alter messages
delivered_to = false
received = false
1a. My email’s from exchange had a pretty dire problem. For whatever reason (google didn’t tell me much on this), prepended to every address in every to field (on every single email), was ‘=SMTP:’ so a to line would look like “to:=SMTP:firstname.lastname@example.org”.
Yeah this was super annoying. To fix it, once everything was in maildir format, I ran this fancy commamd in the directory holding all the emails:
grep -rl '=SMTP:' * | xargs sed -i 's/=SMTP://g'
2. convert to mbox script (only if your email is in maildir format. if you are already in mbox, you’re fine)
This script is nice and simple, note that you may need to do a apt-get install python-mailbox. You can also see it here.
# -*- coding: utf-8 -*-
Frédéric Grosshans, 19 January 2012
Nathan R. Yergler, 6 June 2010
This file does not contain sufficient creative expression to invoke
assertion of copyright. No warranty is expressed or implied; use at
your own risk.
Uses Python's included mailbox library to convert mail archives from
maildir [http://en.wikipedia.org/wiki/Maildir] to
mbox [http://en.wikipedia.org/wiki/Mbox] format, icluding subfolder.
See http://docs.python.org/library/mailbox.html#mailbox.Mailbox for
full documentation on this library.
To run, save as md2mb.py and run:
$ python md2mb.py [maildir_path] [mbox_filename]
[maildir_path] should be the the path to the actual maildir (containing new,
cur, tmp, and the subfolders, which are hidden directories with names like
[mbox_filename] will be newly created, as well as a [mbox_filename].sbd the
def maildir2mailbox(maildirname, mboxfilename):
slightly adapted from maildir2mbox.py,
Nathan R. Yergler, 6 June 2010
# open the existing maildir and the target mbox file
maildir = mailbox.Maildir(maildirname, email.message_from_file)
mbox = mailbox.mbox(mboxfilename)
# lock the mbox
# iterate over messages in the maildir and add to the mbox
for msg in maildir:
# close and unlock
print(dirname +' -> ' +mboxname)
if not os.path.exists(mboxdirname): os.makedirs(mboxdirname)
listofdirs=[dn for dn in os.walk(dirname).next() if dn not in ['new', 'cur', 'tmp']]
for curfold in listofdirs:
curpath=os.path.join(*[dn+'.sbd' for dn in curlist if dn])
if not os.path.exists(curpath): os.makedirs(curpath)
print('| ' +curfold +' -> '+curpath[:-4])
3. using thunderbird, add the ImportExportTools addon, create a Unix Movemail account and right click on it > ImportExportTools > Import mbox file
3a. Enable IMAP in your gmail settings. Then, add this account to Thunderbird. Standard IMAP SSL settings google uses (e.g. imap.gmail.com) apply here. They have a guide on this.
4. Select the emails you want from the mbox based account to be moved to google. First I did the emails sent by myself. Just right click > copy > Your Gmail Account > [Gmail]/Sent Mail. Then, I did the rest to [Gmail]/All Mail
[quote]NOTE: You may want to dump all your non-sent mail to a label instead of All Mail in case you have a ton of emails and want to track which ones you are migrating. In my case, the connection dropped somehow and Thunderbird didn’t just try again, it just kinda stopped.
When you do this, the messages are not going to your inbox automatically. This means once your messages are moved over, to ensure they exist in your inbox, select all the messages in your “migration” label and select Move to > Inbox. These messages will still keep the “migration” label but will also exist in your inbox![/quote]
5. Finally, you will have to re-apply your filters by searching again for emails matching that filter. Go through each filter, hit edit, and re-search for matching emails. Then just do the Continue > Update Filter to ensure the filter applies to the newly added emails.