imapsync software is a command line tool allowing incremental and recursive imap transfers from one mailbox to another, both anywhere on the internet or in your local network.

imapsync is useful for imap account migration or imap account backup.

First, create same mailbox on the new mail server.

Then, install imapsync on CentOS 6 or 7.

yum install imapsync

NOTE: hostname address should be IMAP SERVER ADDRESS.

imapsync –host1 old-hostname –port1 993 -ssl1 –user1 old-emailid@domain.com –password1 password-of-old-emailid –host2 new-hostname –port2 993 -ssl2 –user2 new-emailid@domain.com –password2 password-of-new-emailid

example:
imapsync –host1 old-server.domain.com –port1 993 -ssl1 –user1 example@domain.com –password1 q1w2e3r4 –host2 new-server.domain.com –port2 993 -ssl2 –user2 example@domain.com –password2 q1w2e3r4