Fleeing from Gmail

So you came to the same conclusion as I: Google is actually evil indeed. That makes it kind of uncomfortable to have all your e-mails over there, doesn’t it? I for one decided that it’s time to leave and will show you how to do the same using an UNIX based OS.

Disclaimer: I’m neither responsible nor liable if the my instructions – whether followed precisely or not – cause any harm to you or your e-mails. Use your own brain.

Where to?

The first question that arises is of course: “Whom can I entrust my e-mails?” I boldly suggest FastMail which I chose too. They are reliable, fast and even Marco Arment approves. For the sake of completeness I’d like to mention that they have been acquired by Opera Software in 2010 – whatever that may mean to you. And for the sake of further completeness: they bought themselves out again.

I advise against free mail providers for “if you’re not paying, you’re the product”. Just as Marco, I consider e-mails simply too important.

For the sake of simplicity, I’m going to use the migration to FastMail as an example.

Contacts

One of my favorite features of Gmail was the seamless synchronization of my contacts between e-mail and my phone. I’m afraid I won’t be able to help everybody here. Since I went all Apple, I’m using the native address book anyway and sync it using iCloud to my iPhone.

E-Mails

As a matter of fact, FastMail offers IMAP migration. You can find it under Options/Migrate IMAP. As I want to keep this article relevant to people who switch to different providers – and as the migration failed miserably when I tried it (the migration report was an e-mail of several megabytes full of errors with only ⅓ of mails successfully copied) – I’ll describe the manual way.

Copying mails away from Gmail isn’t easy unfortunately. It’s even worse if you use an IMAP client. I tried it both with Thunderbird and Mail.app, but it’s a pain. Don’t do it.

Ideally you shouldn’t run the copy process at “home”. You’d have to download all your mails and then upload them again. Even fast consumer connections have rather weak uplinks. You should try hard to keep slow consumer connections out of the game – even a cheap virtual server is much better.

Ubuntu currently ships with ImapCopy. However chances are, that you won’t be able to use it because it has no way to rewrite folder names and Cyrus IMAPd belches on folder names containing square brackets. Your mileage may wary with a different IMAP vendor.

Ultimately I found peace with imapcopy.pl from IMAP-Tools by Rick Sanders. It should support TLS just by installing libio-socket-ssl-perl and setting the port to 993 – unfortunately it doesn’t for me. So I added stunnel to the mix (update: I’ve been told TLS works now).

Handling Folders

As Gmail’s “All Email” folder contains, well, all e-mails, we have to copy only two folders: “[Gmail].All Mails” and “[Gmail].Sent Mail”. If you copy all folders, you end up having duplicate e-mails. To get the mails into the right folders afterward, you have to use your e-mail client (just re-create your filter rules and run them on the mail box).

The reason why we’re using imapcopy.pl are it’s rewriting capabilities. In order to fix the folder names, you have to create a mapping file which I called just “map”:

[Gmail]/Sent Mail:Sent Items
[Gmail]/All Mail:Archive

Feel free to use other folder names as destination of course.

Copy

I strongly suggest to run the following inside of a tmux or screen session. Depending on your bandwidth and Google’s willingness to deliver content, it will take quite a while (my “All Mails” folder with 24,063 messages took over 4 hours).

First of all, you two SSL tunnels to Gmail and FastMail. Start each in one tmux/screen window.

1
2
stunnel -c -f -d 1143 -r imap.gmail.com:993 -P ''
stunnel -c -f -d 1144 -r fastmail.fm:993 -P ''

(N.B. I’m afraid the syntax is Ubuntu/debian-specific which wraps stunnel :(.)

Now you have a secure SSL connections to both providers on localhost:1143 and :1144 to Gmail and FastMail respectively. If you don’t switch to FastMail just adjust the host name.

Now it’s time to start the copy process. You’ll have to tweak this command line for your environment of course:

1
2
3
4
5
    wget http://imaputils.googlecode.com/svn-history/r5/trunk/imapcopy.pl
    perl imapcopy.pl \
        -S localhost:1143/your.google.name@gmail.com/google.password \
        -D localhost:1144/your@new.account/new.password \
        -M map -m "[Gmail]/All Mail,[Gmail]/Sent Mail"

For reasons of curiosity, you may want to add a time before perl so you get runtime statistics afterward.

Remember, that if you have used Google’s two-phase authentication, you’ll have to create an AuthToken first and use it as the password.

When it’s done the sorting handiwork begins. But at least all your mails are on your new server.

What if I need to keep my Gmail address?

Gmail supports e-mail forwarding. You’ll find the option in “Mail Settings/Forwarding and POP/IMAP”. Google’s spam protection is pretty weak though, so I’d consider other ways if you don’t want it to forward junk mail all the time (the fact that it’s forwarded by Google circumvents your local spam protection).

Final Words

Although I’m kind of pissed now, Google clearly isn’t the devil and they still do a lot of great stuff.

Nevertheless, e-mails are the core of my personal communication and I’d prefer that snooping in my inbox is not the way to pay for a service (I know, I know – they did it always to some extent for advertising – better a late reaction than none).

← See all posts