If you prefer command line, there is a script called imapsync. It looks like now it's sold for money, but there are older versions around back from the time when it was opensourced.
I used it to move mail to gmail quite a while ago since I was tired of having mail, calendar and contacts in different places.
I used it to move mail to gmail quite a while ago since I was tired of having mail, calendar and contacts in different places.