Compressed Folders Patch

for the Mutt Mailreader

If Mutt was compiled with compressed folders support (by running the configure script with the --enable-compressed flag), Mutt can open folders stored in an arbitrary format, provided that the user has a script to convert from/to this format to one of the accepted.

The most common use is to open compressed archived folders e.g. with gzip.

In addition, the user can provide a script that gets a folder in an accepted format and appends its context to the folder in the user-defined format, which may be faster than converting the entire folder to the accepted format, appending to it and converting back to the user-defined format.

There are three hooks defined (open-hook, close-hook and append-hook) which define commands to uncompress and compress a folder and to append messages to an existing compressed folder respectively.

For example:

open-hook \\.gz$ "gzip -cd %f > %t"
close-hook \\.gz$ "gzip -c %t > %f"
append-hook \\.gz$ "gzip -c %t >> %f"

You do not have to specify all of the commands. If you omit append-hook, the folder will be open and closed again each time you will add to it. If you omit close-hook (or give empty command) , the folder will be open in the mode. If you specify append-hook though you'll be able to append to the folder.

Note that Mutt will only try to use hooks if the file is not in one of the accepted formats. In particular, if the file is empty, mutt supposes it is not compressed. This is important because it allows the use of programs that do not have well defined extensions. Just use "." as a regexp. But this may be surprising if your compressing script produces empty files. In this situation, unset $save_empty, so that the compressed file will be removed if you delete all of the messages.

Open a compressed mailbox for reading

Usage: open-hook regexp "command"

The command is the command that can be used for opening the folders whose names match regexp.

The command string is the printf-like format string, and it should accept two parameters: %f, which is replaced with the (compressed) folder name, and %t which is replaced with the name of the temporary folder to which to write.

%f and %t can be repeated any number of times in the command string, and all of the entries are replaced with the appropriate folder name. In addition, %% is replaced by %, as in printf, and any other %anything is left as is.

The command should not remove the original compressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong.

Example:

open-hook \\.gz$ "gzip -cd %f > %t"

If the command is empty, this operation is disabled for this file type.

Write a compressed mailbox

Usage: close-hook regexp "command"

This is used to close the folder that was open with the open-hook command after some changes were made to it.

The command string is the command that can be used for closing the folders whose names match regexp. It has the same format as in the open-hook command. Temporary folder in this case is the folder previously produced by the open-hook command.

The command should not remove the decompressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong.

Example:

close-hook \\.gz$ "gzip -c %t > %f"

If the command is empty, this operation is disabled for this file type, and the file can only be open in the read-only mode.

close-hook is not called when you exit from the folder if the folder was not changed.

Append a message to a compressed mailbox

Usage: append-hook regexp "command"

This command is used for saving to an existing compressed folder. The command is the command that can be used for appending to the folders whose names match regexp. It has the same format as in the open-hook command. The temporary folder in this case contains the messages that are being appended.

The command should not remove the decompressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong.

Example:

append-hook \\.gz$ "gzip -c %t >> %f"

When append-hook is used, the folder is not opened, which saves time, but this means that we can not find out what the folder type is. Thus the default ($mbox_type) type is always supposed (i.e. this is the format used for the temporary folder).

If the file does not exist when you save to it, close-hook is called, and not append-hook. append-hook is only for appending to existing folders.

If the command is empty, this operation is disabled for this file type. In this case, the folder will be open and closed again (using open-hook and close-hookrespectively) each time you will add to it.

Encrypted folders

The compressed folders support can also be used to handle encrypted folders. If you want to encrypt a folder with PGP, you may want to use the following hooks:

open-hook  \\.pgp$ "pgp -f < %f > %t"
close-hook \\.pgp$ "pgp -fe YourPgpUserIdOrKeyId < %t > %f"

Please note, that PGP does not support appending to an encrypted folder, so there is no append-hook defined.

If you are using GnuPG instead of PGP, you may use the following hooks instead:

open-hook  \\.gpg$ "gpg --decrypt < %f > %t"
close-hook \\.gpg$ "gpg --encrypt --recipient YourGpgUserIdOrKeyId < %t > %f"

Note: the folder is temporary stored decrypted in the /tmp directory, where it can be read by your system administrator. So think about the security aspects of this.