Compacting folders

Revision Information
  • Revision id: 219397
  • Created:
  • Creator: Matt
  • Comment: Not for review
  • Reviewed: No
  • Ready for localization: No
Revision Source
Revision Content

This article explains how Thunderbird stores messages on disk and why it is necessary to periodically compact (purge).

What compact does not do

Compact (purge):

  • does not delete messages from folders
  • does not remove messages from trash or spam folders

Compact sometimes appears just when you have deleted a message, or when you start Thunderbird. This is expected behavior and is not cause for concern or alarm - again, compact does not delete your messages.

How does Thunderbird store messages?

Thunderbird has two storage methods:

  • MBOX is the default format, where all of a folder's messages are stored in a single file on disk. This is where the compact process is useful, and the purpose of this article is to explain how and why.
  • Maildir is a newer storage format, where every message of a folder is a separate file. Maildir does not use compact, and so this article is not applicable Maildir folders.

Why is compact required?

Folders stored in MBOX format need periodic cleaning because your daily usage involves:

  • Adding messages to a folder, which makes an MBOX file larger.
  • Deleting a message or moving it to another folder does not immediately make the MBOX file smaller. Instead, for performance reasons, a deleted message is only logically marked for deletion and it is hidden from you. These are now gaps in the folder that are no longer accessible to you - like bits of dirt - the messages that were there are gone, and the gaps are no longer of any value.

Compact (purge) is done later to remove the gaps. This frees disk space which would otherwise accumulate over time, and helps maintain best performance. It is like sweeping the floor to get rid of the dirt.

When does compact occur?

A compact happens when:

  • You right-click a folder and select Compact to compact a single folder
  • You select File > Compact Folders to compact all folders in an account
  • The amount of disk to be saved by removing the gaps exceeds the threshold for automatic compact (configuration described below). This may result in a prompt asking you to approve the compact.

The compact prompt

The compact prompt appears when the compact threshold has been reached. It has a checkbox which you can mark, and then click "Proceed", in which case you will no longer be prompted - future automatic compacts will happen in the background.

How can I configure compact?

In the Thunderbird | PreferencesTools | OptionsEdit | Preferences , you can search the term compact after which you can:

  • Disable automatic compact (which is not recommended because your folders won't be regularly cleaned of deleted messages)
  • Change the compact threshold - a higher vaule will result in less frequent compacts (for example if you deal with large messages or a large volume of messages, then you may want use a larger threshold)

CompactTermSearchResults

How does compact work?

Thunderbird opens the MBOX file on the disk (for example, the Inbox), and based on the rules for the MBOX mail format it reads the file one message at a time:

  • If the message is still current, it is copied to a new temporary MBOX file, called Nstmp.
  • If the message was marked as deleted or moved, that message is skipped and not moved to the mtemporary MBOX file.

This repeats until the end of the file is reached. Then the original storage file is deleted, the new one replaces it, and a new index for this message file is created (for example Inbox.msf). The end result is the gaps (the dirt) are gone.

During compact the progress is displayed in the Status Bar:

Compacting folder message

Notes

Note: Compact does not apply to accounts using the Maildir storage format. Unlike MBOX, Maildir stores each message in a separate file, and deleting a message results in deleting the message file.

See also