You can use https://github.com/Schluggi/pymap-copy as well. I think this is more handsome, because you don't have to compile anything.
If you would like it as described above (copy every mail of every subfolder to the import folder):
./pymap-copy.py \
--source-user=user1 \
--source-server=server1.example.org \
--source-pass=2345678 \
--destination-user=user2 \
--destination-server=server2.example.info \
--destination-pass=abcdef \
--redirect *:INBOX.import
And in the case you want to maintain your folder structure:
./pymap-copy.py \
--source-user=user1 \
--source-server=server1.example.org \
--source-pass=2345678 \
--destination-user=user2 \
--destination-server=server2.example.info \
--destination-pass=abcdef \
--destination-root INBOX.import