Re: [EXIM] Filtering

Top Page
Delete this message
Reply to this message
Author: Gareth McCaughan
Date:  
To: Max Caines
CC: exim-users
Subject: Re: [EXIM] Filtering
Max Caines wrote:

> I am trying to construct a system filter expression to match a value in
> dollars, to look like this:
>
>     if $h_Subject: matches "\\$[0-9]+"

>
> I have tried it with numbers of backslashes before the '$' ranging from
> zero to 4, and (in desperation) making it a character class (e.g.
> "[\\$][0-9]+"). Either it won't parse; or it does, but doesn't match a
> header like 'Make $150 now'. I can't work out from the documentation what
> the expression _should_ look like. Can anyone tell me?


This is really horrible. Here's how it works.

1. Inside "..." \ needs to be backslashed to inhibit escape interpretation.
2. When string expansion may happen, $ must be backslashed to stop it,
and so must \ (because unbackslashed \ is used for inhibiting expansion).
3. In regexps, $ needs to be backslashed to stop it meaning EOL.

So: We want to match $. By (3) we need the regexp \$. By (2)
we need that to look like \\\$ (that's a backslashed \ plus a
backslashed $). By (1) all those \s need to be doubled, giving
\\\\\\$. Ouch.

On the other hand, note that

| If the text contains no white space then it can be typed
| verbatim. However, if it is part of a condition, it must
| also be free of round brackets [...]


So you can avoid both 1 and 2 by saying

    if $h_Subject: matches \$[0-9]+


but this won't work if you need spaces in your matching string.

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
gjm11@???  Cambridge University, England.


--
*** Exim information can be found at http://www.exim.org/ ***