procmail
[Top] [All Lists]

Re: weirdness with trailing ^^ and with ^.*$

1996-07-18 13:59:57
Stephen van den Berg ... well, answered all my questions, but

I had written:

| >Long story, but I was looking for a search expression that would always be
| >found twice, regardless of the message text.  (No, it wasn't simply to score

[text of mine that Stephen did not quote:]

   ... 2 points; that is easy enough with

   * 2^0

   I tried ...

| > * 1^1 H ?? ^(From .*)?$
| 
| >thinking for sure that the header would always contain one From_ line and
| >one empty line, but it counted three matches and scored 3!

Stephen responded,

| Simplify it to:
| 
|       * 1^1 H ?? ^From .*$
|       * 1^1 H ?? ^$
| 
| Which is equivalent to what you wrote above.

Well, it is equivalent to what I wrote but not to what I want.  I wanted a
single expression that is guaranteed to match exactly twice.

As Stephen wrote later:

| So the simplest search that matches twice would be:
| 
|   * 1^1 H ?? ^$

... provided that the incoming message is in decent shape.  (What if it has
no blank lines at all?)

Anyhow, what I need is a way to find two matches on a single expression
because in what I was trying the multiplier wasn't 1.  Here is the problem:
Jim Osborn asked how to save a negative value of $= in a variable, because
an action dependent on a recipe with a negative (or zero) score will not be
executed.  I had suggested this, which will save the score regardless of
sign:

 :0
 * multiplicand^multiplier condition
 * multiplicand^multiplier condition
 * ... etc.
 { } # standard procmailrc no-op

 SAVED_SCORE = $= # quick, before it's clobbered

That brought a question to my mind: suppose one wants to save a score in
order to subtract it from the cumulative score in a future recipe (even if
the saved amount is negative and that means an increase to the later recipe's
score)?

 * $ -$SAVED_SCORE^0

works wonderfully if $SAVED_SCORE is positive or zero, but if it is negative
procmail sees it as

 * $ --[absolute value of $SAVED_SCORE]^0

and, since legitimate multiplicands do not begin with "--", it finds an
error.

It occurred to me that (-2)^0 + (-2)^1 = -1, so if we can find an expression
that is guaranteed to match exactly twice,

 * $ $SAVED_SCORE^-2 regexp_that_matches_twice

reliably subtracts $SAVED_SCORE (regardless of its sign) from the current
cumulative score.

This puppy is a lock:

 * $ $SAVED_SCORE^-2 !? exit 2;

but it has the overhead of running a shell.  (Remember, I said from the first
that this was a long story.)

So I was looking for an expression that will always match twice.  Dividing
the condition into two searches:

 * $ w^x a_regexp_that_always_matches_once
 * $ w^x another_regexp_that_always_matches_once_or_the_same_one

will not have the desired effect.  I needed ONE condition that will register
two matches.

| procmail reads any $^ sequence to be equivalent with ^^
| So, ($)$^^ becomes equivalent to (^)(^^)(^), which, obviously, can *never*
| match.  This will be fixed in the upcoming version.

That clears up the $^^ problem, and the explanations that search areas have
putative newlines added at each end and that matches can overlap by sharing
a bordering newline pretty much answers everything else.  Thank you, Stephen.

<Prev in Thread] Current Thread [Next in Thread>