Using imapsync to backup / archieve your Gmail emails

1. Download and install the latest version of imapsync at http://www.linux-france.org/prj/imapsync/dist/. As of today, the latest version is 1.255.

2. imapsync requires Mail-IMAPClient 2.2.9. Most recent Linux distribution comes with version > 3.x, so you will need to manually download it at http://search.cpan.org/~djkernen/Mail-IMAPClient-2.2.9/.

3. Extract it, and install Mail-IMAPClient 2.2.9

wget http://search.cpan.org/CPAN/authors/id/D/DJ/DJKERNEN/Mail-IMAPClient-2.2...
tar xzf Mail-IMAPClient-2.2.9.tar.gz
cd Mail-IMAPClient-2.2.9
perl Makefile.PL
make install

4. You are set to go. The typical command to synchronize from Gmail to your other mail server will be similar to this:

imapsync --host1 imap.gmail.com --user1 changeme@gmail.com --password1 mypassword \
    --host2 my_other_mail_server --user2 changeme --password2 mypassowrd \
    --syncinternaldates --ssl1 -ssl2 --noauthmd5 --split1 100 --split2 100 \
    --exclude All Mail|Spam|Trash

Obviously you need to provide your actual email address and credentials. It can also work for Gmail Apps, just replace xxx@gmail.com to yourname@mydomain.com, provided you are Gmail Apps customer.

The parameter "--exclude All Mail|Spam|Trash" is there to ensure that you won't download the Gmail/All Mail folder from Gmail, as it is actually a collection of all your emails from all your other folders. So essentially, you will end up storing duplicates, and will require twice as much storage if you don't specify it.

So there it goes. It might take a while to complete, and Gmail might lock you with Lockdown in Sector 44 if you try do open multiple connections. Once its done, you can sleep at night knowing the you have the copy of the emails your stored with the big G.