IMAP: How to migrate mailboxes using imapsync

This guide assumes you are using Debian Buster

sudo apt install git rcs make makepasswd cpanminus
sudo apt install libauthen-ntlm-perl \
libclass-load-perl libcrypt-ssleay-perl liburi-perl \
libdata-uniqid-perl libdigest-hmac-perl libdist-checkconflicts-perl \
libfile-copy-recursive-perl libio-compress-perl libio-socket-inet6-perl \
libio-socket-ssl-perl libio-tee-perl libmail-imapclient-perl \
libmodule-scandeps-perl libnet-ssleay-perl libpar-packer-perl \
libreadonly-perl libsys-meminfo-perl libterm-readkey-perl \
libtest-fatal-perl libtest-mock-guard-perl libtest-pod-perl \
libtest-requires-perl libtest-simple-perl libunicode-string-perl \
libfile-tail-perl libcrypt-openssl-rsa-perl libjson-webtoken-perl \
libregexp-common-perl libtest-mockobject-perl libtest-deep-perl \
libcgi-pm-perl liblwp-useragent-chicaching-perl libencode-imaputf7-perl
sudo apt install libssl-dev
sudo apt install apt-file

git clone https://github.com/imapsync/imapsync

cd imapsync

mkdir -p dist

sudo make install
imapsync --host1 mail.example.nl \
--user1 mail@example.com \
--password1 ____PASSWORD____ \
--authmech1 PLAIN \
--tls1 \
--host2 mail.example.org \
--user2 newmail@example.com \
--password2 ____PASSWORD____ \
--authmech2 PLAIN \
--tls2 \
--no-modulesversion \
--addheader

Batch migrating IMAP accounts

credentials
username@example.org password
username2@example.org anotherpassword
imapsync-batch.sh
#! /bin/sh

while IFS=' ' read -ra ACCOUNT line
do
    imapsync --host1 oldserver.example.org --user1 ${ACCOUNT[0]} --password1 ${ACCOUNT[1]} --authmech1 PLAIN --tls1 --host2 newserver.example.org --user2 ${ACCOUNT[0]} --password2 ${ACCOUNT[1]} --authmech2 PLAIN --tls2 --no-modulesversion --addheader
done < credentials

Flags

  • Use --delete2 to perform a strict sync: it deletes messages in host2 folder B that are not in host1 folder A.

References

Related