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

cd imapsync

mkdir -p dist

sudo make install
imapsync --host1 \
--user1 \
--password1 ____PASSWORD____ \
--authmech1 PLAIN \
--tls1 \
--host2 \
--user2 \
--password2 ____PASSWORD____ \
--authmech2 PLAIN \
--tls2 \
--no-modulesversion \

Batch migrating IMAP accounts

credentials password anotherpassword
#! /bin/sh

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


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