Howtoforge posted a guide about migrate mailboxes between IMAP servers with imapcopy
This guide explains how you can migrate mailboxes between IMAP servers with imapcopy. imapcopy lets you copy recursively all email messages and folders from one imap account to another. It supports the protocols imap and imaps.How To Migrate Mailboxes Between IMAP Servers With imapcopy