Use IMAPSYNC
It even has an online version so that you do not have to install it:
https://i005.lamiral.info/X/