1IMAPSYNC(1) User Contributed Perl Documentation IMAPSYNC(1)
2
3
4
6 imapsync - Email IMAP tool for syncing, copying and migrating email
7 mailboxes between two imap servers, one way, and without duplicates.
8
10 This documentation refers to Imapsync $Revision: 1.882 $
11
13 To synchronize the source imap account
14 "test1" on server "test1.lamiral.info" with password "secret1"
15 to the destination imap account
16 "test2" on server "test2.lamiral.info" with password "secret2"
17 do:
18
19 imapsync \
20 --host1 test1.lamiral.info --user1 test1 --password1 secret1 \
21 --host2 test2.lamiral.info --user2 test2 --password2 secret2
22
24 We sometimes need to transfer mailboxes from one imap server to one
25 another.
26
27 Imapsync command is a tool allowing incremental and recursive imap
28 transfers from one mailbox to another.
29
30 By default all folders are transferred, recursively, meaning the whole
31 folder hierarchy is taken, all messages in them, and all messages flags
32 (\Seen \Answered \Flagged etc.) are synced too.
33
34 Imapsync reduces the amount of data transferred by not transferring a
35 given message if it resides already on both sides.
36
37 Same specific headers and the transfer is done only once. By default,
38 the identification headers are "Message-Id:" and "Received:" lines but
39 this choice can be changed with the --useheader option.
40
41 All flags are preserved, unread messages will stay unread, read ones
42 will stay read, deleted will stay deleted.
43
44 You can stop the transfer at any time and restart it later, imapsync
45 works well with bad connections and interruptions, by design.
46
47 You can decide to delete the messages from the source mailbox after a
48 successful transfer, it can be a good feature when migrating live
49 mailboxes since messages will be only on one side.
50
51 In that case, use the --delete1 option. Option --delete1 implies also
52 option --expunge1 so all messages marked deleted on host1 will be
53 really deleted.
54
55 You can also decide to remove empty folders once all of their messages
56 have been transferred. Add --delete1emptyfolders to obtain this
57 behavior.
58
59 A different scenario is synchronizing a mailbox B from another mailbox
60 A in case you just want to keep a "live" copy of A in B.
61
62 For this, option --delete2 has to be used, it deletes messages in host2
63 folder B that are not in host1 folder A. If you also need to destroy
64 host2 folders that are not in host1 then use --delete2folders. See also
65 --delete2foldersonly and --delete2foldersbutnot.
66
67 Imapsync is not adequate for maintaining two active imap accounts in
68 synchronization when the user plays independently on both sides. Use
69 offlineimap (written by John Goerzen) or mbsync (written by Michael R.
70 Elkins) for a 2 ways synchronization.
71
73 usage: imapsync [options]
74
75 Mandatory options are the six values, three on each sides, needed to
76 log in into the IMAP servers, ie, a host, a username, and a password,
77 two times.
78
79 Conventions used:
80
81 str means string
82 int means integer
83 reg means regular expression
84 cmd means command
85
86 --dry : Makes imapsync doing nothing for real, just print what
87 would be done without --dry.
88
89 OPTIONS/credentials
90 --host1 str : Source or "from" imap server. Mandatory.
91 --port1 int : Port to connect on host1.
92 Optional since default port is 143 or 993 if --ssl1
93 --user1 str : User to login on host1. Mandatory.
94 --password1 str : Password for the user1.
95
96 --host2 str : "destination" imap server. Mandatory.
97 --port2 int : Port to connect on host2.
98 Optional since default port is 143 or 993 if --ssl2
99 --user2 str : User to login on host2. Mandatory.
100 --password2 str : Password for the user2.
101
102 --showpasswords : Shows passwords on output instead of "MASKED".
103 Useful to restart a complete run by just reading the log,
104 or to debug passwords. It's not a secure practice.
105
106 --passfile1 str : Password file for the user1. It must contain the
107 password on the first line. This option avoids to show
108 the password on the command line like --password1 does.
109 --passfile2 str : Password file for the user2. Contains the password.
110
111 OPTIONS/encryption
112 --nossl1 : Do not use a SSL connection on host1.
113 --ssl1 : Use a SSL connection on host1. On by default if possible.
114
115 --nossl2 : Do not use a SSL connection on host2.
116 --ssl2 : Use a SSL connection on host2. On by default if possible.
117
118 --notls1 : Do not use a TLS connection on host1.
119 --tls1 : Use a TLS connection on host1. On by default if possible.
120
121 --notls2 : Do not use a TLS connection on host2.
122 --tls2 : Use a TLS connection on host2. On by default if possible.
123
124 --debugssl int : SSL debug mode from 0 to 4.
125
126 --sslargs1 str : Pass any ssl parameter for host1 ssl or tls connection. Example:
127 --sslargs1 SSL_verify_mode=1 --sslargs1 SSL_version=SSLv3
128 See all possibilities in the new() method of IO::Socket::SSL
129 http://search.cpan.org/perldoc?IO::Socket::SSL#Description_Of_Methods
130 --sslargs2 str : Pass any ssl parameter for host2 ssl or tls connection.
131 See --sslargs1
132
133 --timeout1 int : Connection timeout in seconds for host1.
134 Default is 120 and 0 means no timeout at all.
135 --timeout2 int : Connection timeout in seconds for host2.
136 Default is 120 and 0 means no timeout at all.
137
138 OPTIONS/authentication
139 --authmech1 str : Auth mechanism to use with host1:
140 PLAIN, LOGIN, CRAM-MD5 etc. Use UPPERCASE.
141 --authmech2 str : Auth mechanism to use with host2. See --authmech1
142
143 --authuser1 str : User to auth with on host1 (admin user).
144 Avoid using --authmech1 SOMETHING with --authuser1.
145 --authuser2 str : User to auth with on host2 (admin user).
146 --proxyauth1 : Use proxyauth on host1. Requires --authuser1.
147 Required by Sun/iPlanet/Netscape IMAP servers to
148 be able to use an administrative user.
149 --proxyauth2 : Use proxyauth on host2. Requires --authuser2.
150
151 --authmd51 : Use MD5 authentication for host1.
152 --authmd52 : Use MD5 authentication for host2.
153 --domain1 str : Domain on host1 (NTLM authentication).
154 --domain2 str : Domain on host2 (NTLM authentication).
155
156 OPTIONS/folders
157 --folder str : Sync this folder.
158 --folder str : and this one, etc.
159 --folderrec str : Sync this folder recursively.
160 --folderrec str : and this one, etc.
161
162 --folderfirst str : Sync this folder first. --folderfirst "Work"
163 --folderfirst str : then this one, etc.
164 --folderlast str : Sync this folder last. --folderlast "[Gmail]/All Mail"
165 --folderlast str : then this one, etc.
166
167 --nomixfolders : Do not merge folders when host1 is case-sensitive
168 while host2 is not (like Exchange). Only the first
169 similar folder is synced (ex: with Sent SENT sent
170 on host1 only Sent will be synced to host2).
171
172 --skipemptyfolders : Empty host1 folders are not created on host2.
173
174 --include reg : Sync folders matching this regular expression
175 --include reg : or this one, etc.
176 If both --include --exclude options are used, then
177 include is done before.
178 --exclude reg : Skips folders matching this regular expression
179 Several folders to avoid:
180 --exclude 'fold1|fold2|f3' skips fold1, fold2 and f3.
181 --exclude reg : or this one, etc.
182
183 --automap : guesses folders mapping, for folders well known as
184 "Sent", "Junk", "Drafts", "All", "Archive", "Flagged".
185
186 --f1f2 str1=str2 : Force folder str1 to be synced to str2,
187 --f1f2 overrides --automap and --regextrans2.
188
189 --subfolder2 str : Move whole host1 folders hierarchy under this
190 host2 folder str .
191 It does it by adding two --regextrans2 options before
192 all others. Add --debug to see what's really going on.
193
194 --subscribed : Transfers subscribed folders.
195 --subscribe : Subscribe to the folders transferred on the
196 host2 that are subscribed on host1. On by default.
197 --subscribeall : Subscribe to the folders transferred on the
198 host2 even if they are not subscribed on host1.
199
200 --prefix1 str : Remove prefix str to all destination folders,
201 usually INBOX. or INBOX/ or an empty string "".
202 imapsync guesses the prefix if host1 imap server
203 does not have NAMESPACE capability. This option
204 should not be used, most of the time.
205 --prefix2 str : Add prefix to all host2 folders. See --prefix1
206 --sep1 str : Host1 separator in case NAMESPACE is not supported.
207 --sep2 str : Host2 separator in case NAMESPACE is not supported.
208
209 --regextrans2 reg : Apply the whole regex to each destination folders.
210 --regextrans2 reg : and this one. etc.
211 When you play with the --regextrans2 option, first
212 add also the safe options --dry --justfolders
213 Then, when happy, remove --dry, remove --justfolders.
214 Have in mind that --regextrans2 is applied after prefix
215 and separator inversion. For examples see
216 https://imapsync.lamiral.info/FAQ.d/FAQ.Folders_Mapping.txt
217
218 OPTIONS/folders sizes
219 --nofoldersizes : Do not calculate the size of each folder at the
220 beginning of the sync. Default is to calculate them.
221 --nofoldersizesatend: Do not calculate the size of each folder at the
222 end of the sync. Default is to calculate them.
223 --justfoldersizes : Exit after having printed the initial folder sizes.
224
225 OPTIONS/tmp
226 --tmpdir str : Where to store temporary files and subdirectories.
227 Will be created if it doesn't exist.
228 Default is system specific, Unix is /tmp but
229 /tmp is often too small and deleted at reboot.
230 --tmpdir /var/tmp should be better.
231 --pidfile str : The file where imapsync pid is written,
232 it can be dirname/filename.
233 Default name is imapsync.pid in tmpdir.
234 --pidfilelocking : Abort if pidfile already exists. Useful to avoid
235 concurrent transfers on the same mailbox.
236
237 OPTIONS/log
238 --nolog : Turn off logging on file
239 --logfile str : Change the default log filename (can be dirname/filename).
240 --logdir str : Change the default log directory. Default is LOG_imapsync/
241
242 OPTIONS/messages
243 --skipmess reg : Skips messages matching the regex.
244 Example: 'm/[\x80-ff]/' # to avoid 8bits messages.
245 --skipmess is applied before --regexmess
246 --skipmess reg : or this one, etc.
247
248 --pipemess cmd : Apply this cmd command to each message content
249 before the copy.
250 --pipemess cmd : and this one, etc.
251
252 --disarmreadreceipts : Disarms read receipts (host2 Exchange issue)
253
254 --regexmess reg : Apply the whole regex to each message before transfer.
255 Example: 's/\000/ /g' # to replace null by space.
256 --regexmess reg : and this one, etc.
257
258 OPTIONS/flags
259 --regexflag reg : Apply the whole regex to each flags list.
260 Example: 's/"Junk"//g' # to remove "Junk" flag.
261 --regexflag reg : then this one, etc.
262
263 --resyncflags : Resync flags for already transferred messages.
264 On by default.
265 --noresyncflags : Do not resync flags for already transferred messages.
266 May be useful when a user has already started to play
267 with its host2 account.
268
269 OPTIONS/deletions
270 --delete1 : Deletes messages on host1 server after a successful
271 transfer. Option --delete1 has the following behavior:
272 it marks messages as deleted with the IMAP flag
273 \Deleted, then messages are really deleted with an
274 EXPUNGE IMAP command. If expunging after each message
275 slows down too much the sync then use
276 --noexpungeaftereach to speed up.
277 --expunge1 : Expunge messages on host1 just before syncing a folder.
278 Expunge is done per folder.
279 Expunge aims is to really delete messages marked deleted.
280 An expunge is also done after each message copied
281 if option --delete1 is set.
282 --noexpunge1 : Do not expunge messages on host1.
283 --delete1emptyfolders : Deletes empty folders on host1, INBOX excepted.
284 Useful with --delete1 since what remains on host1
285 is only what failed to be synced.
286
287 --delete2 : Delete messages in host2 that are not in
288 host1 server. Useful for backup or pre-sync.
289 --delete2duplicates : Delete messages in host2 that are duplicates.
290 Works only without --useuid since duplicates are
291 detected with an header part of each message.
292
293 --delete2folders : Delete folders in host2 that are not in host1 server.
294 For safety, first try it like this (it is safe):
295 --delete2folders --dry --justfolders --nofoldersizes
296 --delete2foldersonly reg : Deleted only folders matching regex.
297 Example: --delete2foldersonly "/^Junk$|^INBOX.Junk$/"
298 --delete2foldersbutnot reg : Do not delete folders matching regex.
299 Example: --delete2foldersbutnot "/Tasks$|Contacts$|Foo$/"
300
301 --expunge2 : Expunge messages on host2 after messages transfer.
302 --uidexpunge2 : uidexpunge messages on the host2 account
303 that are not on the host1 account, requires --delete2
304
305 OPTIONS/dates
306 --syncinternaldates : Sets the internal dates on host2 same as host1.
307 Turned on by default. Internal date is the date
308 a message arrived on a host (mtime).
309 --idatefromheader : Sets the internal dates on host2 same as the
310 "Date:" headers.
311 If you encounter problems with dates see also
312 https://imapsync.lamiral.info/FAQ.d/FAQ.Dates.txt
313
314 OPTIONS/message selection
315 --maxsize int : Skip messages larger (or equal) than int bytes
316 --minsize int : Skip messages smaller (or equal) than int bytes
317 --maxage int : Skip messages older than int days.
318 final stats (skipped) don't count older messages
319 see also --minage
320 --minage int : Skip messages newer than int days.
321 final stats (skipped) don't count newer messages
322 You can do (+ are the messages selected):
323 past|----maxage+++++++++++++++>now
324 past|+++++++++++++++minage---->now
325 past|----maxage+++++minage---->now (intersection)
326 past|++++minage-----maxage++++>now (union)
327
328 --search str : Selects only messages returned by this IMAP SEARCH
329 command. Applied on both sides.
330 For a complete of what can be search see
331 https://imapsync.lamiral.info/FAQ.d/FAQ.Messages_Selection.txt
332
333 --search1 str : Same as --search but for selecting host1 messages only.
334 --search2 str : Same as --search but for selecting host2 messages only.
335 --search CRIT equals --search1 CRIT --search2 CRIT
336
337 --maxlinelength int : skip messages with a line length longer than int bytes.
338 RFC 2822 says it must be no more than 1000 bytes.
339
340
341 --useheader str : Use this header to compare messages on both sides.
342 Ex: Message-ID or Subject or Date.
343 --useheader str and this one, etc.
344
345 --usecache : Use cache to speed up the sync.
346 --nousecache : Do not use cache. Caveat: --useuid --nousecache creates
347 duplicates on multiple runs.
348 --useuid : Use UIDs instead of headers as a criterium to recognize
349 messages. Option --usecache is then implied unless
350 --nousecache is used.
351
352 OPTIONS/miscellaneous
353 --syncacls : Synchronizes acls (Access Control Lists).
354 --nosyncacls : Does not synchronize acls. This is the default.
355 Acls in IMAP are not standardized, be careful.
356
357 OPTIONS/debugging
358 --debug : Debug mode.
359 --debugfolders : Debug mode for the folders part only.
360 --debugcontent : Debug content of the messages transferred. Huge output.
361 --debugflags : Debug mode for flags.
362 --debugimap1 : IMAP debug mode for host1. Very verbose.
363 --debugimap2 : IMAP debug mode for host2. Very verbose.
364 --debugimap : IMAP debug mode for host1 and host2. Twice very verbose.
365 --debugmemory : Debug mode showing memory consumption after each copy.
366
367 --errorsmax int : Exit when int number of errors is reached. Default is 50.
368
369 --tests : Run local non-regression tests. Exit code 0 means all ok.
370 --testslive : Run a live test with test1.lamiral.info imap server.
371 Useful to check the basics. Needs internet connection.
372 --testslive6 : Run a live test with ks2ipv6.lamiral.info imap server.
373 Useful to check the ipv6 connectivity. Needs internet.
374
375 OPTIONS/specific
376 --gmail1 : sets --host1 to Gmail and options from FAQ.Gmail.txt
377 --gmail2 : sets --host2 to Gmail and options from FAQ.Gmail.txt
378
379 --office1 : sets --host1 to Office365 options from FAQ.Exchange.txt
380 --office2 : sets --host2 to Office365 options from FAQ.Exchange.txt
381
382 --exchange1 : sets options from FAQ.Exchange.txt, account1 part
383 --exchange2 : sets options from FAQ.Exchange.txt, account2 part
384
385 --domino1 : sets options from FAQ.Domino.txt, account1 part
386 --domino2 : sets options from FAQ.Domino.txt, account2 part
387
388 OPTIONS/behavior
389 --maxmessagespersecond int : limits the number of messages transferred per second.
390
391 --maxbytespersecond int : limits the average transfer rate per second.
392 --maxbytesafter int : starts --maxbytespersecond limitation only after
393 --maxbytesafter amount of data transferred.
394
395 --maxsleep int : do not sleep more than int seconds.
396 On by default, 2 seconds max, like --maxsleep 2
397
398 --abort : terminates a previous call still running.
399 It uses the pidfile to know what process to abort.
400
401 --exitwhenover int : Stop syncing when total bytes transferred reached.
402
403 --version : Print only software version.
404 --noreleasecheck : Do not check for new imapsync release (a http request).
405 --releasecheck : Check for new imapsync release (a http request).
406 --noid : Do not send/receive ID command to imap servers.
407 --justconnect : Just connect to both servers and print useful
408 information. Need only --host1 and --host2 options.
409 --justlogin : Just login to both host1 and host2 with users
410 credentials, then exit.
411 --justfolders : Do only things about folders (ignore messages).
412
413 --help : print this help.
414
415 Example: to synchronize imap account "test1" on "test1.lamiral.info"
416 to imap account "test2" on "test2.lamiral.info"
417 with test1 password "secret1"
418 and test2 password "secret2"
419
420 imapsync \
421 --host1 test1.lamiral.info --user1 test1 --password1 secret1 \
422 --host2 test2.lamiral.info --user2 test2 --password2 secret2
423
425 You can use --passfile1 instead of --password1 to give the password
426 since it is safer. With --password1 option, any user on your host can
427 see the password by using the 'ps auxwwww' command. Using a variable
428 (like $PASSWORD1) is also dangerous because of the 'ps auxwwwwe'
429 command. So, saving the password in a well protected file (600 or
430 rw-------) is the best solution.
431
432 Imapsync activates ssl or tls encryption by default, if possible. What
433 detailed behavior is under this "if possible"? Imapsync activates ssl
434 if the well known port imaps port (993) is open on the imap servers. If
435 the imaps port is closed then it open a normal (clear) connection on
436 port 143 but it looks for TLS support in the CAPABILITY list of the
437 servers. If TLS is supported then imapsync goes to encryption.
438
439 If the automatic ssl/tls detection fails then imapsync will not protect
440 against sniffing activities on the network, especially for passwords.
441
442 If you want to force ssl or tls just use --ssl1 --ssl2 or --tls1 --tls2
443
444 See also the document FAQ.Security.txt in the FAQ.d/ directory or at
445 https://imapsync.lamiral.info/FAQ.d/FAQ.Security.txt
446
448 Imapsync will exit with a 0 status (return code) if everything went
449 good. Otherwise, it exits with a non-zero status.
450
452 Imapsync is free, open, public but not always gratis software cover by
453 the NOLIMIT Public License. See the LICENSE file included in the
454 distribution or just read this simple sentence as it IS the licence
455 text:
456
457 "No limits to do anything with this work and this license."
458
459 In case it is not long enough, I repeat:
460
461 "No limits to do anything with this work and this license."
462
463 https://imapsync.lamiral.info/LICENSE
464
466 Gilles LAMIRAL <gilles@lamiral.info>
467
468 Feedback good or bad is very often welcome.
469
470 Gilles LAMIRAL earns his living by writing, installing, configuring and
471 teaching free, open and often gratis software. Imapsync used to be
472 "always gratis" but now it is only "often gratis" because imapsync is
473 sold by its author, a good way to maintain and support free open public
474 software over decades.
475
477 See https://imapsync.lamiral.info/FAQ.d/FAQ.Reporting_Bugs.txt
478
480 See https://imapsync.lamiral.info/S/imapservers.shtml
481
483 Pay special attention to options --subscribed --subscribe --delete1
484 --delete1emptyfolders --delete2 --delete2folders --maxage --minage
485 --maxsize --useuid --usecache
486
487 If you have many mailboxes to migrate think about a little shell
488 program. Write a file called file.txt (for example) containing users
489 and passwords. The separator used in this example is ';'
490
491 The file.txt file contains:
492
493 user001_1;password001_1;user001_2;password001_2
494 user002_1;password002_1;user002_2;password002_2
495 user003_1;password003_1;user003_2;password003_2
496 user004_1;password004_1;user004_2;password004_2
497 user005_1;password005_1;user005_2;password005_2 ...
498
499 On Unix the shell program can be:
500
501 { while IFS=';' read u1 p1 u2 p2; do
502 imapsync --host1 imap.side1.org --user1 "$u1" --password1 "$p1" \
503 --host2 imap.side2.org --user2 "$u2" --password2 "$p2" ...
504 done ; } < file.txt
505
506 On Windows the batch program can be:
507
508 FOR /F "tokens=1,2,3,4 delims=; eol=#" %%G IN (file.txt) DO imapsync ^
509 --host1 imap.side1.org --user1 %%G --password1 %%H ^
510 --host2 imap.side2.org --user2 %%I --password2 %%J ...
511
512 The ... have to be replaced by nothing or any imapsync option. Welcome
513 in shell or batch programming !
514
515 You will find already written scripts at
516 https://imapsync.lamiral.info/examples/
517
519 Imapsync works under any Unix with perl.
520
521 Imapsync works under most Windows (2000, XP, Vista, Seven, Eight, Ten
522 and all Server releases 2000, 2003, 2008 and R2, 2012 and R2)
523 as a standalone binary software called imapsync.exe,
524 usually launched from a batch file in order to avoid always typing
525 the options.
526
527 Imapsync works under OS X as a standalone binary
528 software called imapsync_bin_Darwin
529
530 Purchase latest imapsync at
531 https://imapsync.lamiral.info/
532
533 You'll receive a link to a compressed tarball called imapsync-x.xx.tgz
534 where x.xx is the version number. Untar the tarball where
535 you want (on Unix):
536
537 tar xzvf imapsync-x.xx.tgz
538
539 Go into the directory imapsync-x.xx and read the INSTALL file.
540 As mentioned at https://imapsync.lamiral.info/#install
541 the INSTALL file can also be found at
542 https://imapsync.lamiral.info/INSTALL.d/INSTALL.ANY.txt
543 It is now split in several files for each system
544 https://imapsync.lamiral.info/INSTALL.d/
545
547 There is no specific configuration file for imapsync, everything is
548 specified by the command line parameters and the default behavior.
549
551 Feel free to hack imapsync as the NOLIMIT license permits it.
552
554 See also https://imapsync.lamiral.info/S/external.shtml
555 for a better up to date list.
556
557 imap_tools : https://github.com/andrewnimmo/rick-sanders-imap-tools
558 offlineimap : https://github.com/nicolas33/offlineimap
559 Doveadm-Sync : http://wiki2.dovecot.org/Tools/Doveadm/Sync
560 ( Dovecot sync tool )
561 mbsync : http://isync.sourceforge.net/
562 mailsync : http://mailsync.sourceforge.net/
563 mailutil : http://www.washington.edu/imap/
564 part of the UW IMAP tookit.
565 imaprepl : http://www.bl0rg.net/software/
566 http://freecode.com/projects/imap-repl/
567 imapcopy : http://www.ardiehl.de/imapcopy/
568 migrationtool : http://sourceforge.net/projects/migrationtool/
569 imapmigrate : http://sourceforge.net/projects/cyrus-utils/
570 wonko_imapsync: http://wonko.com/article/554
571 see also file W/tools/wonko_ruby_imapsync
572 exchange-away : http://exchange-away.sourceforge.net/
573 pop2imap : http://www.linux-france.org/prj/pop2imap/
574
575 Feedback (good or bad) will often be welcome.
576
578 I wrote imapsync because an enterprise (basystemes) paid me to install
579 a new imap server without losing huge old mailboxes located in a far
580 away remote imap server, accessible by a low-bandwidth often broken
581 link. The tool imapcp (written in python) could not help me because I
582 had to verify every mailbox was well transferred, and then delete it
583 after a good transfer. Imapsync started its life as a patch of the
584 copy_folder.pl script. The script copy_folder.pl comes from the
585 Mail-IMAPClient-2.1.3 perl module tarball source (more precisely in the
586 examples/ directory of the Mail-IMAPClient tarball). So many happened
587 since then that I wonder if it remains any lines of the original
588 copy_folder.pl in imapsync source code.
589
590
591
592perl v5.22.1 2018-05-05 IMAPSYNC(1)