On Sun, Mar 29, 2026 at 02:29:41PM +0200, Sébastien Hinderer wrote:
Kevin J. McCarthy (2026/03/29 20:05 +0800):
On Sun, Mar 29, 2026 at 12:45:13PM +0200, Sébastien Hinderer wrote:
> In my configuration I have hooks like
>
> save-hook '~f amazon.fr' '=amazon/'
>
> As such, I am assuming that a mail sent from any address *ocntaining*
> amazon.fr, like for instance [email protected], would
> match.
>
> Is there a way to make the regexp more restrictive and to match those
> messages where amazon.fr appears at the end of the address?

Yes, see the example at http://www.mutt.org/doc/manual/#pattern-hook for an
example. It shows send-hook, but this also works for save-hook.

Oh ye, indeed! But then is it documented somewhere that ^ and $ work? Is
it on purpose that they are not mentionned in the part of the manual
about regular expressions?

Yes, at http://www.mutt.org/doc/manual/#regexp see the sentence:
  The period “.” matches any single character. The caret “^” and the
  dollar sign “$” are metacharacters that respectively match the empty
  string at the beginning and end of a line.

Also notice in the example how "." is backslashed, because that matches any
character.

I indeed didn't pay attention so far. I think I was under the wrong
impression that, because the pattern is between single quotes, . is
taken litteraly.

From a "shell quoting" point of view, single quotes make everything be un-evaluated. But regular expressions are an additional layer of complexity, evaluated after the string is processed by mutt.

So we agree that, for isntance int he example you show, the quotes are
not at all optional and that, although they are there, the special
characters occurring in regular expresisons between these quotes do need
to be escaped to get back their ordinary meaning?

Without the single quotes, it gets trickier, because you have two layers to go through. I definitely recommend you use single quotes or you'll have to double the backslashes. See the second example line at http://www.mutt.org/doc/manual/#save-hook for what that looks like.

--
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA

Attachment: signature.asc
Description: PGP signature

Reply via email to