Compressed Folders Feature

Read from/write to compressed mailboxes

1. Support

Since: NeoMutt 2016-05-30

Dependencies: None

2. Introduction

The Compressed Folder patch allows Mutt to read mailbox files that are compressed. But it isn't limited to compressed files. It works well with encrypted files, too. In fact, if you can create a program/script to convert to and from your format, then Mutt can read it.

The patch adds three hooks to Mutt: open-hook, close-hookand append-hook. They define commands to: uncompress a file; compress a file; append messages to an already compressed file.

There are some examples of both compressed and encrypted files, later. For now, the documentation will just concentrate on compressed files.

3. Commands

open-hook pattern shell-command
close-hook pattern shell-command
append-hook pattern shell-command

The shell-command must contain two placeholders for filenames: %fand %t. These represent fromand tofilenames. These placeholders should be placed inside single-quotes to prevent unintended shell expansions.

If you need the exact string %for %tin your command, simply double up the %character, e.g. %%for %%t.

Table 9.1. Not all Hooks are Required

Open Close Append Effect Useful if
Open - - Folder is readonly The folder is just a backup
Open Close - Folder is read/write, but the entire folder must be written if anything is changed Your compression format doesn't support appending
Open Close Append Folder is read/write and emails can be efficiently added to the end Your compression format supports appending
Open - Append Folder is readonly, but can be appended to You want to store emails, but never change them

Note

The command:

  • should return a non-zero exit status on failure

  • should not delete any files

3.1. Read from compressed mailbox

open-hook regexp shell-command

If Mutt is unable to open a file, it then looks for open-hookthat matches the filename.

If your compression program doesn't have a well-defined extension, then you can use .as the regexp.

3.1.1. Example of open-hook

open-hook '\.gz$' "gzip --stdout --decompress '%f' > '%t'"
  • Mutt finds a file, example.gz, that it can't read

  • Mutt has an open-hookwhose regexp matches the filename: \.gz$

  • Mutt uses the command gzip -cdto create a temporary file that it can read

3.2. Write to a compressed mailbox

close-hook regexp shell-command

When Mutt has finished with a compressed mail folder, it will look for a matching close-hookto recompress the file. This hook is optional.

Note

If the folder has not been modified, the close-hookwill not be called.

3.2.1. Example of close-hook

close-hook '\.gz$' "gzip --stdout '%t' > '%f'"
  • Mutt has finished with a folder, example.gz, that it opened with open-hook

  • The folder has been modified

  • Mutt has a close-hookwhose regexp matches the filename: \.gz$

  • Mutt uses the command gzip -cto create a new compressed file

Note

The close-hookcan also include extra options, e.g. compression level: --best

3.3. Append to a compressed mailbox

append-hook regexp shell-command

When Mutt wants to append an email to a compressed mail folder, it will look for a matching append-hook. This hook is optional.

Using the append-hookwill save time, but Mutt won't be able to determine the type of the mail folder inside the compressed file.

Mutt will assume the type to be that of the $mbox_typevariable. Mutt also uses this type for temporary files.

Mutt will only use the append-hookfor existing files. The close-hookwill be used for empty, or missing files.

Note

If your command writes to stdout, it is vital that you use >>in the append-hook. If not, data will be lost.

3.3.1. Example of append-hook

append-hook '\.gz$' "gzip --stdout '%t' >> '%f'"
  • Mutt wants to append an email to a folder, example.gz, that it opened with open-hook

  • Mutt has an append-hookwhose regexp matches the filename: \.gz$

  • Mutt knows the mailbox type from the $mboxvariable

  • Mutt uses the command gzip -cto append to an existing compressed file

Note

The append-hookcan also include extra options, e.g. compression level: --best

3.4. Empty Files

Mutt assumes that an empty file is not compressed. In this situation, unset $save_empty, so that the compressed file will be removed if you delete all of the messages.

3.5. Security

Encrypted files are decrypted into temporary files which are stored in the $tmpdirdirectory. This could be a security risk.

4. Muttrc

# Example NeoMutt config file for the compress feature.

# This feature adds three hooks to Mutt which allow it to
# work with compressed, or encrypted, mailboxes.

# The hooks are of the form:
#       open-hook   regexp "shell-command"
#       close-hook  regexp "shell-command"
#       append-hook regexp "shell-command"
# The 'append-hook' is optional.

# Handler for gzip compressed mailboxes
open-hook   '\.gz$' "gzip --stdout --decompress '%f' >  '%t'"
close-hook  '\.gz$' "gzip --stdout              '%t' >  '%f'"
append-hook '\.gz$' "gzip --stdout              '%t' >> '%f'"
# Handler for bzip2 compressed mailboxes
open-hook   '\.bz2$' "bzip2 --stdout --decompress '%f' >  '%t'"
close-hook  '\.bz2$' "bzip2 --stdout              '%t' >  '%f'"
append-hook '\.bz2$' "bzip2 --stdout              '%t' >> '%f'"
# Handler for xz compressed mailboxes
open-hook   '\.xz$' "xz --stdout --decompress '%f' >  '%t'"
close-hook  '\.xz$' "xz --stdout              '%t' >  '%f'"
append-hook '\.xz$' "xz --stdout              '%t' >> '%f'"
# Handler for pgp encrypted mailboxes
# PGP does not support appending to an encrypted file
open-hook   '\.pgp$' "pgp -f < '%f' > '%t'"
close-hook  '\.pgp$' "pgp -fe YourPgpUserIdOrKeyId < '%t' > '%f'"
# Handler for gpg encrypted mailboxes
# gpg does not support appending to an encrypted file
open-hook   '\.gpg$' "gpg --decrypt < '%f' > '%t'"
close-hook  '\.gpg$' "gpg --encrypt --recipient YourGpgUserIdOrKeyId < '%t' > '%f'"


# vim: syntax=muttrc

6. Credits