In this tutorial we can learn how to migrate emails using IMAP Copy.

What is IMAP Copy?

IMAP Copy is an open-source command used to copy email from one server to another. It can also be used to Microsoft Exchange but it may not copy everything from Exchange. To understand what IMAP Copy is, we need to know the steps that take place during a website migration. Let’s see an overview of the website migration.

Steps in Website migration

Many websites use control panels for management. A control panel will allow the owner to manage the website and associated settings easily. cPanel, Plesk, and DirectAdmin are common control panels in the web hosting industry. It is common to use control panels because it helps a website owner to manage the website even if they are technically savvy and lack the knowledge to navigate the command line interface.

The steps involved to migrate a website is based upon if it had used a control panel previously. Most  control panels have their own utilities or tools to migrate a website easily. This includes very few steps as listed below.

1) Take full website backup

2) Transfer it to the new servers

3) Restore the backup on the new server

For a website without a control panel, the migration process is quite different. The website will need to be migrated manually. This may include a few more steps and those are listed below:

1) Take a backup of website files, Databases, Emails individually.

2) Transfer the backups (Usually over FTP)

3) Create the databases on a new server and restore the backups.

You may have noticed that emails need to be migrated manually. The IMAP Copy is used to transfer the emails from the old server to a new server. Let’s see how can we migrate the emails using IMAP Copy.

IMAP Copy

IMAP Copy is a utility used to copy recursively all email messages and folders from an IMAP server to anther IMAP server. Utilizing this functionality, mail boxes and messages can be transferred from one server to another. Please be aware that this requires an email account to use IMAP over POP3. Below we have compared and contrasted IMAP and POP3.

IMAP

IMAP stands for Internet Message Access Protocol. It is used to access emails on a webserver from a local mail client. If you wish to check your emails from multiple devices like from your mobile phone, personal computer, and from your office, this protocol is recommended. In this protocol emails will be stored on the server, so that you could access it from anywhere. A drawback is depending upon how many emails you save, it can consume a considerably amount of a server’s disk space memory.

POP3

POP3 in another protocol that is used to access emails. It stands for Post Office Protocol. The main difference is that in POP3 it does not download and store emails from the server into your local device.

How does IMAP Copy work

As we have seen earlier, IMAP Copy is a tool that is used to copy a user’s email messages from one web server to another. It is a Perl program designed to work with IMAP servers. This program will log into the old server (where you need the emails to be copied from). It does require your username and password for the account. Then it will build a list of both your mail boxes and email messages in them. The program will then log into the new server (where you are going to copy the emails to) with the username and password of the new server. Then it will copy the mail boxes and the messages to the new server. The structure of mailboxes (email folders) on the old server will be recreated on the new server and the emails will be copied preserving the structure of your old email account

IMAP copy will also preserve flag categories like “Seen”, “Deleted” etc and the dates of the emails.

Steps in IMAP Copy

1) Install IMAP Copy.

For a Centos system, please download imapcopy.tar.gz.

Now untar the file as below.

# wget http://home.arcor.de/armin.diehl/imapcopy/imapcopy.tar.gz
# tar -xvf imapcopy.tar.gz

Now enter into the directory “imapcopy”.

# cd imapcopy

2) Provide the source and destination server details.

To perform this, we need to edit the configuration file of the imapcopy. Locate the file “ImapCopy.cfg” and then edit the file with the required details. A sample for this is given below.

SourceServer server.source.com

SourcePort 143

DestServer server.destination.com

DestPort 145

#CreateEmptyFolders

skipfolder INBOX.Trash

skipfolder INBOX.Sent

skipfolder “INBOX.Sent Objects”

# SourceUser SourcePassword DestinationUser DestinationPassword

Copy “usr1” “usr1srcpw” “usr1” “usr1destnpw”

Copy “usr2” “usr2srcpw” “usr2” “usr2destnpw”

Note: This sample will copy the users “usr1” and “usr2” from the server “server.source.com”, port 143 to the server “server.destination.com”, port 145. The password for “usr1” on the source server is “usr1srcpw” and on the destination server is “usr1destnpw” and the password for “usr2” on the source server is “usr2srcpw” and on the destination server is “usr2destnpw”.

Before performing the imapcopy, we can test the configuration file to verify all data inputted is valid. To test, please run the below command.

3) Test the configuration file.

# imapcopy -t

To show the information about the servlets used, please run the below command.

# imapcopy -l

4) Initiate the process.

To perform the operation, please execute the following command.

# imapcopy