If you need to copy emails from one mailbox to another, even if they are located on different servers, you can use the imapsync utility. You just need to install and run it in the console with parameters. Naturally, you need to know the passwords for both mailboxes.
To install the imapsync on a Mac, you can use homebrew:
brew install imapsync
For installation on other operating systems, follow the instructions.
After installation, just run the command:
imapsync --host1 <source-hostname> --user1 <source-user> --password1 <source-password> --host2 <destination-hostname> --user2 <destination-user> --password2 <destination-password> --subfolder2 "<destination-folder>" --dry
This command will create a folder named “destination-folder” in the mailbox and copy all emails with all folders from the source mailbox to the specified folder.
The –dry option is needed to see what the command will do without doing anything. If you’re sure about the result, just remove –dry and run it again.
Synchronization can take a very long time, depending on the size of the mailbox. If you interrupt the process and start it later, the synchronization will continue from where you left off last time.
In general, the utility is very useful, and it has many other interesting parameters.