Moving E-Mail from Gmail to Google Apps over IMAP using imapsync

Two years ago, I transitioned from using regular Gmail (i.e. "…") to setting up Google Apps for "" (i.e. "…"). I had found the following article back then which gave me helpful hints on how to use imapsync to push data to my new Google Apps e-mail address:

I adapted that script for my own needs, and I was able to successfully copy all the mail from my regular Gmail account to my new Google Apps account.

Here is the final script I ended-up with:

# Copy all e-mail from to (Google Apps)
imapsync \
--host1 --port1 993 --user1 \
--passfile1 /path/to/gmail_mirror.passfile1 --ssl1 \
--host2 --port2 993 --user2 \
--passfile2 /path/to/gmail_mirror.passfile2 --ssl2 \
--useheader 'Message-Id' --skipsize \
--syncinternaldates --noauthmd5 -nofoldersizes \
--split1 100 --split2 100 \
--maxage 50 \
--regexmess 's/Delivered-To: source\ target\'

The --syncinternaldates, --useheader 'Message-Id', and --skipsize options are all recommended by the imapsync FAQ (search for "Gmail"):

I opted to use the --passfile1/passfile2 options rather than passing in a plain-text password in via a command-line param for two reasons: first because anyone with access to your system can use ps to view active processes and hence would see your password plain-as-day; second because it just better abstracts the script-logic from the password-text, and we can control the file-permissions of those password files.

All your Gmail labels should sync-over automagically. Since this is going Google-to-Google, because Google presents labels as separate IMAP folders in their Gmail IMAP implementation, the process above should sync and preserve all your Gmail labels for free.

It's been a two years since I've used this script, but I seem to remember it working pretty painlessly. I wanted to share it here for anyone else who might be looking to do this same thing.