Email Migration is a process used to migrate mailbox content from one account to another.
The command imapsync is a tool allowing incremental and recursive IMAP transfer from one mailbox to another.
By default all folders are transferred, recursively. We sometimes need to transfer mailboxes from one imap server to another. This is called migration.
imapsync is a good tool because it reduces the amount of data transferred by not transferring a given message if it is already on both sides. Same headers, same message size and the transfer is done only once. All flags are preserved, unread will stay unread, read will stay read, deleted will stay deleted. You can stop the transfer at anytime and restart it later, imapsync works well with bad connections.
usage: /usr/bin/imapsync [options]
Several options are mandatory.
–host1 <string> : “from” imap server. Mandatory.
–port1 <int> : port to connect on host1. Default is 143.
–user1 <string> : user to login on host1. Mandatory.
–authuser1 <string> : user to auth with on host1 (admin user).Avoid using –authmech1 SOMETHING with –authuser1.
–password1 <string> : password for the user1. Dangerous, use –passfile1
–passfile1 <string> : password file for the user1. Contains the password.
–host2 <string> : “destination” imap server. Mandatory.
–port2 <int> : port to connect on host2. Default is 143.
–user2 <string> : user to login on host2. Mandatory.
–authuser2 <string> : user to auth with on host2 (admin user).
–password2 <string> : password for the user2. Dangerous, use –passfile2
–passfile2 <string> : password file for the user2. Contains the password.
–noauthmd5 : don’t use MD5 authentification.
–authmech1 <string> : auth mechanism to use with host1:PLAIN, LOGIN, CRAM-MD5 etc. Use UPPERCASE.
–authmech2 <string> : auth mechanism to use with host2. See –authmech1
–ssl1 : use an SSL connection on host1.
–ssl2 : use an SSL connection on host2.
–tls1 : use an TLS connection on host1.
–tls2 : use an TLS connection on host2.
–folder <string> : sync this folder.
–folder <string> : and this one, etc.
–folderrec <string> : sync this folder recursively.
–folderrec <string> : and this one, etc.
–include <regex> : sync folders matching this regular expression
–include <regex> : or this one, etc.in case both –include –exclude options are use, include is done before.
–exclude <regex> : skips folders matching this regular expression. Several folders to avoid: –exclude ‘fold1|fold2|f3’ skips fold1, fold2 and f3.
–exclude <regex> : or this one, etc.
–tmpdir <string> : where to store temporary files and subdirectories. Will be created if it doesn’t exist. Default is system specific and should be ok.
–pidfile <string> : the file where imapsync pid is written.
–prefix1 <string> : remove prefix to all destination folders. (usually INBOX. for cyrus imap servers) You can use –prefix1 if your source imap server.Does not have NAMESPACE capability.
–prefix2 <string> : add prefix to all destination folders.(usually INBOX. for cyrus imap servers)use –prefix2 if your target imap server does not. Have NAMESPACE capability.
–regextrans2 <regex> : Apply the whole regex to each destination folders.
–regextrans2 <regex> : and this one. etc. When you play with the –regextrans2 option, first add also the safe options –dry –justfolders. Then, when happy, remove –dry, remove –justfolders
–regexmess <regex> : Apply the whole regex to each message before transfer. Example: ‘s/\000/ /g’ # to replace null by space.
–regexmess <regex> : and this one.
–regexmess <regex> : and this one, etc.
–regexflag <regex> : Apply the whole regex to each flags list. Example: ‘s/”Junk”//g’ # to remove “Junk” flag.
–regexflag <regex> : and this one, etc.
–sep1 <string> : Host1 separator in case NAMESPACE is not supported
–sep2 <string> : Host2 separator in case NAMESPACE is not supported
–delete : delete messages on host1 server after a successful transfer. Useful in case you want to migrate from one server to another one. With imap, “delete” tags messages as deleted, they are not really deleted. See expunge.
–delete2 : delete messages on host2 that are not on host1 server.
–expunge : expunge messages on host1. expunge really deletes messages marked deleted. expunge is made at the beginning, on host1 only. Newly transferred messages are expunged if option –expunge is given. No expunge is done on destination account. (see –expunge2) but it may change in future releases.
–expunge1 : expunge messages on host1.
–expunge2 : expunge messages on host2.
–uidexpunge2 : uidexpunge messages on the destination imap server that are not on the source server, requires –delete2
–syncinternaldates : sets the internal dates on host2 same as host1. Turned on by default. Internal date is the date a message arrived on a host (mtime).
–idatefromheader : sets the internal dates on host2 same as the “Date:” headers.
–buffersize <int> : sets the size of a block of I/O.
–maxsize <int> : skip messages larger than <int> bytes
–maxage <int> : skip messages older than <int> days. final stats (skipped) don’t count older messages see also –minage
–minage <int> : skip messages newer than <int> days. final stats (skipped) don’t count newer messages
–useheader <string> : Use this header to compare messages on both sides. Ex: Message-ID or Subject or Date.
–useheader <string> and this one, etc.
–skipsize : Don’t take message size into account to compare messages on both sides. On by default. Use –no-skipsize for using size comparaison.
–allowsizemismatch : allow RFC822.SIZE != fetched msg size consider also –skipsize to avoid duplicate messages when running syncs more than one time per mailbox
–dry : do nothing, just print what would be done.
–subscribed : transfers subscribed folders.
–subscribe : subscribe to the folders transferred on the host2 that are subscribed on host1.
–subscribe_all : subscribe to the folders transferred on the host2 even if they are not subscribed on host1.
–nofoldersizes : Do not calculate the size of each folder in bytes and message counts. Default is to calculate them.
–justfoldersizes : exit after printed the folder sizes.
–syncacls : Synchronises acls (Access Control Lists).
–nosyncacls : Does not synchronise acls. This is the default.
–debug : debug mode.
–debugimap1 : imap debug mode for host1. imap debug is very verbose.
–debugimap2 : imap debug mode for host2.
–debugimap : imap debug mode for host1 and host2.
–version : print software version.
–noreleasecheck : do not check for new imapsync release (a http request).
–justconnect : just connect to both servers and print useful information. Need only –host1 and –host2 options.
–justlogin : just login to both host1 and host2 with users credentials, then exit.
–justfolders : just do things about folders (ignore messages).
–fast : be faster (just does not sync flags of messages already transfered).
–reconnectretry1 <int>: reconnect to host1 if connection is lost up to
<int> times per imap command (default is 3)
–reconnectretry2 <int>: same as –reconnectretry1 but for host2
–split1 <int> : split the requests in several parts on host1. <int> is the number of messages handled per request. default is like –split1 1000.
–split2 <int> : same thing on host2.
–fastio1 : use fastio with host1.
–fastio2 : use fastio with host2.
–timeout <int> : imap connect timeout.
–help : print this help.
Few examples of the IMAP sync command usage
We can use the –dry option to check whether the current IMAP command works correctly.
Testing the migration of email account firstname.lastname@example.org in host1 (server IP xxx.xxx.xxx.xxx) to host2 (server IP yyy.yyy.yyy.yyy)
imapsync –noauthmd5 –host1 xxx.xxx.xxx.xxx –user1 email@example.com –password1 yourpassword1 –authmech2 PLAIN –host2 yyy.yyy.yyy.yyy –user2 firstname.lastname@example.org –password2 yourpassword2 –dry
To migrate email account email@example.com in host1 to host2
imapsync –noauthmd5 –host1 xxx.xxx.xxx.xxx –user1 firstname.lastname@example.org –password1 yourpassword1 –authmech2 PLAIN –host2 yyy.yyy.yyy.yyy –user2 email@example.com –password2 yourpassword2
To migrate email account firstname.lastname@example.org in host1 to host2 excluding the specfic mails in Inbox and suscribe all the folders in host2 that are present in host1
imapsync –noauthmd5 –host1 xxx.xxx.xxx.xxx –user1 email@example.com –password1 yourpassword1 –host2 yyy.yyy.yyy.yyy –user2 firstname.lastname@example.org –password2 yourpassword2 –exclude ‘INBOX.52b33bce3dd6b4c2013dd82718a81909|INBOX.52b33bce3dd6b4c2013dd827da5a198f|INBOX.52b33bce3dd6b4c2013dd82a24851a1f|INBOX.52b33bce3dd6b4c2013dd82be7a61a74’ –subscribe_all
Imap sync command to include a specific folder INBOX.201408 in host1 to host2
imapsync –noauthmd5 –host1 xxx.xxx.xxx.xxx –user1 email@example.com –password1 yourpassword1 –host2 yyy.yyy.yyy.yyy –user2 firstname.lastname@example.org –password2 yourpassword2 –subscribe –folder INBOX.201408
Imap sync command to delete the messages from the source mailbox after a successful transfer
imapsync –noauthmd5 –host1 xxx.xxx.xxx.xxx –user1 email@example.com –password1 yourpassword1 –host2 yyy.yyy.yyy.yyy –user2 firstname.lastname@example.org –password2 yourpassword2 –delete –expunge1 –dry
Imap sync command to migrate emails from pop to imap
/usr/bin/pop2imap –host1 pop3.domain.com –user1 username1 –passfile1 /etc/secret1 –host2 imap.domain.com –user2 username2 –passfile2 /etc/secret2
POP to IMAP migration
We can use the command pop2imap for migrating mails from a POP account to IMAP account. You can refer the below options incase of pop to imap email migration.
pop2imap [–host1 server1] [–port1 <num>] [–user1 <string>] [–passfile1 <string>] [–host2 server2] [–port2 <num>] [–ssl2|–starttls2] [–user2 <string>] [–passfile2 <string>] [–from <string>] [–to <string>] [–folder <string>] [–delete] [–dry] [–quiet] [–debug] [–debugimap] [–debugpop] [–version] [–help]
Manual email migration
You can follow the below procedure to migrate an email account from remote server to our server manually.
> Create two email accounts as IMAP in email client (for example Outlook).
> One mail account need to be created with remote mail server settings and the other mail account need to be created with Vodien mail server settings.
> The mails will be automatically fetched from the remote mail server on the mail account setup with remote settings.
> By right clicking each folder the mails can now be copied to the the respective folders of the other mail account having Vodien mail server settings.
If you require help, contact SupportPRO Server Admin