Syncing IMAP servers with imapsync

We’re moving our company mail from a self-hosted Cyrus-Imapd solution to Google Apps for domains. As such, I had to migrate everyone’s email. This sucked majorly.

My first solution to the problem was logging into both accounts (the current IMAP server as well as Gmail) and drag and drop folders. Yeaaaaah, no. I really didn’t care to write my own script to do this seeing as I’ve never written code to interface with IMAP before.

I searched far and wide for an automated/scripted solution and found two very good ones:
1. A Ruby script to sync email from any IMAP server to Gmail [wonko.com]
2. imapsync [freshmeat.net]

The Ruby script worked pretty damn well, but choked on very large amounts of mail, and if it crashed, there was no way for me to see where it had left off. There was also no way to recursively sync a set of folders. One example for an employee whose mail I’m migrating right now is:

INBOX/SALES/PUBLISHERS/FUNDING/RESEARCHER FUNDS

I’d have had to sync all these folders individually as:

'INBOX/SALES' => 'SALES',
'INBOX/SALES/PUBLISHERS' => 'SALES/PUBLISHERS',
'INBOX/SALES/PUBLISHERS/FUNDING' => 'SALES/PUBLISHERS/FUNDING',
'INBOX/SALES/PUBLISHERS/FUNDING/RESEARCHER FUNDS' => 'SALES/PUBLISHERS/FUNDING/RESEARCHER FUNDS'

In imapsync, this was simply:

imapsync --host1 mail.example.com --folderrec 'INBOX/SALES' --user1 localuser --host2 imap.gmail.com --user2 remoteuser@example2.com --noauthmd5 --ssl1 --ssl2 --delete

At the end of it, it reports how many it had to skip and because I’m deleting messages after they’re successfully transferred, I can easily see how many are still left to do, how many I need to retry, etc.

I love you imapsync.


About this entry