procmail
[Top] [All Lists]

Re: ORing conditions

1997-05-08 13:51:00
Axel Thimm asked,

| Finaly I though of inverting the conditions, e.g.
| :0
| * ! rule1
| * ! rule2
| { } # empty action
| :0 E
| {
|   ...
| }

| Does this work (any possible pitfalls)? What is the preferred method?

It works like a charm; there are other ways to OR conditions (for example,
with scoring), but this one is the easiest to type in, I feel, and the
easiest to edit when you want to add or remove alternatives.

[One huge exception here: if any condition is weighted, we have a whole
 different situation, which I'm not going to try to cover in this post.]

For efficiency's sake, put (the negation of) the most common situation first
so that procmail can jump down to the else clause as soon as possible after
seeing that a message fails the negation of a rule (and thus satisfies the
rule).

Note, that, if the two rules are regexps to search for,

 :0
 * regexp1|regexp2
 action

is simpler yet.  Also, if the two rules are exit code conditions and the
more common one requires a shell and your $SHELL understands "||",

 :0
 * ? rule1 || rule2
 action

will do the job.  However, when you cannot combine all the rules into one
condition, invert/and/no-op/else/action is, in my opinion, the best way.

Examples of rules that cannot be combined into one condition:

  two regexps with different search areas
  a size test (even with another size test)
  a non-negated regexp and a negated regexp (unless one of them can be
    phrased the other way)
  an exit code and an inverted exit code (unless one of the commands can be
    told to invert its own exit code, like test or lockfile)
  a regexp and an exit code

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