IMAP Move - An email migration script

When migrating email services one does not want to lose the old messages. This tool copies messages from one IMAP system to the other. We've used this to migrate from Exchange to Gmail/Google Apps, Gmail to Exchange, Exchange to Exchange, in or out of dovecot too.

Here is a sample script to get started

#!/bin/bash -x

curl > imap-move.php

php ./imap-move.php \
    --source imap-ssl:// \
    --target imap-ssl://

This script is also available on github.

Command Options

This IMAP copy script supports a few options.

A URI style pointer to the source IMAP mailbox
A URI style pointer to the target IMAP mailbox
Will simply list the messages and folders that would be copyied
Remove the messages from Source after they have been copied to Target


Here are a bunch of examples showing how to use imap-move.php

Move from Gmail to Google Apps

This copies from an Gmail style account to a Google Apps hosted domain duplicating folder structure

php ./imap-move.php \
    -s imap-ssl:// \
    -t imap-ssl://

Move from Source to Sub-Folder on Target

We can copy mail from for example to our new email system, storing these old messages in a folder calld Archive This will also work with Google Mail systems as a target.

php ./imap-move.php \
    -s imap-ssl:// \
    -t imap-ssl://

Remove from Source

php ./imap-move.php \
    --wipe \
    -s imap-ssl:// \
    -t imap-ssl://

Show Source Paths and Messages to Copy

php ./imap-move.php \
    --fake \
    -s imap-ssl:// \