Good practices for imapsync

Gilles LAMIRAL gilles@lamiral.info
% $Id: GOOD_PRACTICES.t2t,v 1.10 2019/11/25 12:50:54 gilles Exp gilles $



Good practices for imapsync

You are not supposed to have read the TUTORIAL documentation but reading it should help to understand and master the following best practices.

Simple transfer

By principle, imapsync does not change any single byte of messages, unless --regexmess or --addheader is used. Imapsync identifies messages with "Message-Id" and "Received" headers, so it ignores messages that lack those headers; most of the time it happens with the "Sent" folders.

A way to sync those messages is to add option --addheader. Before appending a message on host2, and only when needed, --addheader option adds a Message-Id header like "Message-Id: <123456789@imapsync>" where 123456789 is the host1 folder message UID. Messages on host1 stay untouched. This way, multiples runs will not generate duplicates as long as UIDs stay the same on host1, which is the case for most imap servers.

Unix:

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

Windows:

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

Exact backup

Assertions for this example:

Have in mind

Restore

Restoring is not the exact reverse of backupping since between a backup and a mistake, the context has changed, some things went wrong but not all, for examples new messages arrived. So synchronize an active account identical from a backup might not be the best idea.

The context can be a crash or equivalent like when a not friendly admin or service closed definitevely access to your messages. Even in that case an exact restore, with --delete2 --delete2folders, should not be ok, just because new messages arrive in INBOX all the time.

Presync

Presync is like a backup except deleting folders on host2 that are not on host1 is not always wanted. Presync means a new different imap server will host messages and folders. Often this new imap server has predefined folders that should be kept for proper use, so I suggest to not use option --delete2folders.

Unix:

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

Windows:

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