procmail
[Top] [All Lists]

Re: How do you 'OR' conditions

1995-12-22 16:25:49
Nathan Edwards suggested:

| > From: Era Eriksson <reriksso(_at_)cc(_dot_)helsinki(_dot_)fi>

| My personal preference is to use weighted scoring:
| 
| :0
| * -99^0
| * 100^0 Condition-1
| * 100^0 Condition-2
| * 100^0 Condition-3
| Action

As Alan Stebbens commented, it's enough to do his without the unconditional
negative starting score (since a score of 0 is still a failure):

  :0
  * 1^0 Condition-1
  * 1^0 Condition-2
  * 1^0 Condition-3
  Action

However, both methods share an inefficiency: if Condition-1 is matched, 
procmail still has to go on testing the remaining conditions.  Why bother?
Matching any of them is enough.  If all the conditions are to be ORed,
procmail should jump ahead to the action line as soon as it finds one match.

There are two ways I've thought of to get around that.  First method:

max=2147483647 # maximum procmailsc weight

  :0
  * $ $max^0 Condition-1
  * $ $max^0 Condition-2
  * $ $max^0 Condition-3
  Action

(Or you could leave the weight of the last one at 1 or any other positive
number.)  At the first match, procmail will jump ahead to the action.

Second method:

  :0
  * ! Condition-1
  * ! Condition-2
  * ! Condition-3
  { } # this action line is a safe no-op
  :E
  Action

A match to Condition-1 will cause a mismatch on !Condition-1 and an immediate
jump to the else clause.  A mismatch on Condition-1 will be a match on 
!Condition-1 and a test of the next condition.

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