procmail
[Top] [All Lists]

Re: boolean usage

1996-03-12 16:40:03
Tim Pickett asked,

| Or in procmail syntax, if the "and" condition version is
| 
| :0
| * condition1
| * condition2
| action
| rest_of_file
| 
| Then the "or" condition version can be written as
| 
| :0
| * ! condition1
| * ! condition2
| {
|   rest_of_file
| 
|   :0           # Would these lines be needed?
|   DEFAULT      # They are done by default at the end of
|   :0           # the RC file but does the E flag in the
|   ORGMAIL      # condition below know or care that this is
|                # inside a block?
| }

Well, first, it has to be $DEFAULT and $ORGMAIL, or the saves will be done
to $MAILDIR/DEFAULT and $MAILDIR/ORGMAIL, and second, those saves need local
lockfiles.

The `E' flag does look back at its own nesting level, though, so you probably
do not need to worry about saves to $DEFAULT or $ORGMAIL anyway.

| :0 E
| action
| 
| Has anyone tried this?  Does it work?  If there are flaws in it,
| would they be relatively easy to overcome?

The greater flaw is that rest_of_file may have more instances of ORing, so
the nesting of braces will get very hairy to maintain (and to get right in
the first place).  The lesser flaw is that, without a folding editor, you're
in trouble for maintenance, because the ORed conditions and the action on
them are separated by great amounts of other text in your rcfile.

As long as your version of procmail is recent enough to understand braces and
the `E' flag, which Tim is already using, here's a way to do ORing that is
much easier on human brains:

  :0
  * ! condition1
  * ! condition2
  { }
  :0E
  action_on_condition1_or_condition2

and then you don't have to put the rest of the rcfile inside braces nor save
the OR action for long, long afterward (where you'd need a folding editor to
see the action and the ORed conditions together).

And yes, I've tried it, and yes, it works (even with more than two condi-
tions).  I use it all the time.

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