The Mutt E-Mail Client : Configuration : Setting variables based upon mailbox
Previous: Defining aliases for character sets
Next: Keyboard macros

## 3.5. Setting variables based upon mailbox

Usage: `folder-hook` [!]regexp command

It is often desirable to change settings based on which mailbox you are reading. The folder-hook command provides a method by which you can execute any configuration command. regexp is a regular expression specifying in which mailboxes to execute command before loading. If a mailbox matches multiple folder-hook's, they are executed in the order given in the muttrc.

Note: if you use the ``!'' shortcut for $spoolfile at the beginning of the pattern, you must place it inside of double or single quotes in order to distinguish it from the logical not operator for the expression.

Note that the settings are not restored when you leave the mailbox. For example, a command action to perform is to change the sorting method based upon the mailbox being read:

> `

>     folder-hook mutt set sort=threads

> `

However, the sorting method is not restored to its previous value when reading a different mailbox. To specify a default command, use the pattern ``.'':

> `

>     folder-hook . set sort=date-sent

> `

The Mutt E-Mail Client : Configuration : Setting variables based upon mailbox
Previous: Defining aliases for character sets
Next: Keyboard macros