The Mutt E-Mail Client : Advanced Usage : Using Hooks : Message Matching in Hooks
Previous: Using Hooks
Next: External Address Queries

## 4.4.1. Message Matching in Hooks

Hooks that act upon messages (`send-hook, save-hook, fcc-hook, message-hook`) are evaluated in a slightly different manner. For the other types of hooks, a regular expression is sufficient. But in dealing with messages a finer grain of control is needed for matching since for different purposes you want to match different criteria.

Mutt allows the use of the search pattern language for matching messages in hook commands. This works in exactly the same way as it would when limiting or searching the mailbox, except that you are restricted to those operators which match information mutt extracts from the header of the message (i.e. from, to, cc, date, subject, etc.).

For example, if you wanted to set your return address based upon sending mail to a specific address, you could do something like:

> `

>     send-hook '~t ^me@cs\.hmc\.edu$' 'my_hdr From: Mutt User <user@host>'

> `

which would execute the given command when sending mail to me@cs.hmc.edu.

However, it is not required that you write the pattern to match using the full searching language. You can still specify a simple regular expression like the other hooks, in which case Mutt will translate your pattern into the full language, using the translation specified by the $default_hook variable. The pattern is translated at the time the hook is declared, so the value of $default_hook that is in effect at that time will be used.

The Mutt E-Mail Client : Advanced Usage : Using Hooks : Message Matching in Hooks
Previous: Using Hooks
Next: External Address Queries