Install imapsync on old or new server, you could also install it on your computer if your running Linux . Since imapsync establish connection between old and new imap server to sync the emails you could use any machine that can run imapsync to move emails from one server to another.
apt-get install imapsync
yum install imapsync
Run the below command replacing details that match your old and new server,Remember to create email account on new server so that there is a empty mailbox to sync with old server mail box
–host1 old.imapserver.com –user1 email@example.com –password1 password-for-the-account \
–host2 new.imapserver.com –user2 firstname.lastname@example.org –password2 password-for-the-account
Having trouble moving emails to new server?, Let us move the emails to new server for you at just $40 per domain Get Started