There is a easy to use tool that facilitates the quick’n dirty move of the content of one IMAP account to a new server. Its name is imapsync. In Ubuntu, you may install it as this:
aptitude install imapsync
Now, set two files for the old and the new account in your home, containing the respective passwords of the two accounts. They are called passfile_1 and passfile_2 from now on.
Now run imapsync with the following options:
imapsync --host1 {old_imap_host} --user1 {old_imap_user} --authmech1 LOGIN \
--passfile1 passfile_1 --port1 993 --ssl1 \
--host2 {new_imap_host} --user2 {new_imap_user} --authmech2 LOGIN \
--passfile2 passfile_2 --port2 993 --ssl2
You just need to adjust the ports (143 vs. ssl) and the authentication mechanisms to your needs and you’re set.