IMAP Migration Magic

One of the things that I often forget as a website developer is that, as a freelancer who also offers hosting, I also have to worry about my client’s email service. One thing that is particularly painful is taking over a client and having to migrate their email from one server to another.

As part of my Dreamhost to Linode server migration, one of my most dreaded tasks that I encountered was moving my client’s email to the new server or somewhere else. Particularly those who leave several gigabytes worth of email on the server.

One of my clients treat their email as exclusively web mail. No matter how many times I encouraged them to use POP and have their own computers take the email off of the server, they stuck with web mail which eventually led to server resource issues when they tried to use RoundCube to browse through their email or find something specific they were looking for. Suffice enough to say they ended up using a Microsoft Outlook, however they used IMAP instead of POP. This left me with the huge problem of migrating 4GB worth of email from an email server which I do not have root access to.

My first approach to this problem was to perform the migration by hand using and email Client like Microsoft Outlook or Mozilla Thunderbird, and when I first inherited the 4GB client this time consuming method worked but it took hours and at the time the total amount of email was in the hundreds of megabytes and not gigabytes. Given that I only have a 2MB/s upload speed from my home office (Fibre internet is not available in my building.) I needed to find a solution that would be fast and reduce the impact it has on my clients.

I almost cancelled the migration because of this problem. I dreaded doing this task and really seriously considered the extra power I would have on my web server simply not worth it. It wasn’t until a day later that I even thought to try to research this problem as I had in the past with no luck.

A quick google search lead me to find IMAP Tools, a suite of Perl scripts geared toward fast processing of email on multiple servers via the IMAP protocol. You can get the whole suite for a price, or you can get just the tool that you need for a reduced price. I opted to just get their imapcopy.pl script instead of the whole suite or the heavy duty migrateimap.pl script which does a bulk export based on a list of users, passwords and destinations. When I purchased it, I had to wait about 30 minutes for the email with the script to arrive, which was the only difficult part.

Once you copy the script to any Linux box (it could even be one of your web servers!) simply make the file executable

chmod +x imapcopy.pl

and then run it as follows

./imapcopy.pl -S mail.oldserver.tld:port/user@domain.tld/accountpassword -D mail.newserver.tld/user@domain.tld:port/accountpassword

Lesson learned: no matter how old or new the problem, just keep googling. The feelings of dread quickly subsided.

Aftermath

Due to the 4GB client’s webmail usage habits and regular problems that resulted from I ended up recommending that they switch to Google Apps for Work so that Gmail could manage and handle all of their email in the future. It was surprisingly a really easy sell, especially since their organization was small and only needed two email accounts.