Home > howto, it admin, linux > ImapSync to Gmail Script

ImapSync to Gmail Script

January 26th, 2010

Yes sounds easy but I spent sometime looking for the perfect way to import imap mail for any mail server to imap gmail. This is particularly useful if you are transferring your existing mail accounts to google hosted application.

This handles transferring all existing imap folders and even putting your sent mail, spam, drafts, trash into gmail’s special folder naming convention.  Beware this is one sexy script!Its pretty short and sweet. All you need is the program imapsync
(ie. ubuntu: apt-get install imapsync)

Paste the contents of this file into imap2gmail

# nano imap2gmail
# chmod +x imap2gmail

then run it
# ./imap2gmail

#!/bin/sh
 
#Configure User
SERVER1=imap.anotherserver.com
UNAME1=demo@anotherserver.com
PWORD1=54321
UNAME2=demo@gmail.com
PWORD2=12345
 
#Blank this out if you want to see folder sizes
HIDE="--nofoldersizes --skipsize"
 
imapsync --syncinternaldates --useheader 'Message-Id' \
--host1 ${SERVER1} --user1 ${UNAME1} \
--password1 ${PWORD1} --ssl1 \
--host2 imap.googlemail.com \
--port2 993 --user2 ${UNAME2} \
--password2 ${PWORD2} --ssl2 \
--authmech1 LOGIN --authmech2 LOGIN --split1 200 --split2 200 ${HIDE} \
--exclude 'Drafts|Trash|Spam|Sent'
 
#TO Sync Special Folders to Gmail
imapsync --syncinternaldates --useheader 'Message-Id' \
--host1 ${SERVER1} --user1 ${UNAME1} \
--password1 ${PWORD1} --ssl1 \
--host2 imap.googlemail.com \
--port2 993 --user2 ${UNAME2} \
--password2 ${PWORD2} --ssl2 \
--ssl2 --noauthmd5 --split1 200 --split2 200 ${HIDE} \
--folder "Inbox/Sent" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Sent/Sent Mail/' \
--folder "Inbox/Spam" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Spam/Spam/' \
--folder "Inbox/Trash" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Trash/Trash/' \
--folder "Inbox/Drafts" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Drafts/Drafts/' \
Share and Enjoy:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Furl
  • Print
  • StumbleUpon

howto, it admin, linux ,

  1. No comments yet.
  1. No trackbacks yet.