When searching/limiting mesages, Mutt provides several built-in fast patterns for common headers such as From, To, Cc, References, and Message-ID. For less common headers, it provides the fallback ~h pattern, but this is much slower. (And completely unusable over IMAP: for that you're better off using server-side searches with =h).
Sometimes you commonly search for one particular header over and over, or would like to see that header listed in the index. This post describes a hack you can use to do this quickly, using the spam detection built into Mutt.
For this article, let's say you commonly search for a header called "Importance" and would also like to see the value of this header in your index.
If you are using IMAP, the first thing you need to do is add the header to the $imap_headers setting (note it must be uppercased):
Next, you use the spam command to match the header and record its value:
spam "^importance:\\s*(.*)" "%1"
This takes the raw value of the header, but of course you could do your own transformation:
# Your own flags: spam "^importance:\\s*high" "!" # Or just the first letter: spam "^importance:\\s*(.)" "%1"
Once you've done this you can now use the ~H pattern to search/limit against it, and the %H format string to display the value in your index. Even better, these values are cached in the memory, along with the from/to/cc/subject so searches are fast.