PHP script to handle basic email IMAP migration from one account to another. If you need more sophisticated software, you can purchase imapsync.
Project available at: https://edoceo.com/dev/imap-move and github
Use example:
curl edoceo.com/pub/imap-move.php > imap-move.php
php ./imap-move.php \
--source imap-ssl://userA@domain:secretA@imap.example.com:993/ \
--target imap-ssl://userB@domain:secretB@imap.example.com:993/
Move from Gmail to Google Apps
This copies from a Gmail style account to a Google Apps hosted domain duplicating folder structure
php ./imap-move.php \
-s imap-ssl://userA@gmail.com:secretA@imap.gmail.com:993/ \
-t imap-ssl://userB@domain.tld:secretB@imap.gmail.com:993/