On va utiliser l'outil mbsync
apt-get install isync
Création du fichier de configuration :
vi /tmp/mbsyncrc
IMAPAccount webmaster
Host mon-ip-ou-mon-host
User webmaster
Pass mon-mot-de-passe
AuthMechs LOGIN
CertificateFile /tmp/certificatimap.pem
IMAPStore webmaster-remove
Account webmaster
MaildirStore webmaster-local
Path /path-de-ma-sauvegarde/Maildir/
Inbox /path-de-ma-sauvegarde/Maildir/
SubFolders Verbatim
Channel webmaster
Master :webmaster-remote:
Slave :webmaster-local:
Create Slave
Expunge Slave
Patterns *
SyncState *
CopyArrivalDate yes
Sync Pull
Pour récupérer le certificat du protocole imap :
openssl s_client -connect mon-ip-ou-mon-host:993 -showcerts 2>&1 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed -ne '1,/-END CERTIFICATE-/p' >/tmp/certificatimap.pem
... si le port d'écoute de votre imap est en 993. Sinon ce sera peut être le 143.
Pour exécuter mbsync :
mbsync -a -c /tmp/mbsyncrc