Courier Email Migration

While setting up my new server I also had to migrate all my emails.
Courier saves all emails as files that can simply be copied to the new server. The files are saved in the following directory:

To copy the files scp is the easiest and fastes way. Executing the following command on the new server copies the Mailbox folder from the old server to the new one:

scp user@oldserver:/var/qmail/mailnames/<domain>/<name>/Mailbox /var/qmail/mailnames/<domain>/<name>/

If you don’t use key authentication it asks for the password of user.

scp doesn’t transfer the file permissions so the copied files are owned by the user that executed scp. Because of that courier will rise many errors when you first try do download the emails in your client of choice. The Mailbox folder and all files in it must be owned by the same user and group than the other files in the /var/qmail/<domain>/<name>/ directory. With ls -l the owner and group can be found.

total 8
drwx------ 2 popuser popuser 4096 Sep 19 13:29 @attachments
drwx------ 17 popuser popuser 4096 Sep 27 08:41 Maildir

So user and group is popuser. To change the owner of all files in the Mailbox directory execute

# chown -r <user>:<group> Mailbox/*

The second thing I did and I don’t really know if it is mandatory, is to delete the courierimapuiddb file. Courier creates a new one when emails are fetched the next time, but can have problems if the file does not coincide with the email files.