Credit goes directly to cenolan.com’s blog post – http://www.cenolan.com/2012/02/mass-email-migration-from-imap-to-google-apps-using-imapsync/
This method includes a text file containing the users source email address and password as well as the destination (Google) email address and password. Imapsync is the engine to transfer the email and there is a bash script to drive it.
*Allow each user to update their password once email is directed to Google
**Allow less secure apps to allow the transfer to work – http://support.google.com/a/answer/6260879?hl=en – turn off again once complete
Insert the following into a text file (update with live details):
firstname.lastname@example.org;user1sourcepassword;email@example.com;user1destinationpassword firstname.lastname@example.org;user2sourcepassword;email@example.com;user2destinationpassword firstname.lastname@example.org;user3sourcepassword;email@example.com;user3destinationpassword
Add as many users as necessary. I found it helpful to add 10 users into a text file at a time to keep an eye on transfers.
Create the script: