LinuxCommandLibrary

imapsync

Synchronize IMAP mailboxes

TLDR

Synchronize IMAP account between host1 and host2

$ imapsync --host1 [host1] --user1 [user1] --password1 [secret1] --host2 [host2] --user2 [user2] --password2 [secret2]
copy

SYNOPSIS

imapsync [options]

PARAMETERS

--host1 <host>
    Specifies the hostname or IP address of the source IMAP server.

--user1 <user>
    Sets the username for authentication on the source IMAP server.

--pass1 <password>
    Provides the password for the source IMAP server. Use with caution due to security implications; consider interactive input or passfile.

--host2 <host>
    Specifies the hostname or IP address of the destination IMAP server.

--user2 <user>
    Sets the username for authentication on the destination IMAP server.

--pass2 <password>
    Provides the password for the destination IMAP server. Use with caution.

--ssl1
    Enforces the use of SSL/TLS for the connection to the source IMAP server.

--ssl2
    Enforces the use of SSL/TLS for the connection to the destination IMAP server.

--port1 <port>
    Defines the port number for the source IMAP server (default: 143 or 993 for SSL).

--port2 <port>
    Defines the port number for the destination IMAP server (default: 143 or 993 for SSL).

--exclude <pattern>
    Excludes folders whose names match the given Perl regular expression pattern from synchronization.

--include <pattern>
    Includes only folders whose names match the given Perl regular expression pattern for synchronization, excluding all others.

--synckey <key>
    Specifies a unique key to resume a previously interrupted synchronization, ensuring continuity.

--delete
    Deletes messages on the destination server if they no longer exist on the source server. Use with extreme caution as this action is irreversible.

--dry
    Performs a dry run, simulating the synchronization process without making any actual changes to the mailboxes. Useful for testing and verification.

--noflags
    Prevents the synchronization of message flags (e.g., \Seen, \Answered, \Flagged) to the destination server.

--justfolders
    Synchronizes only the folder structure, without transferring any messages.

--skipsize
    Skips messages if they have the same size on both servers, assuming they are identical.

--useuid
    Forces imapsync to use UIDs (Unique Identifiers) instead of message sequence numbers for message identification, which is generally more robust.

--automap
    Attempts to automatically map common special folder names (e.g., 'INBOX.Sent' to 'Sent Items') between servers.

--debug
    Enables verbose debug output, providing detailed information about the synchronization process.

--version
    Displays the imapsync version information and exits.

--help
    Displays the imapsync usage instructions and a list of available options.

DESCRIPTION

imapsync is a powerful and versatile Perl script designed for robust synchronization and migration of mailboxes between two IMAP servers. It is widely utilized for transferring email accounts from one hosting provider to another, consolidating multiple accounts, or creating reliable backups of IMAP mailboxes. The tool meticulously preserves all aspects of the mailbox data, including message content, headers, flags (e.g., seen, answered, flagged, deleted), and the complete folder hierarchy. It operates by connecting to both a source and a destination IMAP server, systematically reading messages from the source, and then efficiently writing them to the destination. imapsync excels at managing large mailboxes and offers essential features such as resume capabilities, allowing transfers to pick up seamlessly after interruptions. Its extensive set of options also enables selective synchronization, such as excluding specific folders or messages based on criteria, making it a flexible and reliable choice for managing complex IMAP data transfers.

CAVEATS

imapsync requires Perl and several essential Perl modules to be installed on the system where it is executed. Users should be aware that specifying passwords directly on the command line using --pass1 and --pass2 can be a security risk, as they might be exposed in process lists or shell history. It is highly recommended to use environment variables, password files (e.g., --passfile1), or rely on interactive password prompts for enhanced security. The --delete option is irreversible and should be used with extreme caution, as it will permanently remove messages from the destination server that are not present on the source. Performance can vary significantly based on network latency, the capabilities of both IMAP servers, and the number and size of messages being transferred. It is strongly advised to perform thorough testing with the --dry run option before executing a full synchronization, especially for critical data.

SUPPORTED SERVERS

imapsync is designed to work with virtually any IMAP4rev1 compliant server. This includes popular services and platforms such as Gmail, Microsoft Exchange, Dovecot, Courier-IMAP, Zimbra, and many others, making it highly versatile for diverse environments.

SECURITY AND PASSWORD HANDLING

For improved security, instead of directly providing passwords via --pass1 <password> and --pass2 <password>, users can opt to specify password files using --passfile1 <file> and --passfile2 <file>. Alternatively, omitting the password options will prompt imapsync to request passwords interactively at runtime, preventing them from being exposed in shell history or process listings.

RESUME CAPABILITY

The --synckey option is a critical feature for resuming interrupted synchronizations. By providing a unique key, imapsync can intelligently pick up exactly where it left off, significantly saving time and bandwidth, especially when dealing with very large mailboxes or unreliable network connections.

HISTORY

imapsync was originally created by Gilles Lamiral and has been developed as an open-source Perl script over many years. It has evolved into a highly respected and widely adopted tool for IMAP mailbox transfers. Its ongoing development has prioritized reliability, performance, and the ability to gracefully handle the numerous intricacies of diverse IMAP server implementations. It gained significant popularity due to its capability to preserve all aspects of mailboxes, from message content and headers to complex flags and complete folder structures, making it a de-facto standard solution for system administrators and users engaged in critical email migrations or consolidations.

SEE ALSO

rsync(1), fetchmail(1), mbsync(1)

Copied to clipboard