Imap migration

From Simson Garfinkel
Revision as of 14:25, 19 September 2009 by Simson (talk | contribs) (Created page with 'I found that the easiest way to move imap accounts from server to another is to use the '''imapsync''' program that can be installed using the MacPorts system. You can install it…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

I found that the easiest way to move imap accounts from server to another is to use the imapsync program that can be installed using the MacPorts system. You can install it with this command:

 sudo port install imapsync 
 sudo port install p5-digest-hmac

Here is an example of the parameters of the program:

$ imapsync

usage: /opt/local/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

/opt/local/bin/imapsync \
   --host1 imap.truc.org --user1 foo --passfile1 /etc/secret1 \
   --host2 imap.trac.org --user2 bar --passfile2 /etc/secret2

Here is a [darwin] system (Darwin imac2.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386)
with perl 5.8.9
Mail::IMAPClient  3.19
IO::Socket        1.30
IO::Socket::SSL   
Digest::MD5       2.39
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/

simsong@imac2:~$