Sempre que preciso migrar mensagens de um servidor para o outro, via protocolo IMAP, uso o Imapsync. Para quem deseja instalar ele em Debian 9, segue abaixo as instruções:
Instalando dependências
apt install -y libauthen-ntlm-perl libcgi-pm-perl libcrypt-openssl-rsa-perl \ libdata-uniqid-perl libencode-imaputf7-perl libfile-copy-recursive-perl \ libfile-tail-perl libio-socket-inet6-perl libio-socket-ssl-perl libio-tee-perl \ libhtml-parser-perl libjson-webtoken-perl libmail-imapclient-perl \ libparse-recdescent-perl libmodule-scandeps-perl libreadonly-perl \ libregexp-common-perl libsys-meminfo-perl libtest-requires-perl cpanminus \ libterm-readkey-perl libtest-mockobject-perl libdist-checkconflicts-perl \ libtest-pod-perl libunicode-string-perl liburi-perl libwww-perl \ libtest-nowarnings-perl libtest-deep-perl libtest-mock-guard-perl \ libtest-warn-perl make libpar-packer-perl libtest-fatal-perl git-core
Baixando o código
git clone https://github.com/imapsync/imapsync.git
Instalando
cd imapsync make install