IMAP Backup
Monday, March 27th, 2006Today I noticed that my IMAP accounts were getting close to quota, so I decided it was time to back up the mailboxes, stash those tar.gz files somewhere, and clean out the old stuff.
Step 1 was find a command line tool to copy the contents of an IMAP folder, with all nested folders, to some sort of mbox/maildir/whatever local disk format. This sounds easy, but I bounced around between a bunch of perl and python tools to do this, all of which were *WAY* more high powered than what I wanted. Most everything was geared toward IMAP-to-IMAP copy or IMAP to local synchronization, with the ability to detect and propagate changes in either copy. Even after getting one of the sync tools to do a simple copy, I soon discovered that Python’s imaplib has some MemoryError bug, and cannot download multi-MB emails. That pretty much killed every Python based tool. (I couldn’t find anything based on Twisted, and my brain is too weak to write a Twisted-based IMAP tool myself.)
So then I went to Perl. The problem here is that one of my IMAP servers only supports SSL connections, and the default implementation of Mail::IMAPClient does not make it easy to establish a SSL connection (basically, they make you do the socket setup and IMAP login by hand). Thus, most all of the Perl-based tools refused to connect. (Interestingly, Debian has a patched Mail::IMAPClient with a SSL option, but by that point I had given up.)
So, having eliminated Perl and Python tools, I finally just caved in and used Thunderbird. Setup your IMAP account, enable offline browsing on all your folders, and then go to offline mode. Click “Download” when it asks, and *bang*, in your profile directory under ImapMail, you will have an mbox tree of all your mail. Tar, gzip, and go home.
