Magento Developer, Wordpress Integrator, Symfony 2 developer, Full stack web developer
Magento Developer
Wordpress Integrator
  • Home
  • Portfolio
  • Projects
    • WordPress Backup Plugin
  • Services
  • Contact

Migrating your IMAP mail? Here’s how!

February 4, 2010 Tips and Tricks 3 Comments

For those of you who are changing their IMAP email account to a different server, there is a very nice utility called imapsync.

The utility is actually written in PERL so it can run on any number of hosts that support PERL scripting, and while it has many config options, here is the actual command we used to transfer an email account from our server to Google Apps Mail account(GMail is the same) from a Linux box:

The command

imapsync \

–host1 thinkovi.com –user1 email@thinkovi.com –password1 mypass1 \

–host2 imap.gmail.com –user2 new@gmail.com –password2 pass2 \

–ssl2 –ssl1 –authmech1 PLAIN –authmech2 LOGIN

  • bear in mind that this utility will work only for email servers supporting IMAP protocol.
  • also, in the above code notice we have used SSL for both connections, and PLAIN authentication for the original server and LOGIN for the imap server at google

Result Message

++++ End looping on each folder ++++

++++ Statistics ++++

Time                   : 257 sec

Messages transferred   : 170

Messages skipped       : 0

Total bytes transferred: 12914745

Total bytes skipped    : 0

Total bytes error      : 0

Detected 0 errors

  • worth mentioning, the utility really worked and our gmail account contained in the end all email messages and folders from the original IMAP server

The full usage options(“imapsync –help“) and more information can also be found on the imapsync linux man page here.

Please, thank the author (Gilles LAMIRAL) by giving him a book:

http://www.amazon.com/gp/registry/wishlist/1C9UNDIH3P7R7/

Need Help?

We offer dedicated assistance for IMAP email accounts transfer, make an inquiry now.

usage: /usr/bin/imapsync [options]

Several options are mandatory.

–host1       <string> : “from” imap server. Mandatory.

–port1       <int>    : port to connect on host1. Default is 143.

–user1       <string> : user to login on host1. Mandatory.

–authuser1   <string> : user to auth with on host1 (admin user).

Avoid using –authmech1 SOMETHING with –authuser1.

–password1   <string> : password for the user1. Dangerous, use –passfile1

–passfile1   <string> : password file for the user1. Contains the password.

–host2       <string> : “destination” imap server. Mandatory.

–port2       <int>    : port to connect on host2. Default is 143.

–user2       <string> : user to login on host2. Mandatory.

–authuser2   <string> : user to auth with on host2 (admin user).

–password2   <string> : password for the user2. Dangerous, use –passfile2

–passfile2   <string> : password file for the user2. Contains the password.

–noauthmd5            : don’t use MD5 authentification.

–authmech1   <string> : auth mechanism to use with host1:

PLAIN, LOGIN, CRAM-MD5 etc. Use UPPERCASE.

–authmech2   <string> : auth mechanism to use with host2. See –authmech1

–ssl1                 : use an SSL connection on host1.

–ssl2                 : use an SSL connection on host2.

–folder      <string> : sync this folder.

–folder      <string> : and this one, etc.

–folderrec   <string> : sync this folder recursively.

–folderrec   <string> : and this one, etc.

–include     <regex>  : sync folders matching this regular expression

–include     <regex>  : or this one, etc.

in case both –include –exclude options are

use, include is done before.

–exclude     <regex>  : skips folders matching this regular expression

Several folders to avoid:

–exclude ‘fold1|fold2|f3’ skips fold1, fold2 and f3.

–exclude     <regex>  : or this one, etc.

–prefix1     <string> : remove prefix to all destination folders

(usually INBOX. for cyrus imap servers)

you can use –prefix1 if your source imap server

does not have NAMESPACE capability.

–prefix2     <string> : add prefix to all destination folders

(usually INBOX. for cyrus imap servers)

use –prefix2 if your target imap server does not

have NAMESPACE capability.

–regextrans2 <regex>  : Apply the whole regex to each destination folders.

–regextrans2 <regex>  : and this one. etc.

When you play with the –regextrans2 option, first

add also the safe options –dry –justfolders

Then, when happy, remove –dry, remove –justfolders

–regexmess   <regex>  : Apply the whole regex to each message before transfer.

Example: ‘s/\000/ /g’ # to replace null by space.

–regexmess   <regex>  : and this one.

–regexmess   <regex>  : and this one, etc.

–regexflag   <regex>  : Apply the whole regex to each flags list.

Example: ‘s/”Junk”//g’ # to remove “Junk” flag.

–regexflag   <regex>  : and this one, etc.

–sep1        <string> : separator in case namespace is not supported.

–sep2        <string> : idem.

–delete               : delete messages on source imap server after

a successful transfer. Useful in case you

want to migrate from one server to another one.

With imap, delete tags messages as deleted, they

are not really deleted. See expunge.

–delete2              : delete messages on the destination imap server that

are not on the source server.

–expunge              : expunge messages on source account.

expunge really deletes messages marked deleted.

expunge is made at the beginning on the

source server only. newly transferred messages

are expunged if option –expunge is given.

no expunge is done on destination account but

it will change in future releases.

–expunge1             : expunge messages on source account.

–expunge2             : expunge messages on target account.

–uidexpunge2          : uidexpunge messages on the destination imap server

that are not on the source server, requires –delete2

–syncinternaldates    : sets the internal dates on host2 same as host1.

Turned on by default.

–idatefromheader      : sets the internal dates on host2 same as the

“Date:” headers.

–buffersize  <int>    : sets the size of a block of I/O.

–maxsize     <int>    : skip messages larger than <int> bytes

–maxage      <int>    : skip messages older than <int> days.

final stats (skipped) don’t count older messages

see also –minage

–minage      <int>    : skip messages newer than <int> days.

final stats (skipped) don’t count newer messages

You can do (+ are the messages selected):

past|—-maxage+++++++++++++++>now

past|+++++++++++++++minage—->now

past|—-maxage+++++minage—->now (intersection)

past|++++minage—–maxage++++>now (union)

–skipheader  <regex>  : Don’t take into account header keyword

matching <string> ex: –skipheader ‘X.*’

–useheader   <string> : Use this header to compare messages on both sides.

Ex: Message-ID or Subject or Date.

–useheader   <string>   and this one, etc.

–skipsize             : Don’t take message size into account.

–allowsizemismatch    : allow RFC822.SIZE != fetched msg size

consider –skipsize to avoid duplicate messages

when running syncs more than one time per mailbox

–dry                  : do nothing, just print what would be done.

–subscribed           : transfers subscribed folders.

–subscribe            : subscribe to the folders transferred on the

“destination” server that are subscribed

on the “source” server.

–nofoldersizes        : Do not calculate the size of each folder in bytes

and message counts. Default is to calculate them.

–justfoldersizes      : exit after printed the folder sizes.

–syncacls             : Synchronises acls (Access Control Lists).

–nosyncacls           : Does not synchronise acls. This is the default.

–debug                : debug mode.

–debugimap            : imap debug mode.

–version              : print software version.

–justconnect          : just connect to both servers and print useful

information. Need only –host1 and –host2 options.

–justlogin            : just login to both servers with users credentials

and exit.

–justfolders          : just do things about folders (ignore messages).

–fast                 : be faster (just does not sync flags).

–reconnectretry1 <int>: reconnect if connection is lost up to <int> times

–reconnectretry2 <int>: reconnect if connection is lost up to <int> times

–split1     <int>     : split the requests in several parts on source server.

<int> is the number of messages handled per request.

default is like –split1 1000

–split2     <int>     : same thing on the “destination” server.

–fastio1              : use fastio with the “from” server.

–fastio2              : use fastio with the “destination” server.

–timeout     <int>    : imap connect timeout.

–help                 : print this.

Example: to synchronise imap account “foo” on “imap.truc.org”

to  imap account “bar” on “imap.trac.org”

with foo password stored in /etc/secret1

and  bar password stored in /etc/secret2

/usr/bin/imapsync \

–host1 imap.truc.org –user1 foo –passfile1 /etc/secret1 \

–host2 imap.trac.org –user2 bar –passfile2 /etc/secret2

Here is a [linux] system (Linux ovidiu-desktop 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:01:29 UTC 2009 i686)

with perl 5.10.0

Mail::IMAPClient  3.19

IO::Socket        1.30_01

IO::Socket::SSL

Digest::MD5       2.36_01

Digest::HMAC_MD5

Term::ReadKey

Date::Manip

$Id: imapsync,v 1.286 2009/07/24 15:53:04 gilles Exp gilles $

Happy with this free, open and gratis GPL software?

Please, thank the author (Gilles LAMIRAL) by giving him a book:

http://www.amazon.com/gp/registry/wishlist/1C9UNDIH3P7R7/

or rate imapsync at http://freshmeat.net/projects/imapsync/

Tags: imap email migration, transfer email account

Comments 3

  1. Mauricio

    July 5, 2010

    Thanks for this!

    I’m sorry, a very stupid question:

    Where did you “run” this lines? where did you type them? Im REAAAALLY new at this.

  2. Ovidiu

    Ovidiu

    July 5, 2010

    Hi Mauricio, the command was sent using a secure shell terminal on a linux box, please check here http://en.wikipedia.org/wiki/Secure_Shell

    Hope it helps! Ovidiu

  3. Mauricio

    July 5, 2010

    Whoa man, thanks for the quick response. Read it already, I’m requesting ssh access to my provider.

    Thanks a lot!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Home
  • Services
  • Blog
  • Contact
  • Privacy Policy
© Copyright 2020. Web Developer ThinkOvi.