Updated on | #imapsync, #mailbox, #imapclient | 0 User comments

Sync your IMAP Account - Synchronization with IMAPSync

The purpose of imapsync is to migrate an IMAP mailbox or to backup IMAP accounts. IMAP is one of the three current standard protocols to access mailboxes, the two other are POP3 and HTTP with webmails (often tied to an IMAP server). It allows multiple clients simultaneously connected to the same mailbox, and through flags stored on the server, different clients accessing the same mailbox at the same or different times can detect state changes made by other clients.

IMAPsync software is a command line tool that allows incremental and recursive Internet Message Access Protocol (IMAP) transfers from one mailbox to another, both anywhere on the internet or in your local network. "Incremental" means you can stop the transfer at any time and restart it later efficiently. "Recursive" means the complete folders hierarchy can be copied. "Command line" means it's not a graphical tool, on Windows you have to run imapsync in a DOS box (cmd.exe) or from a batch file.

Download imapsync

  1. mkdir /tmp/mail && cd /tmp/mail
  2. wget https://github.com/imapsync/imapsync/archive/master.zip
  3. unzip *.zip && cd imapsync-master

Test your Perl Installation

Perl is a highly capable, feature-rich programming language and it is used by imapsync. In this case, you have to verfiy if all needed libraries (libs) are installed with:

  1. perl -c imapsync

If you get an error message, you have to install the imapclient lib in perl:

  1. cpan -i Mail::IMAPClient

In this case, you need the following perl modules:

  • Mail::IMAPClient
  • Digest::MD5
  • Term::ReadKey
  • Digest::HMAC_MD5 (optional)

Test your IMAP Accounts

Use at first the dry option to test your IMAP Accounts.

  1. ./imapsync --dry \
  2. --host1 imap.host1.de --user1 user@host1.de --password1 my_password1 --authmech1 LOGIN \
  3. --host2 imap.host2.de --user2 user@host2.de --password2 my_password2 --authmech2 PLAIN

To synchronize imap account "user1" on "imap.host1.de" to imap account "user2" on "imap.host2.de" with user1 password "my_password1" and user2 password "my_password2".

Sync your IMAP Accounts

After you tested the dry option successfully, you can start to synchronize your data with:

  1. ./imapsync --timeout 0 --addheader --useheader ALL --nosyncacls --subscribe --syncinternaldates --buffersize 81920000 \
  2. --host1 imap.host1.de --user1 user@host1.de --password1 my_password1 --authmech1 LOGIN \
  3. --host2 imap.host2.de --user2 user@host2.de --password2 my_password2 --authmech2 PLAIN

At the end you will get a statistic like that:

  1. ++++ Statistics
  2. Transfer started on               : Tue Feb 25 10:20:36 2014
  3. Transfer ended on                 : Tue Feb 25 10:32:14 2014
  4. Transfer time                     : 698.0 sec
  5. Messages transferred              : 2583
  6. Messages skipped                  : 4144
  7. Messages found duplicate on host1 : 5
  8. Messages found duplicate on host2 : 0
  9. Messages void (noheader) on host1 : 26
  10. Messages void (noheader) on host2 : 0
  11. Messages deleted on host1         : 0
  12. Messages deleted on host2         : 0
  13. Total bytes transferred           : 605704012 (577.644 MiB)
  14. Total bytes duplicate host1       : 3927851 (3.746 MiB)
  15. Total bytes duplicate host2       : 0 (0.000 KiB)
  16. Total bytes skipped               : 421366549 (401.846 MiB)
  17. Total bytes error                 : 299252027 (285.389 MiB)
  18. Message rate                      : 3.7 messages/s
  19. Average bandwidth rate            : 847.4 KiB/s
  20. Reconnections to host1            : 0
  21. Reconnections to host2            : 0
  22. Memory consumption                : 287.5 MiB
  23. Biggest message                   : 22629105 bytes
  24. Initial difference host2 - host1  : -4158 messages, -908922416 bytes (-866.816 MiB)
  25. Final   difference host2 - host1  : -1570 messages, -303130061 bytes (-289.087 MiB)

More Informations

Manpage

  1. usage: /usr/bin/imapsync [options]
  2.  
  3. Several options are mandatory.
  4.  
  5. --host1       <string> : "from" imap server. Mandatory.
  6. --port1       <int>    : port to connect on host1. Default is 143.
  7. --user1       <string> : user to login on host1. Mandatory.
  8. --authuser1   <string> : user to auth with on host1 (admin user).
  9. --password1   <string> : password for the user1. Dangerous, use --passfile1
  10. --passfile1   <string> : password file for the user1. Contains the password.
  11. --host2       <string> : "destination" imap server. Mandatory.
  12. --port2       <int>    : port to connect on host2. Default is 143.
  13. --user2       <string> : user to login on host2. Mandatory.
  14. --authuser2   <string> : user to auth with on host2 (admin user).
  15. --password2   <string> : password for the user2. Dangerous, use --passfile2
  16. --passfile2   <string> : password file for the user2. Contains the password.
  17. --noauthmd5            : don't use MD5 authentification.
  18. --authmech1   <string> : auth mechanism to use with host1:
  19.                          PLAIN, LOGIN, CRAM-MD5 etc.
  20. --authmech2   <string> : auth mechanism to use with host2. See --authmech1
  21. --ssl1                 : use an SSL connection on host1.
  22. --ssl2                 : use an SSL connection on host2.
  23. --folder      <string> : sync this folder.
  24. --folder      <string> : and this one, etc.
  25. --folderrec   <string> : sync this folder recursively.
  26. --folderrec   <string> : and this one, etc.
  27. --include     <regex>  : sync folders matching this regular expression
  28. --include     <regex>  : or this one, etc.
  29.                          in case both --include --exclude options are
  30.                          use, include is done before.
  31. --exclude     <regex>  : skips folders matching this regular expression
  32.                          Several folders to avoid:
  33.                           --exclude 'fold1|fold2|f3' skips fold1, fold2 and f3.
  34. --exclude     <regex>  : or this one, etc.
  35. --prefix1     <string> : remove prefix to all destination folders
  36.                          (usually INBOX. for cyrus imap servers)
  37.                          you can use --prefix1 if your source imap server
  38.                          does not have NAMESPACE capability.
  39. --prefix2     <string> : add prefix to all destination folders
  40.                          (usually INBOX. for cyrus imap servers)
  41.                          use --prefix2 if your target imap server does not
  42.                          have NAMESPACE capability.
  43. --regextrans2 <regex>  : Apply the whole regex to each destination folders.
  44. --regextrans2 <regex>  : and this one. etc.
  45.                          When you play with the --regextrans2 option, first
  46.                          add also the safe options --dry --justfolders
  47.                          Then, when happy, remove --dry, remove --justfolders
  48. --regexmess   <regex>  : Apply the whole regex to each message before transfer.
  49.                          Example : 's/\000/ /g' # to replace null by space.
  50. --regexmess   <regex>  : and this one.
  51. --regexmess   <regex>  : and this one, etc.
  52. --regexflag   <regex>  : Apply the whole regex to each flags list.
  53.                          Example : 's/"Junk"//g' # to remove "Junk" flag.
  54. --regexflag   <regex>  : and this one, etc.
  55. --sep1        <string> : separator in case namespace is not supported.
  56. --sep2        <string> : idem.
  57. --delete               : delete messages on source imap server after
  58.                          a successful transfer. Useful in case you
  59.                          want to migrate from one server to another one.
  60.                          With imap, delete tags messages as deleted, they
  61.                          are not really deleted. See expunge.
  62. --delete2              : delete messages on the destination imap server that
  63.                          are not on the source server.
  64. --expunge              : expunge messages on source account.
  65.                          expunge really deletes messages marked deleted.
  66.                          expunge is made at the beginning on the
  67.                          source server only. newly transferred messages
  68.                          are expunged if option --expunge is given.
  69.                          no expunge is done on destination account but
  70.                          it will change in future releases.
  71. --expunge1             : expunge messages on source account.
  72. --expunge2             : expunge messages on target account.
  73. --syncinternaldates    : sets the internal dates on host2 same as host1
  74. --buffersize  <int>    : sets the size of a block of I/O.
  75. --maxsize     <int>    : skip messages larger than <int> bytes
  76. --maxage      <int>    : skip messages older than <int> days.
  77.                          final stats (skipped) don't count older messages
  78.                          see also --minage
  79. --minage      <int>    : skip messages newer than <int> days.
  80.                          final stats (skipped) don't count newer messages
  81.                          You can do (+ are the messages selected):
  82.                          past|----maxage+++++++++++++++>now
  83.                          past|+++++++++++++++minage---->now
  84.                          past|----maxage+++++minage---->now (intersection)
  85.                          past|++++minage-----maxage++++>now (union)
  86. --skipheader  <regex>  : Don't take into account header keyword
  87.                          matching <string> ex: --skipheader 'X.*'
  88. --useheader   <string> : Use this header to compare messages on both sides.
  89.                          Ex: Message-ID or Subject or Date.
  90. --useheader   <string>   and this one, etc.
  91. --skipsize             : Don't take message size into account.
  92. --dry                  : do nothing, just print what would be done.
  93. --subscribed           : transfers subscribed folders.
  94. --subscribe            : subscribe to the folders transferred on the
  95.                          "destination" server that are subscribed
  96.                          on the "source" server.
  97. --(no)foldersizes      : Calculate the size of each "From" folder in bytes
  98.                          and message counts. Meant to be used with
  99.                          --justfoldersizes. Turned on by default.
  100. --justfoldersizes      : exit after printed the folder sizes.
  101. --syncacls             : Synchronises acls (Access Control Lists).
  102. --nosyncacls           : Does not synchronise acls. This is the default.
  103. --debug                : debug mode.
  104. --debugimap            : imap debug mode.
  105. --version              : print software version.
  106. --justconnect          : just connect to both servers and print useful
  107.                          information. Need only --host1 and --host2 options.
  108. --justfolders          : just do things about folders (ignore messages).
  109. --fast                 : be faster (just does not sync flags).
  110. --split1     <int>     : split the requests in several parts on source server.
  111.                          <int > is the number of messages handled per request.
  112.                          default is like --split1 1000
  113. --split2     <int>     : same thing on the "destination" server.
  114. --nofastio1            : don't use fastio with the "from" server.
  115. --nofastio2            : don't use fastio with the "destination" server.
  116. --timeout     <int>    : imap connect timeout.
  117. --help                 : print this.
  118.  
  119. Example: to synchronise imap account "foo" on "imap.truc.org"
  120.                      to imap account "bar" on "imap.trac.org"
  121.  
  122. /usr/bin/imapsync \
  123.    --host1 imap.truc.org --user1 foo --passfile1 /etc/secret1 \
  124.    --host2 imap.trac.org --user2 bar --passfile2 /etc/secret2
  125.  
  126.  
  127.  Mail::IMAPClient version is 2.2.9
  128.  $Id: imapsync,v 1.219 2007/04/04 09:32:20 gilles Exp $
  129.       imapsync copyleft is the GNU General Public License.
  130.       See http://www.gnu.org/copyleft/gpl.html

Well, what do you think?

Comments powered by LudwigDisqus for ModX