#!/bin/cat
# $Id: FAQ,v 1.209 2015/05/09 20:53:23 gilles Exp gilles $

+-------------------+
| FAQs for imapsync |
+-------------------+

http://imapsync.lamiral.info/FAQ
http://imapsync.lamiral.info/FAQ.d/

Unix versus Windows syntax.
There are several differences between Unix and Windows
in the command line syntax. 
- Character \ versus ^
- Character ' versus "


A) \ versus ^

On Unix shells you can write a single command on multiple lines
by using the escape character \ at the end of each line 
(except the last one). On Windows this character is ^

Unix example:

./imapsync \
   --host1 imap.truc.org --user1 foo --password1 secret1 \
   --host2 imap.trac.org --user2 bar --password2 secret2


Windows example:

imapsync ^
   --host1 imap.truc.org --user1 foo --password1 secret1 ^
   --host2 imap.trac.org --user2 bar --password2 secret2


Of course you can write the command on one only line without 
characters \ nor ^. I use them because the output is
better, no truncation, pretty print. It's just sugar.

In this FAQ I use \ for examples. Transcript to ^ if
you're on a Windows system.

B) ' versus " 

On Windows the single quote character ' doesn't work
like on Unix so in the examples of this FAQ the 
command containing single quotes ' will fail on Windows.
To fix it just replace single quotes ' by double quotes "

Also on Windows, in examples with \$1 replace 
any \$1 by $1 (remove the \ before $).

=======================================================================
Q. How to verify imapsync.exe I got is the right file bit per bit?

R. Use md5sum to check integrity of the file.
   Get md5sum.exe at http://etree.org/md5com.html

   md5sum imapsync.exe

   Then compare the checksum with the one given by the author.

=======================================================================
Q. How to install imapsync?

R. Read the INSTALL file in the tarball also available at
   http://imapsync.lamiral.info/INSTALL

=======================================================================
Q. How to configure and run imapsync?

R. Read the README and FAQ files in the tarball also available at 
   http://imapsync.lamiral.info/README
   http://imapsync.lamiral.info/FAQ

=======================================================================
Q. Can you give some configuration examples?

R. The FAQ file contains many examples for several scenarios
   http://imapsync.lamiral.info/FAQ

=======================================================================
Q. How can I have commercial support?

R. Buy support from imapsync author and expert: Gilles LAMIRAL
http://imapsync.lamiral.info/#buy_all

=======================================================================
Q. How can I have gratis support?

R. Use the mailing-list

To write on the mailing-list, the address is:
<imapsync@linux-france.org>

To subscribe, send a message to:
<imapsync-subscribe@listes.linux-france.org>

To unsubscribe, send a message to:
<imapsync-unsubscribe@listes.linux-france.org>

To contact the person in charge for the list:
<imapsync-request@listes.linux-france.org>

The list archives may be available at:
http://www.linux-france.org/prj/imapsync_list/
So consider that the list is public, anyone
can see your post. Use a pseudonym or do not
post to this list if you want to stay private.

Thank you for your participation.

=======================================================================
Q. Can I copy or sync Calendar or Contacts with imapsync?

R. No. It's because most IMAP servers don't get contacts and calendar 
events via IMAP. In other words, messages synced by imapsync from 
Calendar or Contacts folders are not used by email servers to set 
or get the contacts or calendars. 
No way via IMAP, no way via imapsync.
See next question.

=======================================================================
Q. How can I copy or synchronize Calendars or Contacts?

R1. It can't be done with imapsync.

R2. It can be done, depending on the email server softwares used.

a) From Exchange to Exchange, export contacts and calendar to
   PST format files on host1 and import them on host2.

b) From Gmail to Gmail, export and import calendars in ical format, 
   extension for those files is .ics.
   Contacts can be copied using a csv file. See the help page
   http://support.google.com/mail/bin/topic.py?hl=en&topic=1669027

c) Etc. Search the web. There's also specific tools and paid services.
   There's no silver bullet to migrate Calendars and Contacts,
   if you find one, tell me!


=======================================================================
Q. Where I can find old imapsync releases?

R. Search the Internet.

=======================================================================
Q. Where I can find free open and gratis imapsync releases?

R. Search the Internet.

Q. Is is legal to find imapsync gratis (or not) elsewhere?

R. Yes, the license permits it
   http://imapsync.lamiral.info/NOLIMIT

=======================================================================
Q. How "Facts and figures" are known on http://imapsync.lamiral.info/

R. To know wether a newer imapsync exists or not imapsync does a http 
   GET to http://imapsync.lamiral.info/VERSION
   Via the User-agent parameter it also send:

    * imapsync release
    * Perl version
    * Mail::IMAPClient version
    * Operating System

You can remove this behavior by adding option --noreleasecheck on the
command line (or by setting $releasecheck = 0 in the source code) 

=======================================================================
Q. I use --useuid which uses a cache in /tmp or --tmpdir, the hostnames
   host1 or host2 has changed but mailboxes are the same. Will imapsync
   generate duplicate messages on next runs?

R. Yes

Q. How can I fix this?

R. The cache path reflects exactly hostnames or ip addresses given via
   --host1 and --host2 values. So just change the directory names 
   of host1 or host2. Use --dry to see if next runs will generate 
   duplicates.
   By default on Unix the cache is like 

   /tmp/imapsync_cache/host1/user1/host2/user2/...

=======================================================================
Q. How can I speed up transfers?

R. By using --useuid imapsync avoid getting messages headers and build
   a cache. On Unix a good thing is to add also --tmpdir /var/tmp
   to keep the cache since /tmp is often cleared on reboot.

   imapsync ... --useuid 

On Unix:

   imapsync ... --useuid --tmpdir /var/tmp/

R. Add also --nofoldersizes since the default behavior is to compute
   folder sizes. Folder sizes are useless for the transfer, just 
   useful to see what has to be done on each folder and guess when 
   the transfer will end (ETA).

R. Add also --noexpungeaftereach if you use --delete. 
   But be warn that an interrupted transfer can loose messages 
   on host2 in a second run if you use a (silly) combination like

   imapsync ... --delete --noexpunge --noexpungeaftereach --expunge2

R. Add also --nocheckmessageexists
   --nocheckmessageexists is on by default since release 1.520.
   Since transfer can be long on a huge mailbox imapsync checks
   a message exist before copying it, but it takes time and 
   cpu on the host1 server. 


Notes about --useuid

Case where building the cache first is necessary (to avoid multiples transfers)

If you run again imapsync with --useuid on a transfer  already done without 
--useuid then, to avoid messages be copied again, first run imapsync 
with --usecache but without --useuid, example scenario:

A] Running with the default options, I began without --useuid 

1) First run with default options

  imapsync ...

Too slow, I want to speed up!

2) Build the cache

 imapsync ... --usecache

3) Speed up now

  imapsync ... --useuid

B] I began with --useuid from the first time

1) First run and next runs with --useuid

  imapsync ... --useuid


Inodes number issue.

The cache is simple, it uses the file-system natively, 
it's just an empty file per message transfered.
When mailboxes are huge the cache can exhaust the number of inodes 
allowed in the filesystem, that's a limitation like limitation
size but it's less often encountered.

On Unix, to predict whether your tmpdir filesystem used by imapsync 
will support the whole cache, just run the command "df -i /var/tmp", 
if /var/tmp is the --tmpdir argument.

On windows, search and drop me a note about how to count the number 
of files allowed in the filesystem. 
It seems FAT32 supports 268 435 445 clusters.

Choosing the number of inodes allowed by a filesystem can be done 
at the creation of it with "mkfs -N number-of-inodes ..."

imapsync can predict how many messages have to be synced with the 
option --justfoldersizes (no transfer will be done)

  imapsync ... --justfoldersizes


=======================================================================
Q. I see warning messages like 
"Host1 Sent/15 size 1428 ignored (no header so we ignore this message)"
What can I do to transfer those messages?

R1. Use --addheader option, it will add a header like
   "Message-Id: <15@imapsync>" and transfer the message on host2.
   Duplicates won't happen in next runs.

   imapsync ... --addheader

R2. Use --useuid then imapsync will avoid dealing with headers.

   imapsync ... --useuid

=======================================================================
Q. On Windows, with --useuid or --usecache a problem occurs with long
   nested folder names. The error message is:
   "No such file or directory; The filename or extension is too long"

R. This comes from a Windows limitation on pathnames.
No more than 260 characters are allowed for pathnames.
See more details on page
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx#maxpath
The workaround solution given at the previous link, 
ie using \\?\D:", does not work for imapsync. 
So this imapsync Windows bug is still pending and needs a fix using 
a different technic to cache, like a database file for example.

A solution to fix the issue is to use a Linux virtual host on a 
Windows box, with VirtualBox or VmWare etc. There is no bug this way,
pathnames can be several thousands charaters long.
Better said that done but not so difficult nor expensive these days,
VirtualBox is free and VmWare Player is free for personal or test use.

If you have to stick on Windows, there are two good workarounds 
to reduce the cache directory name:

1) Use --tmpdir "D:\\temp" or simply --tmpdir "D:" and imapsync
will build and use the cache in the sub directory 
D:\imapsync_cache\

2) add two equivalent entries in the etc/hosts for host1 imap.truc.org 
and host2 imap.trac.org. 
If you map the ip of imap.truc.org just with the letter a 
and same thing for imap.trac.org then you gain characters

etc/hosts

192.168.12.1 a
192.168.55.3 b

Then use:

  imapsync --host1 a --host2 b ...

You can get the ip of a host with the ping command line
C:\> ping imap.truc.org

Fixing the long path problem directly in imapsync is in the TODO file.

=======================================================================
Q. How can I try imapsync with latest Mail::IMAPClient 3.xx perl module?

Three solutions at least.

R1 - Look at the script named "i3" in the tarball, it can be used to
     run imapsync with the included Mail-IMAPClient-3.35/ wherever you 
     unpacked the imapsync tarball

R2 Run:

   perl -MCPAN -e "install Mail::IMAPClient"

   or

   cpan -i Mail::IMAPClient

R3 If you want to install the Perl module locally in a directory

   - Download latest Mail::IMAPClient 3.xx at
     http://search.cpan.org/dist/Mail-IMAPClient/

   - untar it anywhere:
        tar xzvf Mail-IMAPClient-3.xx.tar.gz

   - Get any imapsync (latest is better).

   - run imapsync with perl and -I option tailing to use the perl
     module Mail-IMAPClient-3.xx. Example:

         perl -I./Mail-IMAPClient-3.35/lib  ./imapsync ...

     or if imapsync is in directory /path/
        perl -I./Mail-IMAPClient-3.35/lib   /path/imapsync ...


=======================================================================
Q. How can I use imapsync with Mail::IMAPClient 2.2.9 perl module?

R. Mail::IMAPClient 2.2.9 is no longer supported.

=======================================================================
Q. I get "Out of memory" errors. How to fix that?

R. Usually "Out of memory" errors are related to old days,
to old Mail::IMAPClient module releases, before 3.26.
Look at imapsync output first lines to get the Mail::IMAPClient release used.
Then upgrade Mail::IMAPClient Perl module if needed.

=======================================================================
Q. Can I use imapsync to migrate emails from pop3 server to imap server?

R1. No. 
You can migrate emails from pop server to imap server with pop2imap:
http://www.linux-france.org/prj/pop2imap/

R2. Yes 
Many pop3 servers runs in parallel with an imap server on exactly 
the same mailboxes. They serve the same INBOX
(imap serves INBOX and several other folders, pop3 serves only INBOX)
So have a try with imapsync on the same host1.

=======================================================================
Q. Folders are not created on host2. What happens?

R. Do you use IMAP or POP3 with your client software?
It looks like you use POP3 instead of IMAP, POP3 sees only INBOX.


=======================================================================
Q. I am interested in creating  a local clone of the IMAP on a LAN 
server for  faster synchronizations, email will always be delivered 
to the remote server and so the synchronization will be one way - from 
remote to local. How suited is imapsync for continuous one-way 
synchronization of mailboxes? Is there a better solution?

R. If messages are delivered remotely and you play locally with the
copy, in order to have fast access, then the synchronization can't
be one way. You may change flags, you may move messages in 
different folders etc. The issue described is clearly 
two-ways sync.

A better tool with this scenario is offlineimap, 
designed for this issue, and faster than imapsync.

=======================================================================
Q. We have found that the time and date displayed have been changed to 
   the time at which the file was synchronized. 

R. This is the case by default with some email readers like:
   - Outlook 2003
   - Ipad

but not with:

   - Mutt
   - Thunderbird
   - Zimbra
   - Gmail


A thing to keep in mind, imapsync does not touch any byte of messages 
unless told to do so by option --regexmess. 
Messages on both parts should be identical.

I explain the whole picture about dates of messages.

There are several different dates for any message.
First, there is the "Date:" header. Most of the time, this date is set 
by the MUA. MUA means Mail User Agent; it is Outlook, Mutt
or Thunderbird. The Date header is usually the date the message was written 
or sent the first time. It is never changed by any transfer or copy.
If an email reader uses the Date header for displaying the date of a 
message then no problem should arise.

There is also the internal date. In IMAP the internal date is handled
and normally it corresponds to the arrival date in the mailbox. The 
IMAP protocol allows the internal date to be set by a email client.
Imapsync synchronizes internal dates by default, internal dates on host2
should then be the same as the internal dates on host1. 
If an email reader uses the internal date for displaying the date of a 
message then the sync date problem only occurs when the host2 server software
ignores the internal date given by imapsync during the APPEND imap 
command. It happens with some imap servers.

There are also the Received header lines. Each time a message travels
a SMTP server, this one adds a Received header line. Sometimes 
some email clients use the last "Received" header date as the date of the
message. And some IMAP servers softwares add a Received line after
and imap transfer. If those both conditions are met then the date
displayed become the transfer date even if imapsync 
has done its best to keep all the dates synchronized. Bad luck.



Solutions: 
a) Use a better email client or configure it in order it sorts messages
by sent date, the Date header.

b) Use a imap server that respects the imap RFC and accepts 
the internal date set by imapsync. 

c) Try to understand why the reader shows another date. 
For Exchange look at the next FAQ item.



=======================================================================
Q. imapsync calculates 479 messages in a folder but only transfers 400 
   messages. What's happen?

R1. Unless --useuid is used, imapsync considers a header part 
   of a message to identify a message on both sides.
   By default the header part used is lines "Message-Id:" "Message-ID:" 
   and "Received:" or specific lines depending on --useheader 
   --skipheader. Whole header can be set by --useheader ALL

Consequences:

  1) Duplicate messages (identical header) are not transferred
     several times.

The result is that you can have more messages on host1 than on host2.

R2. With option --useuid imapsync doesn't use headers to identify
messages on both sides but it uses their imap uid. In that case
duplicates on host1 are transferred on host2.

=======================================================================
Q. I need to log every output on a file named log.txt

R1. imapsync logs on a file by default, its name is given at the 
    beginning and the end of each run. This name is unique since
    it is compound of the current date and time and user2 value. 

R2. To change this default name, use --logfile log.txt

  imapsync ... --logfile log.txt


=======================================================================
Q. I need to log every output on a file named log.txt and also to the 
   screen in order to keep seeing what's going on during execution

R. Use the tee program (also available on Windows)
http://en.wikipedia.org/wiki/Tee_%28command%29
http://stackoverflow.com/questions/796476/displaying-windows-command-prompt-output-and-redirecting-it-to-a-file
http://code.google.com/p/wintee/


  imapsync ...  2>&1 | tee log.txt

=======================================================================
Q. Can I run more instances of imapsync in parallel on a Windows host.

R. Yes!

Q. Any performance issue?

You have to try and check the transfer rates, sum them up to
have a uniq numeric criteria. 
There is always a limit, depending on remote imap servers 
and the one running imapsync;
CPU, memory, Inputs/Outputs are the classical bottlenecks, 
the worst bottleneck is the winner that sets the limit.

examples/sync_loop_windows.bat says
...
REM ==== Parallel executions ====
REM If you want to do parallel runs of imapsync then this current script is a good start.
REM Just copy it several times and replace, on each copy, the csvfile variable value.
REM Instead of SET csvfile=file.txt write for example
REM SET csvfile=file01.txt in the first copy
REM then also 
REM SET csvfile=file02.txt in the second copy etc.
REM Of course you also have to split the data contained in file.txt
REM into file01.txt file02.txt etc.
REM After that, just double-click on each batch file to launch each process


=======================================================================
Q.  I run multiple imapsync applications at the same time then get a
    warning "imapsync.pid already exists, overwriting it".
    Is this a potential problem when trying to sync multiple 
    IMAP account in parallel?

R1. No issue with the file imapsync.pid if you don't use its content
by yourself. 

This file can help you to manage multiple runs by sending signals 
to the processes (sigterm or sigkill) using their PID.
Each run can have its own pid file with --pidfile option.
The file imapsync.pid contains the PID of the imapsync process.
This file is removed at the end of a normal run.
You can safely ignore the warning if you don't use imapsync.pid file.


=======================================================================
Q. Couldn't create [INBOX.Ops/foo/bar]: NO Invalid mailbox name: 
INBOX.Ops/foo/bar 

Let begin by an explanation.

Example:
sep1 = /
sep2 = .

imapsync reverts each separator automatically. 

a) All / character coming from host1 are converted to . (convert the separator)
b) All . character coming from host1 are converted to / (to avoid 
intermediate unwanted folder creation). 

So 
INBOX/Ops.foo.bar (Ops.foo.bar is just one folder name) will be translated to 
INBOX.Ops/foo/bar 

Sometimes the sep1 character is not valid on host2 (character "/" usually)

R. Try :

  --regextrans2 "s,/,X,g"

It'll convert / character to X 
Choose X as you wish: _ or SEP or 
any string (including the empty string).

This issue is automatically fixed by default since imapsync 
release 1.513, use --nofixslash2 to suppress the fix.

=======================================================================
Q. Is it possible to sync also the UIDL of the POP3 server?

R. imapsync does not POP3 but I think you mean UID in IMAP.
   See next question.

=======================================================================
Q. Is it possible to sync also the UIDs of the IMAP server?

UIDs in IMAP are chosen and created by the servers, not by the clients,
imapsync is a client. So UIDs cannot be synced by any imap method.
UIDs might be synced via a rsync command on the server part.

=======================================================================
Q. The option --subscribe does not seem to work

R1. Use it with --subscribed

R2. There is also the --subscribe_all option that subscribe
to all folders on host2.

=======================================================================
Q. Is there a way we can specify a date range to sync emails? 
   If yes, can you please share an example?

R. Yes, with the --search option.

  imapsync ... --search "SENTSINCE 1-Jan-2010 SENTBEFORE 31-Dec-2010"

   Jan
   Feb
   Mar
   Apr
   May 
   Jun
   Jul 
   Aug
   Sep
   Oct 
   Nov
   Dec

=======================================================================
Q. Is there a way we can specify an age to sync emails? 
   If yes, can you please share some examples?

R. Yes, with the --maxage or the --minage option.

E.1 Sync only messages less than 2 days old:

  imapsync ... --maxage 2

E.2 Sync only messages more than 2 days old:

  imapsync ... --minage 2

E.3 Sync only messages more than 30 days old and less than 365 days old:

  imapsync ... --minage 30 --maxage 365

E.4 Sync only messages less than 30 days old or more than 365 days old:

  imapsync ... --maxage 30 --minage 365

Full explanation:

--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)


=======================================================================
Q. On Unix, some passwords contain * and " characters. Login fails.
R. Use a backslash to escape the characters:

    imapsync ... --password1 \"password\" 

It works for the star * character,
I don't know if it works for the " character.

=======================================================================
Q. On Windows, some passwords contain $ characters. Login fails.
R1. Enclose passwords between ""

    imapsync ... --password1 "zzz$zz$$z"

R2. Prefix each $ character with a ^ since ^ is the escape character
    on Windows

    imapsync ... --password1 zzz^$zz^$^$z

For a password that is exactly the 8 characters string $%&<>|^"
you have to enter

    imapsync ... --password1 "$%%&<>|^"^"

=======================================================================
Q. On Windows, some passwords begin with an equal = character. 
   Login fails. What can I do?

R. Use twice equals == characters instead; For example, if =secret 
   is the password then use:

    imapsync ... --password1 ==secret

or even

    imapsync ... --password1 "==secret"

=======================================================================
Q. With huge account (many messages) when it comes to reading the
destination server it comes out this error:
"To   Folder [INBOX.foobar] Not connected" 
What can I do?

R. May be spending too much time on the source server, the connection 
timed out on the destination server.
Try options --nofoldersizes 

=======================================================================
Q. Does imapsync support IMAP TLS?

R. Use --tls1 and/or --tls2 options

--tls1 tells imapsync to use tls on host1.
--tls2 tells imapsync to use tls on host2.


=======================================================================
Q. Does imapsync support IMAP over SSL (IMAPS)?

R. Yes natively since release 1.161. 
still, 2 ways, at least :

a) Use native --ssl1 and/or --ssl2 options

--ssl1 tells imapsync to use ssl on host1.
--ssl2 tells imapsync to use ssl on host2.


b) Use stunnel
   http://www.stunnel.org/
   Assuming there is an imaps (993) server on imap.foo.org,
   on your localhost machine (or bar machine) run :
       stunnel -c -d imap -r imap.foo.org:imaps
   or using names instead of numbers 
       stunnel -c -d 143 -r imap.foo.org:993
   then use imapsync on localhost (or bar machine) imap (143) port.
   If the local port 143 is already taken then use a free one, 10143.

c) Other example for gmail with no root access to open port 143

   stunnel -f -P '' -c -d 9993 -r imap.gmail.com:993

Then, to access gmail as host2 use:

  imapsync ... --host2 localhost --port2 9993 --nossl2 

=======================================================================
Q. How can I manually test a login via ssl?

R. Use ncat or telnet-ssl like in this example:

ncat --ssl -C  imap.gmail.com 993
* OK Gimap ready for requests from 78.196.254.58 q1mb175739668wix
a LOGIN "gilles.lamiral@gmail.com" "secret" 
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ... ESEARCH
a OK gilles.lamiral@gmail.com Gilles Lamiral authenticated (Success)
b LOGOUT
* BYE LOGOUT Requested
b OK 73 good day (Success)

The client part to type is "a LOGIN ..." and "b LOGOUT" without
the double-quotes. 


=======================================================================
Q: How to have an imaps server?

R. 
a) Install one 

b) or use stunnel :
   Assuming there is an imap (143) server on localhost
        stunnel  -d 993 -r 143 -f

c) or use stunnel on inetd
   imaps stream  tcp nowait cyrus /usr/sbin/stunnel -s cyrus -p /etc/ssl/certs/imapd.pem -r localhost:imap2

======================================================================
Q. I am transferring mails from one IMAP server to another. I am using
   an SSL connection. Transferring huge mails (>10MB) takes ages.

R. try to transfer the mails without SSL connection. SSL code outside
   imapsync uses a memory buffer, which gets increased upon reading of
   mails by 4096 bytes. This creates a huge load on the host imapsync
   runs on by copying the memory buffers for every 4096 byte step.
   This does not occur without SSL.

(Written by Stefan Schmidt)

======================================================================
Q. What are --subscribe and --subscribed for, and how can they be used?

R. In the IMAP protocol each user can subscribe to one or more folders.
   Then he can configure its email software to just see his subscribed
   folders list. That's an IMAP feature.

   Knowing that, the imapsync help says:

  imapsync --help
  ...
  --subscribed           : transfers subscribed folders.
  --subscribe            : subscribe to the folders transferred on the 
                           host2 that are subscribed on host1.
  --subscribe_all        : subscribe to the folders transferred on the 
                           host2 even if they are not subscribed on host1.


======================================================================
Q. I want to exclude a folder hierarchy like "public"

R. Use:

--exclude "^public\."
or maybe
--exclude '^"public\.'

In the example given the character "." is the folder separator, you
can omit it. Just take the string as it appears on the imapsync
output line :

From folders list : [INBOX] [public.dreams] [etc.]


======================================================================
Q. I want to exclude only INBOX

R. Use:

  imapsync ... --exclude "^INBOX$" 

A good way to see what will be done is to first use:

  imapsync ...  --exclude "^INBOX$" --justfolders --nofoldersizes --dry


======================================================================
Q. Can Imapsync filter Spam during the sync?

R. No, imapsync doesn't detect Spam by itself and currently it can't
delegate this job during its IMAP syncs. But I've seen blogs and
Spamassassin documentation explaining solutions to apply Spamassassin
to a imap mailbox. So you can apply one of these solutions on the host1
source mailbox before the imapsync run or on the destination host2
mailbox after the imapsync transfer.

http://www.stearns.org/doc/spamassassin-setup.current.html#isbg
http://euer.krebsco.de/using-spamassassin-on-a-remote-imap-host.html
https://github.com/ook/isbg

======================================================================
Q. I want to exclude folders matching SPAM no matter the case, 
   aka how to be case insensitive

R. Use:

  imapsync ... --exclude "(?i)spam" 

A good way to see what will be done is to first use:

  imapsync ... --exclude "(?i)spam" --justfolders --nofoldersizes --dry


======================================================================
Q. I want the --folder "MyFolder" option be recursive.

Two solutions:

R1. Use

--folderrec "MyFolder"

R2. Use --include "^MyFolder"
   Then the folder "MyFolder" and all its subfolders will be handled
   and only them.


======================================================================
Q. How to migrate from uw-imap with an admin/authuser account?

R. Use the following syntax:

  imapsync ... --user1="loginuser*admin_user" --password1 "admin_user_password"


======================================================================
Q. How to migrate to Dovecot with an admin/MasterUser account?

R. Dovecot uses the same syntax as uw-imap

  imapsync ... --user2="loginuser*admin_user" --password2 "admin_user_password"

To setup a Dovecot MasterUser see 
http://wiki2.dovecot.org/Authentication/MasterUsers

======================================================================
Q. How to migrate from cyrus with an admin account?

R. Use:
 
 imapsync ... \
   --authuser1 admin_user  ----password1 admin_user_password \
   --user1 foo_user --ssl1

Instead of --ssl1 the alternative --tls1 can be used.
With --authuser1, the option --authmech1 PLAIN is set
automatically, you don't have to add it.

PLAIN authentication is the only way to go with --authuser1 for now.
So don't use --authmech1 SOMETHING with --authuser1 admin_user,
it will not work.
Same behavior with the --authuser2 option.

Do not forget the option --ssl1 or --tls1 since PLAIN auth is only
supported with ssl encryption most of the time. But it can
work without --ssl1 nor --tls1 if PLAIN is permitted in clear text
transmissions (the normal mode).

Add the AdminAccount to admins line in /etc/imapd.conf
Give AdminAccount lrswipkxtecda to the Cyrus Imap account 
being migrated from, "joe" here.


Here is an example:
 imapsync \
	--host1 server1 \
	--user1 joe \
	--authuser1 AdminAccount \
	--password1 AdminAccountPassword \
	--ssl1 \
	--host2 server2 \
	--user2 joe \
	--password2 joespassonserver2 \
	--exclude "^user\."

======================================================================
Q: How to migrate from Sun Java Enterprise System / Sun One / iPlanet /
Netscape servers with an admin account?

R: Those imap servers don't allow the typical use of --authuser1 to use an
administrative account. They expect the use of an IMAP command called
proxyauth that is issued after login in as an administrative account.

For example, consider the administrative account 'administrator' and your
real user 'real_user'. The IMAP sequence would be:

  OK [CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ NAMESPACE UIDPLUS
  CHILDREN BINARY UNSELECT LANGUAGE STARTTLS XSENDER X-NETSCAPE XSERVERINFO
  AUTH=PLAIN] imap.server IMAP4 service (Sun Java(tm) System Messaging
  Server ...))
  1 LOGIN administrator password
  1 OK User logged in
  2 PROXYAUTH real_user
  2 OK Completed

In imapsync, you can achieve this by using the following options:

  --host1 source.imap.server \
  --user1 real_user \
  --authuser1 administrator \
  --proxyauth1 \
  --passfile admin.txt

======================================================================
Q. Is there anyway of making imapsync purge the destination folder
   when the source folder is deleted?

R. Yes, use --delete2folders

--delete2folders       : Delete folders in host2 that are not in host1 server. 
                         For safety, first try it like this (it is safe):
			 --delete2folders --dry --justfolders --nofoldersizes
--delete2foldersonly   <regex>: Deleted only folders matching regex.
                         Example: --delete2foldersonly "/^Junk$|^INBOX.Junk$/"
--delete2foldersbutnot <regex>: Do not delete folders matching regex.
                         Example: --delete2foldersbutnot "/Tasks$|Contacts$|Foo$/"


=======================================================================
Q. I want to play with headers line and --regexmess but I want to leave
   the body as is.

R. The header/body separation is a blank line so an example:
   --regexmess 's{\A(.*?(?! ^$))^Date:(.*?)$}{$1Date:$2\nX-Date:$2}gxms'

Will replace (HeaderBegin and HeaderEnd are not part of the header)

HeaderBegin
Message-ID: <499EF800.4030002@blabla.fr>
Date: Fri, 20 Feb 2009 19:35:44 +0100
From: Gilles LAMIRAL <lamiral@linux-france.org>
HeaderEnd

by

HeaderBegin
Message-ID: <499EF800.4030002@blabla.fr>
Date: Fri, 20 Feb 2009 19:35:44 +0100
X-Date: Fri, 20 Feb 2009 19:35:44 +0100
From: Gilles LAMIRAL <lamiral@linux-france.org>
HeaderEnd

This example just add an header line "X-Date:" based on "Date:" line.

=======================================================================
Q. My imap server does not accept a message and warns
   "Invalid header". What is the problem?

R. You fall in the classical mbox versus Maildir/ format
   problem. May be you use a misconfigured procmail rule.

A header beginning like the following one is in the mbox
format, header line 1 has no colon behind "From", header
lines 2 through N do have a colon :

From foo@yoyo.org  Sat Jun 22 01:10:21 2002
Return-Path: <foo@yoyo.org>
Received: ...

Any Maildir/ configured imap server may refuse this message since its
header is invalid. The first "From " line is not valid. It lacks a
colon character ":". To solve this issue you have several solutions

a) Remove manually this first "From " line for each message before
   using imapsync. 

b) Replace manually the whitespace by a colon in string "From " but you
   might end with two "From:" lines (just have a look at the other 
   header lines of the message)

c) Run imapsync with the following option (this replaces "From "by "From:"):
   --regexmess 's/\AFrom /From:/'

or may be better (no other "From:" collision):

d) Run imapsync with the following option (this replaces "From "by "X-om:"):
   --regexmess 's/\AFrom /X-om:/'

e) Run imapsync with the following option (this removes the whole "From " line):
   --regexmess 's{\AFrom\ [^\n]*(\n)?}{}gxms'

Solution e) is solution a) made by imapsync itself.
Solutions c) and d) keep "From " lines information
(normally it's useless to keep them)

Best solutions are e) or d).

=======================================================================
Q. The contact folder isn't well copied. 
   How to copy the contact folder?

R. Forget the destination server (choose the same)
Change the script around line 1426
       # ITSD
       $new_id = $from->copy($t_fold,$f_msg);
       #$new_id = $to->append_string($t_fold,$string, $flags_f, $d);

and tried a copy of the mail instead an append_string. Because we are
using the same server, we can use $from->copy Therefore we seem to not
download and upload the message and therefore we do not have any
format issues. And now it works fine. (Thanks to Hansjoerg.Maurer)

=======================================================================
              Server specific issues and solutions
=======================================================================

=======================================================================
Q. From Zimbra to XXX

imapsync ... \
	--exclude "Conversation Action Settings" \
	--exclude "Quick Step Settings" \
	--exclude "News Feed"

=======================================================================
Q. From or to HMailServer version 4.4.1.

R. You have to add prefix and separator manually because  4.4.1 doesn't
honor the NAMESPACE imap command.

Example for host1:

imapsync ... \
         --prefix1 "" --sep1 .

No specific option for HMailServer 5.3.3 since NAMESPACE is supported.

Maybe --subscribe_all will help you to see all migrated folders.


=======================================================================
Q. Synchronizing from Kerio Connect to XXX

R. No special options required. 
See also:
http://www.linux-france.org/prj/imapsync_list/msg01756.html
http://www.safetynet-it.com/it-support/mac-kerio-server-to-microsoft-exchange-2010-migration-1/
http://www.safetynet-it.com/it-support/mac-kerio-server-to-microsoft-exchange-2010-migration-2/


=======================================================================
Q. Synchronizing from SmarterMail to XXX

imapsync --host1 imap.d1.org --user1 joe --password1 secret1 --sep1 "/" \
         --host2 imap.d2.org --user2 joe --password2 secret2  \
         --prefix1 ""  \
         --regextrans2 "s#Sent Items$#Sent#" \
         --dry --justfolders

Maybe add other --regextrans2 to change folder names and see the result.
When satisfied, run without --dry --justfolders


=======================================================================
Q. Synchronizing from Yahoo to XXX

R. Use --host1 imap.mail.yahoo.com --sep1 '/'

./imapsync \
	--host1 imap.mail.yahoo.com \
        --user1 billy \
        --password1 secret \
        --host2 XXX \
        --user2 billy \
        --password2 secret \
        --sep1 '/'

Can also add --ssl1 to gain encrypted transfer from yahoo.
SSL seems to be mandatory for yahoo (since november 2011)

=======================================================================
Q. from Microsoft's Exchange 2007 to Google Apps for your Domain 
   (GAFYD)

R. Take a look at:
http://mark.ossdl.de/2009/02/migrating-from-exchange-2007-to-google-apps-mail/

=======================================================================
Q. Syncing from Google Apps domain to Googlemail account

A known bug encountered with this output (Alexander is a folder name):

++++ Verifying [Alexander] -> [Alexander] ++++
+ NO msg #16 [A96Dh4AwlLVphOAW5MS/eQ:779824] in Alexander
+ Copying msg #16:779824 to folder Alexander
flags from : [\Seen]["04-Jul-2007 14:32:22 +0100"]
Couldn't append msg #16 (Subject:[Rieter-Event    (please accept with
comments)]) to folder Alexander: 46 NO Invalid folder: Sent (Failure)

In fact folder "Sent" is just the last folder listed previously
as a:
...
To   Folder [Sent]                             does not exist yet
To   Folder [Sonja]                             Size:   1024546 Messages:    96
...

R. Just run imapsync a time like this :
imapsync ... --folder Alexander

=======================================================================
Q. Migrating from or to Parallels Plex Server

R. It depends on the OS

Parallells Plesk Panel for Windows requires --sep2 / --prefix2 ""
Parallells Plesk Panel for Linux works with default parameters.

=======================================================================
Q. I'm migrating from WU to Cyrus, and the mail folders are under
   /home/user/mail but the tool copies everything in /home/user, how
   can i avoid that?

Two solutions:

R. Use
   imapsync ... --include '^mail'

R. or (better)
   imapsync ... --subscribed --subscribe


=======================================================================
Q. I'm migrating from WU to Cyrus, and the mail folders are under
   /home/user/mail directory.  When imapsync creates the folders in
   the new cyrus imap server, it makes a folder "mail" and below that
   folder puts all the mail folders the user have in /home/user/mail,
   i would like to have all those folders directly under INBOX.

R. Use 
   imapsync ... --regextrans2 's/^mail/INBOX/' --dry
   look at the simulation and if all transformations seem
   good then remove the --dry option.


=======================================================================
Q. Migrating from Groupwise to Cyrus

R. By Jamie Neil:

I eventually managed to get the mail to migrate without errors using the 
following options:

--sep1 /
  - doesn't report separator so has to be set explicitly.

--nosyncacls
  - doesn't support ACLs.

--skipheader '^Content-Type'
  - MIME separator IDs seem to change every time a mail is accessed so 
    this is required to stop duplicates.

--maxage 3650
  - some messages just don't seem to want to transfer and produce the 
    perl errors I mentioned before. This prevents the errors, but the
    bad messages don't transfer.

Even though the mail migrated OK, there are a couple of gotchas with 
Groupwise IMAP:

1) Some of the GW folders are not real folders and are not available
to IMAP, the main problem one being "Sent Items". I could find no way
of coping the contents of these folders. The nearest I got was to
create a "real" folder and copy/move the sent items into it, but
imapsync still didn't see the messages (I think because there is
something funny about the reported dates/sizes).

It think this problem has been rectified in GW6.5.

2) The "skipheader '^Content-Type'" directive is required to stop 
duplicate messages being created. GW seems to generate this field on
the fly for messages that have MIME separators and so it's different
every time.

3) Version 6.0.1 of the Groupwise Internet Connector sucks. I was 
getting server aborts when I pushed it a bit hard! I eventually had to
upgrade to 6.0.4 which seems to be a lot more stable.


=======================================================================
Q. Migrating from iPlanet Messaging Server
5.2 Patch 2 (built Jul 14 2004)) to Groupwise 7.0
I encounter many errors like this:
"Error trying to append string: 17847 BAD APPEND"

R. GroupWise 7 seems buggy. Apply GroupWise 7 support pack 1

=======================================================================
Q. Migrating from David Tobit V10 (DvISE Mail Access Server MA-...)

R. Use the following options:

imapsync ... --prefix1 ""    --sep1 /  --idatefromheader ^
             --nofoldersizes --useuid --nocheckmessageexists

=======================================================================
Q. Migrating from David Tobit V8
   ("* OK IMAP4rev1 DvISE Mail Access Server MA-8.10a (0126)")

First try above V10 solution since improvments have been made
to support Tobit.

R. Use the following options :
imapsync ... --prefix1 INBOX. --sep1 / --subscribe --subscribed 

=======================================================================
Q. Migrating from Tobit David Server 6 
   ("DvISE Mail Access Server MA-6.60a (0118)")

First try above V10 solution since improvments have been made
to support Tobit.

R. Look at the discussion:
http://www.linux-france.org/prj/imapsync_list/msg00582.html
http://www.linux-france.org/prj/imapsync_list/threads.html#00582
patch saved in ./patches/imapsync-1.337_tobit_V6.patch

=======================================================================
Q. I need to migrate 1250 mailboxes, passwords are in a MySQL Database.
Can you tell me if your script suits my needs?

R. Mailboxes must exist before running imapsync.
You have to extract users logins and passwords in a csv file.
See the "HUGE MIGRATION" section in the README file.


======================================================================
Q: From MailEnable 1.75
R: --sep1 "/" --prefix1 ""

Q: From MailEnable 2.2
R: --sep1 "." --prefix1 ""

Q: To MailEnable
R: --sep2 / --prefix2 "" --addheader --messageidnodomain --syncflagsaftercopy

======================================================================
Q. From GMX IMAP4 StreamProxy
R. Use:
   --prefix1 INBOX and --sep1 .

======================================================================
Q. From Courier to Archiveopteryx
R. You can read http://www.archiveopteryx.org/migration/imapsync
   Default values might be fine now with latest imapsync.

======================================================================
Q. To Sun Java(tm) System Messaging Server 6.2-7.05
Q. To Communigate Pro - Solaris version

R. See and run patches/imapsync_1.267_jari


======================================================================
Q. From Softalk Workgroup Mail 7.6.4 

R. Old Softalk releases don't support the IMAP SEARCH command.
   Here are the options to get it working.

imapsync ... --sep1 '.' --prefix1 '' \
             --noabletosearch  --nocheckmessageexists --addheader

(Thanks to Andrew Tucker)

======================================================================
Q. From or to QQMail IMAP4Server

R. imapsync ... --noabletosearch

======================================================================
Q. From FirstClass to XXX
   http://www.firstclass.com/

R. Migrating from FirstClass is not easy because FirstClass, strangely, 
   does not show all messages via IMAP. To make it show all messages,
   a trick, painful to follow by hand, is moving emails 
   out and back in, for each folder. May be it can be done by a script.

  FirstClass releases prior to release 12 do not shows the "Sent" 
  folder in IMAP but FirstClass release 12 shows it.
  I advice you to upgrade to FirstClass release 12 before leaving it
  with imapsync or another imap tool.

Here is a command line used to migrate from FirtClass release 12:

  imapsync ... \
    --tmpdir /var/tmp --usecache \
    --useheader Message-ID \
    --idatefromheader \
    --addheader \
    --regextrans2 "s,(/|^) +,\$1,g" --regextrans2 "s, +(/|$),\$1,g" \
    --regextrans2 "s/[\^]/_/g"       \
    --regextrans2 "s/['\"\\\\]/_/g"  \
    --regextrans2 "s,&AC8-,-,g" \
    --regextrans2 "s,&APg-,oe,g" 

On Windows, in the previous example containing \$1 you have to 
replace the two \$1 by $1 (remove the \ before $).

Special thanks to Kristian Wind and Joey Alexander for helping me
writing this FAQ item. 
See also this worth reading discussion in a Zimbra forum:
http://www.zimbra.com/forums/migration/20349-help-needed-migrating-firstclass.html

======================================================================
Q. From XXX to FTGate

R. Do NOT use --usecache since new UIDs are not given by FTGate and also
   badly guessed by imapsync. UIDEXPUNGE does not work so use also
   --expunge2 when using --delete2
  
  imapsync ... \
     --sep2 / --prefix2 "" \
     --useheader Message-Id \


======================================================================
Q: How can I write an .rpm with imapsync

R. You'll find an RPM imapsync.spec file in the directory learn/rpm/
   It has been downloaded from
   https://svn.fysik.dtu.dk/projects/rpmbuild/trunk/SPECS/imapsync.spec
   It has been tested with imapsync 1.434 (May 2011) on CentOS5 
   and RedHat RHEL5 Linux. (Thanks to Ole Holm Nielsen).
   This imapsync.spec is coming from Neil Brown work in 2007.

=======================================================================
Q. Where I can read up on the various IMAP RFCs?

R. Here:

RFC 3501 - INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1
http://www.faqs.org/rfcs/rfc3501.html

RFC2683 - IMAP4 Implementation Recommendations
http://www.faqs.org/rfcs/rfc2683.html

RFC 2595 - Using TLS with IMAP, POP3 and ACAP
http://www.faqs.org/rfcs/rfc2595.html

RFC 2822 - Internet Message Format
http://www.faqs.org/rfcs/rfc2822.html

RFC 2342 - IMAP4 Namespace
http://www.faqs.org/rfcs/rfc2342.html

RFC2180 - IMAP4 Multi-Accessed Mailbox Practice
http://www.faqs.org/rfcs/rfc2180.html

RFC 4549 - Synchronization Operations for Disconnected IMAP4 Clients
http://www.faqs.org/rfcs/rfc4549.html


