Depending on your specific needs, you probably want one of imapsync, isync/mbsync, or OfflineIMAP. You could also use mutt or Thunderbird or the client of your choice to connect to both servers and move items through the UI.
If you have file-level access to the mail servers, any kind of file transfer of the maildirs should work. But from your description I'd encourage you to spend some time looking at imapsync, I think it's the closest fit to what you're wanting to do.