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 edoceo.com/pub/imap-move.php > imap-move.php php ./imap-move.php \ --source imap-ssl://userA@domain:secretA@imap.example.com:993/ \ --target imap-ssl://userB@domain:secretB@imap.example.com:993/sub-folder
This script is also available on github.
Command Options
This IMAP copy script supports a few options.
- --source
- A URI style pointer to the source IMAP mailbox
- --target
- A URI style pointer to the target IMAP mailbox
- --fake
- Will simply list the messages and folders that would be copyied
- --wipe
- Remove the messages from Source after they have been copied to Target
Examples
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://userA@gmail.com:secretA@imap.gmail.com:993/ \ -t imap-ssl://userB@domain.tld:secretB@imap.gmail.com:993/
Move from Source to Sub-Folder on Target
We can copy mail from for example old.com 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://userA@old.com:secretA@imap.gmail.com:993/ \ -t imap-ssl://userB@new.com:secretB@imap.gmail.com:993/Archive
Remove from Source
php ./imap-move.php \ --wipe \ -s imap-ssl://userA@old.com:secretA@imap.gmail.com:993/ \ -t imap-ssl://userB@new.com:secretB@imap.gmail.com:993/Archive
Show Source Paths and Messages to Copy
php ./imap-move.php \ --fake \ -s imap-ssl://userA@old.com:secretA@imap.gmail.com:993/ \