IMAP backup

From MozillaZine Knowledge Base

It is straightforward for backup programs like Mozbackup to backup POP accounts since the messages are stored within the profile. IMAP accounts are designed to use messages stored in remote folders on the IMAP server. Mozbackup is oblivious of those message's existence.

Starting with Thunderbird 3.0 offline folders are enabled by default by Tools -> Account Settings -> Account_name -> Synchronization & Storage -> "Keep messages for this account on this computer". An offline folder contains a copy of all messages in the corresponding online folder. Offline folders are stored as mbox files, just like mail folders for POP accounts and Local Folders. The offline folder for a inbox would be a "inbox." file. The *.msf files don't have any messages, just headers and some status information.

When you are working online (File -> Offline -> Work Online) the folder listing shows the contents of the remote folder. When you are working offline (File -> Offline -> Work Offline) network activity is disabled and it shows the contents of the corresponding offline folder, if it exists. You can also switch between working online and offline using the icon that looks like two blue PC's next to each other in the lower left corner of the main window.

It used to be that unless you synchronized the remote and offline folders using "File -> Offline -> Download/Sync Now" you could delete a message in the remote folder, empty the trash and compact the folder, and the offline folder was unaffected despite the menu being called Synchronization & Storage. However, with recent versions they are automatically synchronized.


Recommended solution

The easiest way to backup an IMAP account is to automate backing up a profile that contains offline folders. Mozbackup supports command line arguments that can be used to run it under Windows task scheduler. The ImportExportTools add-on has an option to schedule backups. Its dangerous to rely upon the offline folder as a backup since its contents are synchronized, its best used as a way to create a mbox file that can be backed up.

However, you could backup the remote folders without creating offline folders. One solution would be to copy the messages to another IMAP account that you use just for backups. A free Gmail IMAP account has a mailbox of over 10GB. You could also use a program to backup/restore the contents of your IMAP mailbox (independent of Thunderbird). IMAPSize would be a good choice if you are running Windows. It supports incremental backups.


  • You could use message filters to automatically copy new messages from one IMAP account to another. The main limitation is that message filters are only run automatically for the inbox folder.
  • You could use a server side filter to automatically copy the messages between the accounts. Some email providers such as, Runbox, and Tuffmail support the Sieve mail filtering language . That would let you use a redirect :copy command to copy the message to another account without effecting the original message. All Cyrus, Exim, DBmail, PMDF, Sendmail Intelligent Inbox and Sun Messaging IMAP servers have built-in Sieve support. Others might use something like the MVMF or libSieve package to add support for it. If you want to backup from one Gmail account to another you'd have to use a forward command in the filter since Gmail doesn't support Sieve. Typically you use webmail commands (from a browser) to edit/create server side filters. The filters are automatically run whenever the server gets a new message in the mailbox, you don't have to login or check for new mail to run them.

Email forwarding service

  • An email forwarding service is useful if you have a personal domain since it lets you easily change where you read your mail from, without getting a new address. You could use a email forwarding service like POBox that does not add any visible headers when it forwards a message to automatically store a copy of every new message in another IMAP account.

Mailbox synchronization

  • Use imapsync to copy the messages. It requires that you install Perl. See this web page for a writeup with screen shots.
  • Use MailSync . It is designed for a Unix/Linux like operating system though you may be able to run it under Windows if you also install cygwin. Its written in C so you don't need to install an interpreter such as Perl or Python.
  • Use offlineimap . It is designed for a Unix/Linux like operating system though "With some fiddling, it reportedly ran under Windows as well".
  • isync. Its also known as mbsync. Not to be confused with Apple's iSync program for mobile phones. It supports IMAP and Maildir mailboxes.

IMAP backup

  • Use a Windows utility like IMAPSize to backup the messages as .EML files. It does an incremental backup - it won't backup a message again if its already backed up. You can use it to restore any backed up messages or use the ImportExportTools add-on to import the *.EML files into Local Folders, and then move the messages to a remote folder. Since it supports command line arguments you could automatically run it using the Windows Task Scheduler. One advantage it has over a offline folder is that if you delete a message in a remote folder your local copy (a .EML file) is not deleted like it is with a offline folder.
  • Use a Python script such as Imap Backup Tool to backup the folders as mbox, mbox.gz, or mbox.bz2 files. It supports incremental copying from any/all folders. It doesn't backup IMAP flags (tags). IMAPSave is another one. It only stores the messages in mbox files and does not do incremental backups. Both of these programs only do backup, but you could use the ImportExportTools add-on to import the mbox files.
  • BeyondInbox sells for $9.99 a command line tool for Windows/Linux/OS X called Beyond Inbox Commander that does incremental backups of IMAP folders to .eml files. It also supports sending a backup report through mail after the backup is completed.
  • imap2maildir is a Python script [1] to backup a IMAP mailbox to maildir files. Thunderbird 12 added support for maildir files but they're not useful yet as there is no support for converting mbox based accounts etc. yet.
  • If you are using Linux or OS X you could use fetchmail and procmail to backup a IMAP mailbox to mbox or maildir files.

Commercial services

  • If you are using a host such as Dreamhost, HostGator, HostMonster, BlueHost, Siteground etc. you can backup all your IMAP accounts under your cPanel by using its full backup feature.
  • IMAP Backup & Archiver [2] will schedule backups of IMAP accounts to Amazon Web Services (EC2, S3).
  • Backupify and Spanning backup Google Apps.
  • SpinBackup for both Google Apps (commercial) and individual Gmail accounts (free, limited to 5GB). It uses Amazon Web Services (EC2, S3) to store the backups.

There are lots of other programs/scripts to synchronize mailbox's or backup remote folders. However its best to stick with something well known that is actively maintained.

See also

External links