7

I am trying to synchronize two mailboxes which reside in different servers. This is due to a migration process. The old server is a courier server and needs to be accessed via IMAP, whereas the new server is a dovecot server. I am trying to follow the original Dovecot documentation. Unfortunately it is not specified where the configuration of the source IMAP needs to be set, when the doveadm script is run on the destination server. The documentation provides the settings, but does not mention which dovecot configuration file the settings have to be entered.

4 Answers 4

8

You can also do the following on the command-line without configuration files:

# doveadm -Dv  \
  -o imapc_host=<SOURCE_HOST> \
  -o imapc_user=<SOURCE_USERNAME> \
  -o imapc_password=<SOURCE_PASSWORD> \
  -o imapc_features=rfc822.size \
  -o imapc_ssl=starttls \
  -o mail_fsync=never \
   backup -R -u <DESTINATION_MAILBOX> imapc:

I had great problems, because my source IMAP only supports STARTTLS on port 143. -o imapc_ssl=starttls was a life-saver in my case.

You can make a sync after the initial backup with:

# doveadm -Dv \
  -o imapc_host=<SOURCE_HOST> \
  -o imapc_user=<SOURCE_USERNAME> \
  -o imapc_password=<SOURCE_PASSWORD> \
  -o imapc_features=rfc822.size \
  -o imapc_ssl=starttls \
  -o mail_fsync=never \
  sync -1 -R -u <DESTINATION_MAILBOX> imapc:

Of course, this is quite insecure if you have more users on the box that can see your commands (and passwords) with who or by looking into your .bash_history file, so beware.

4

If the two mail servers are running without problems with the IMAP protocol I would use imapsync to do the job. Both Courier and Dovecot are supported by imapsync.

It's really straightforward to use and support many features, like regexp mappings for different folder synchronisation.

The software is FOSS and can be found here: http://imapsync.lamiral.info

If you need the UID sync you can add the option --useuid in the imapsync. I'm not sure if you're talking about this kind of UID. But this is the option that you should be looking for:

--useuid : Use uid instead of header as a criterium to recognize messages. Option --usecache is then implied unless --nousecache is used.

5
  • Hi. Thanks for the hint. I have also considered using imapsync. But I have read ( wiki2.dovecot.org/Migration ) that it does not preserve the UID of the e-mails. If UIDs are not preserved, the IMAP clients which are already bound to the first server, when they are pointed to the new server, will not be able to sync with the local cache and have to download all (thousands) of messages from scratch. I would therefore like to stick to the original documentation, which is albeit a bit unclear
    – lefterav
    Jun 18, 2014 at 12:11
  • Sorry but I was unable to understand this. IMAPSync does not care about UID. It works on the IMAP layer, so the UID's are defined at your server by you at the account creation processes. Jun 18, 2014 at 16:09
  • 1
    Exactly. IMAPsync does not care about UIDs, but clients like Thunderbird do. It is clearly said here: wiki2.dovecot.org/Migration#IMAP_migration "When migrating mails from another IMAP server, you should make sure that these are preserved: If UIDs are lost, at the minimum clients' message cache gets cleaned and messages are re-downloaded as new. Some IMAP clients store metadata by assigning it to specific UID, if UIDs are changed these will be lost.". The solution is to use doveadm but I don't understand how.
    – lefterav
    Jun 19, 2014 at 14:23
  • I don't get the point of UID mapping. But I've updated my answer to fit your needs. Jun 20, 2014 at 4:41
  • I would also like that the messages in the new server also have the UUID they used to have in the old server. This is not provided by --useuid I think, according the description
    – lefterav
    Oct 24, 2014 at 15:37
2

You should migrate your mail using the dsync utility from Dovecot. This will preserve the UIDs and even POP3 UIDLs if necessary.

Run dsync using the backup -R option, to 'reverse backup' from the remote IMAP server to the local Dovecot server. You need to have a special configuration file created, something like this:

imapc_host = imap.company.com
imapc_user = %[email protected]
imapc_password =  mypassword
imapc_features = rfc822.size fetch-headers
imapc_port = 143
pop3c_host = pop3host.company.com
pop3c_user = %[email protected]
pop3c_password = mypassword
pop3c_port = 110
namespace pop3c {
   prefix = POP3-MIGRATION-NS/
   location = pop3c:~/pop3c
   list = no
   hidden = yes
}

!include /etc/dovecot/dovecot.conf

plugin {
  pop3_migration_mailbox = POP3-MIGRATION-NS/INBOX
  pop3_migration_skip_size_check = yes
  pop3_migration_ignore_missing_uidls=yes
}
mail_prefetch_count = 20
mail_shared_explicit_inbox = no
protocol doveadm {
  mail_plugins = $mail_plugins pop3_migration
}

Note this is for a single user; you may want to have different options if you use a master user/password, or if you require SSL for the connections.

Then call it with something like: dsync -D -v -u username -c configfile.cfg

The username replaces the %u in the config.cfg file. The -D -v is verbose debug mode.

1
  • The Dovecot documentation page Migrating mailboxes has more examples on creating this file.
    – Paul
    Jan 31, 2022 at 19:59
1

You need to include those settings in Dovecot configuration, usually Dovecot configs are in /etc/dovecot/.

Best would be to place the configuration in /etc/dovecot/conf.d/90-migration.conf (all files in conf.d dir are automatically included).

To reload the config you need to run:

sudo doveadm reload

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .