Yesterday, I needed migrate an IMAP mail account to another one. As I frequently use my GMail account, I decided  migrate it to there.

Well, there is a friendly and very useful perl tool that can do this arduous work to us. It’s named imapsync.

See how you can transfer all your emails to GMail using this script:

imapsync --host1 imap.host1.com --user1 richizo --authmech1 LOGIN \
    --passfile1 host1_passfile --host2 imap.gmail.com --port2 993 --ssl2 \
    --user2 user@gmail.com --authmech2 LOGIN --passfile2 gmail_passfile \
    --useheader 'Message-Id' --skipsize --expunge

Pay attention, the option expunge will delete all messages in your old account after a successful transfer!

If you have folders in your old IMAP mail account the script will create a correspondent label in GMail and transfer all messages to this new label.

My 2 cents ;)