Transferring Email From Gmail/Google Apps to Dovecot With Larch


As regular readers of this blog know, I am in the process of trying to back up Google Apps accounts to Dovecot. Well I have finally found my solution. Not only does it work, but its in Ruby.

First thing that you’ll need to do is grab yourself a copy of Larch. I did this simply by typing and it installed everything nicely, but click the link to the repository on Github if it doesn’t work for you.

$ sudo gem install larch

Immediately I dove in and ran it. And immediately I hit my first problem:

$ larch --from imaps:// --from-user --from-pass FILTERED --to-pass --to-pass FILTERED --all
... Removed for brevity ...
NameError: uninitialized constant Larch::IMAP::OpenSSL (cannot recover)

The fix for this issue is that SSL needs to be available (or installed as a library) to Ruby. Since I have Ruby built from source, it was just as easy as what’s below. I have removed the output for readability.

$ cd /usr/local/src/ruby-1.8.6/ext/openssl
$ ruby extconf.rb
$ make
$ sudo make install

Now that we have SSL installed, let’s try it again.

[Dec 07 16:54:06] [info] Net::IMAP::NoResponseError: Mailbox doesn't allow inferior mailboxes (will retry)
[Dec 07 16:54:09] [fatal] Net::IMAP::NoResponseError: Mailbox doesn't allow inferior mailboxes (giving up)
[Dec 07 16:54:09] [info] 69 message(s) copied, 0 failed, 0 untouched out of 69 total

Whoops, another stopping point. If you are receiving the above error, then you need to make sure that your dovecot installation is set up for maildir. What this error is saying is that your installation doesn’t support folder that are folders and mailboxes at the same time. If your current dovecot installation is setup for mbox, you will need to convert it. That is beyond the scope of this post, but add the code below in the /etc/dovecot.conf if it’s not already there.

mail_location = maildir:/var/spool/mail/vhosts/%d/%u/Maildir
namespace private {
separator = /
prefix = ""
inbox = yes

I have been happily and successfully running Larch ever since.

2 Responses to “Transferring Email From Gmail/Google Apps to Dovecot With Larch”

  1. […] If you wanted to backup your gmail/google apps account, dovecote seems like a good option.Eric Lubow’s blog post here has good information on this – […]

  2. Martijn Kools says:

    This is an old article but it worked great for me! Exactly what I was looking for. The syntax is wrong btw use this:

    larch –from imaps:// –from-user –from-pass yourpas –to imaps://yourimapserver –to-user –to-pass yourpass –all

    Thanks for this!

Leave a Reply