KOMPX.COM or COMPMISCELLANEA.COM   

Imapsync IMAP migration under Windows

Migrating an IMAP e-mail box from one IMAP server to another under Windows by means of imapsync command-line tool:

The process is done in three steps:

  1. Test run: imapsync-test.bat
  2. Migrating folder structure: imapsync-folders.bat
  3. Migrating e-mails: imapsync-emails.bat

Test run

Content of imapsync-test.bat:


.\imapsync.exe ^
	--host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^
	--host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^
	--ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^
	--skipheader "^(?!Message-Id)" ^
	--automap ^
	--regextrans2 "s/^INBOX\.(.+)/$1/" ^
	--addheader ^
	--justfolders ^
	--dry
@PAUSE

Note: the caret character ( ^ ) at the end of line means "this command continues on the next line". It allows to break a long command with many options into several parts to put them in several lines for better readability.

This step is meant for testing if imapsync may be run at all, if it can connect to both e-mail boxes and can read the basic structure of the first one. Imapsync runs without actually doing anything, just printing what would have been done without the --dry option. Adding --justfolders is to make testing faster, as imapsync does its job only for folders then.

A log file with full details for each run is placed into the LOG_imapsync folder.

Migrating folder structure

Content of imapsync-folders.bat:


.\imapsync.exe ^
	--host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^
	--host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^
	--ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^
	--skipheader "^(?!Message-Id)" ^
	--automap ^
	--regextrans2 "s/^INBOX\.(.+)/$1/" ^
	--addheader ^
	--justfolders
@PAUSE

This step reproduces the folder structure of the e-mail box being migrated in the one it is being migrated to.

Migrating e-mails

Content of imapsync-emails.bat:


.\imapsync.exe ^
	--host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^
	--host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^
	--ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^
	--skipheader "^(?!Message-Id)" ^
	--automap ^
	--regextrans2 "s/^INBOX\.(.+)/$1/" ^
	--addheader
@PAUSE

Now e-mails are being copied. If the size of an e-mail with attachment(s) is larger than it is allowed (for Yandex Mail it is not more than 30 megabytes - source), then this particular message is not going to be migrated and there is to be an error mentioned in the log file.

Operating systems
More