Skip to content

Instantly share code, notes, and snippets.

Forked from dalethedeveloper/
Last active January 16, 2017 21:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Transferring to/from Gmail accounts to a Google Apps account with imapsync. Also good for GApps to GApps transfers, archives, or migrations.
# Most of the tweaks here are wrapped up in gmailmig
# Props to brave folks who figured this out before me
# Loop thorugh multiple times as things behave better working in 500mb chunks (-exitwhenover 500000000)
for i in {1..10}
imapsync –split1 100 –split2 100 --fast --syncinternaldates --nocheckmessageexists --allowsizemismatch --exitwhenover 500000000 -host1 -host2 -port1 993 -port2 993 --ssl2 --ssl1 --authmech2 LOGIN --authmech2 LOGIN \
--pidfile '/tmp/' \
-user1 $USER1USERNAME -password1 $USER1PASSWORD \
-user2 $USER2USERNAME -password2 $USER2PASSWORD \
# --regexmess 's/Delivered-To: OLDGMAIL\@GMAIL.COM/Delivered-To: NEWGMAIL\@GAPPS.COM/g' \
# --regexmess 's/<OLDGMAIL\@GMAIL.COM>/<NEWGMAIL\@GAPPS.COM>/g' \
--regexmess 's/Subject:(s*)\n/Subject: (no–subject)$1n/g' \
--regexmess 's/Subject: ([Rr][Ee]):(s*)\n/Subject: $1: (no–subject)$2n/g' \
--include '^\[Gmail\]\/All Mail' \
--include '^\[Gmail\]\/Sent' \
--regextrans2 's/\[Gmail\]\///' \
# If you want to keep transferred mail in a separate tag/folder
# --regextrans2 's/(.*)/OLDGMAIL\/$1/' \
--nofoldersizes &
# Use this line instead of the above to dry run and see what folders will go
# --dry --justfolders ;
# Let imapsync fire up and set the hardcoded PID file above in --pidfile
sleep 10
cpid=`cat /tmp/`
# Peek in periodically to see if we're still running
while kill -0 $cpid
sleep 30
#Tip: Run like this to log: $> nohup ./ >>sync.log &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment