I’ve just released Larch, a Ruby application that syncs messages from one IMAP server to another quickly and safely. It’s smart enough not to copy messages that already exist on the destination and robust enough to deal with ornery or misbehaving servers.
A couple years ago I posted a quick and dirty script that did this. Larch is a much more mature tool that does essentially the same thing (only faster and more reliably).
Larch is particularly well-suited for copying email to, from, or between Gmail accounts. During its development, I used it to sync over 25,000 messages from a Dovecot IMAP server to Gmail.
To install Larch via RubyGems, run:
sudo gem install larch
Visit Larch’s GitHub page for usage information and other documentation.
Update: Larch now has a mailing list where you can post questions and comments and find answers to questions that have already been answered.