IMAP local backup with OfflineIMAP


  1. have a one-way local copy of my work address (“A”)
  2. do the same for my private mail address (“B”)
  3. make them accessible together through an easy interface
  4. all software must be open and free

My case:

  1. my own mail address is on Gmail with IMAPS access enabled
  2. my work mail address is accessible via a standard IMAP server
  3. I already have a LAMP webserver in a LXC container hosted on my MicroServer

What you need:

  1. Linux, of course
  2. an internet connection (really?)
  3. a great tool called OfflineIMAP (
  4. an IMAP server, DOVECOT ( in this case

How does it work?

remote IMAP server --> offlineimap --> maildir on localstorage --> local dovecot imap server --> webmail/mail client (like claws-mail

the local maildir is created as

                                     ---> SUBFOLDER 2
                                     ---> SUBFOLDER 2

Ok, let’s go!

  1. first of all install the software needed, for Fedora 17 is pretty easy
    yum install dovecot offlineimap
  2. now, create the OfflineIMAP configuration for your local user (not root!): the file is called .offlineimaprc and is placed in user home
    ]# Copy this to ~/.offlineimaprc and edit to
    # suit to get started fast.
    accounts = account_A, account_B
    ui = TTYUI
    readonly = True
    #beautiful UI but do not use with cron or with logging
    #ui = Blinkenlights
    [Account account_A]
    localrepository = ALocal
    remoterepository = ARemote
    readonly = True
    [Repository ALocal]
    type = Maildir
    sep = /
    localfolders = ~/mail/A
    [Repository ARemote]
    type = IMAP
    remotehost =
    remoteuser = myuser
    remotepass = mypass
    createfolders = False
    [Account account_B]
    localrepository = BLocal
    remoterepository = BRemote
    readonly = True
    [Repository BLocal]
    type = Maildir
    sep = /
    localfolders = ~/mail/B
    [Repository BRemote]
    type = Gmail
    remoteuser = myuser
    remotepass = mypass
    folderfilter = lambda foldername: foldername in ['[Gmail]/All messages']
    createfolders = False
    nametrans = lambda folder: 'INBOX'

    Please note: with “sep = /” you are creating each IMAP subfolder as directory itself (folder/subfolder/subsubfolder) instead of common IMAP format of a single folder called folder.subfolder.subsubfolder

  3. configure DOVECOT to read the correct maildir structure created by OfflineIMAP. In /etc/dovecot/conf.d edit 10-mail.conf
    mail_location = maildir:%h/mail:LAYOUT=fs
  4. install and configure a webmail (not -yet- covered here) or use your favorite mail client to access the emails (the local DOVECOT is usually available at imap+ssl://myhomeserver:993/)
  5. launch offlineimap periodically (via cron, as normal user) to keep the local copy sync


  • Actually I’m using system account as IMAP auth
  • To access the IMAP backup you need an IMAP server or you can access it locally using mutt -f or evolution
Local backup as it looks in RoundCube webmail

Local backup as it looks in RoundCube webmail