brew tap dsoares/imapsync
brew install imapsync
Run (example)
imapsync --include <regexp> --exclude "All Mail|Spam|Trash" \
--host1 imap.from.server --user1 foo --password1 secret1 --ssl1 \
--host2 imap.dest.server --user2 bar --password2 secret2 --ssl2