The Zentyal 2.0 release included a new groupware module to support the Zarafa Collaboration Platform. This software can be used as a unified communications platform, it includes a lot of features such as calendar, contacts, tasks, mail gateways and much more. It supports many clients, such as Microsoft Outlook 2007, web browsers and the ones that are compliant with protocols like ActiveSync, Blackberry Enterprise Server, POP3/IMAP and iCal/CalDAV.

For storing the mail, Zarafa has its own database, so if you want to migrate all the messages of an account from a standard mail server to Zarafa, the best way is to use the IMAP protocol, that allows to read all the messages in the original server and copy or move them to the new server. Although you can probably use your mail client to manually copy all your messages from one account to the other one, some tools exist to automatize this process. In this article I’m going to explain how to use imapsync, one of these tools, to migrate a mail account.

imapsync can be installed in a debian based system using apt-get:

sudo apt-get install imapsync

After installing it we need to know, at least, the following information to connect with our mail accounts:

  • Authentication mechanism or protocols used to connect with the server. They are usually plain, SSL or TLS.
  • Hostname of the server that contains the account
  • User name
  • User password

And you will also probably need information about how the messages are stored in the server:

  • Path separator, that can be different between servers. It usually is “.” or “/”.
  • Path prefix. Prefix added to any path in the server.
  • Header information particularities. Important to compare messages and avoid repeated ones.

If you are using Zentyal and Zarafa, the separator is “/” and there is no prefix. You’ll need to take this into account when configuring the destination server during the migration.

imapsync tries to avoid duplicate copies of the messages and for that reason, by default, it compares all the headers of copied messages with the existing ones in the destination account. This can cause problems with servers with custom header information because they will be always different, as is the case of Zarafa. To solve this, you can specify the way to compare the messages. The most common solution is to use only some header fields, e.g. for this migration we will only use Message-ID, that is usually unique.

Once you know all this, you can start to use the tool. Let’s see the needed parameters (the parameters ending with 1 are for the origin server and the ones ending with 2 are for the destination server):

  • –noauthmd5, to not to use md5 authentications.
  • –ssl1 and –ssl2, to use SSL connections.
  • –host1 and –host2, hostname.
  • –user1 and –user2, user name.
  • –password1 and –password2, to specify the passwords in the command line. This is only useful if you are going to make scripts to migrate lots of accounts, if you are going to migrate only one, it’s safer to let imapsync ask for the passwords if needed.
  • –sep1 and –sep2, path separator.
  • –prefix1 and –prefix2, path prefix.
  • –skipheader, regular expression of headers to skip when checking the duplicated messages.

At the end, the command result in something like this:

imapsync --noauthmd5 \
    --ssl1 \
    --host1 \
    --user1 \
    --ssl2 \
    --host2 \
    --user2 jsoriano \
    --sep2 / \
    --prefix2 '' \
    --skipheader '^(?!Message-ID)'

Notice that the format of the user account depends on the server, e.g. Zentyal uses the complete mail address in the mail module, while Zarafa uses only the user name. Notice also how to specify that all the headers that are not Message-ID have to be skipped by using the –skipheader argument and regular expressions.

If your connection with the servers is not very good and you keep disconnecting, you can run the command in a loop and add the –skipsize argument to avoid the initial size checks:

while ! imapsync --skipsize [...]; do true; done

And finally, if you want to copy only some directories, you can use the argument –folderrec followed by the base path.

Once all your messages have been migrated, you can also configure your mail client to use the same folders as Zarafa, e.g., in Thunderbird you can specify the following paths:

  • Move deleted messages to Deleted Items
  • When a message is sent, put a copy on Sent Items
  • Move spam to Junk E-mail

With this instructions you should have all that you need to migrate your IMAP account to a Zarafa server.

A post by Jaime Soriano