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
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:
which would execute the given command when sending mail to firstname.lastname@example.org.
send-hook '~t ^me@cs\.hmc\.edu$' 'my_hdr From: Mutt User <user@host>'
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.