On Linux I used #imapSync for copying all emails and folders from one account to another. My hosting provider had this tool installed but it can run on your machine at home.
It is no longer in the official Debian repositories, I have read that #mailSync can do the same.
I used the following (rest is code):
imapsync \
--logdir ~/logs/imapsync \
--host1 imap.example.com \
--user1 first.user@example.com \
--ssl1 \
--host2 example.org \
--user2 second.user@example.org \
--ssl2 \
