I have headless debian/raspbian linux machine and I would like to backup all my emails via IMAP including all mail and subfolders once daily (connection is secured with SSL/TLS. it should run automatically from cronjob every day). This backup should store the same emails as I have on my default mailserver - so it means when I am working from another computer whole day, it should be able to sync my work (that's why I want to use IMAP). Ideally I would like to have all my emails in readable format on backup machine, if main mailserver fails.Any idea how this can be done? 
backup emails from IMAP in readable form
email;backup;imap
Use getmail.  It's a nice python program which can be used to download mails from servers.  The website is a bit dated, but the software is recent and well maintained.  Here is an example config file:[options]delete = False[retriever]type = SimpleIMAPRetrieverserver = my-servernameusername = my-usernamepassword = my-password[destination]type = Maildirpath = ~/Maildir/As you can see, one can define where the mail is to be safed. Multiple mailbox formats are supported.  You could also hand mail over to a local IMAP server, e.g. dovecot.