Try to use open source project imap-backup: https://github.com/joeyates/imap-backup
$ imap-backup setup The setup system is a menu-driven command line application.
It creates ~/.imap-backup directory and configuration file. E.g.:
{ "accounts": [ { "username": "[email protected]", "password": "secret", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ] } ] } It connects to GMail by default, but you can also specify a server:
{ "accounts": [ { "username": "[email protected]", "password": "secret", "server": "my.imap.example.com", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ] } ] }