brew install imapsync
Run (without ssl)
imapsync --host1 imap.from.server --user1 foo --password1 secret1 --host2 imap.dest.server --user2 bar --password2 secret2
Run (with ssl)
imapsync --host1 imap.from.server --user1 foo --password1 secret1 --host2 imap.dest.server --user2 bar --password2 secret2 --ssl1 --ssl2