procmail
[Top] [All Lists]

Re: Simple condition efficiency

1997-09-16 20:22:13
Bill Moseley asked,

| Will Procmail quit checking the condition lines when a condition fails?

Yes, unless the condition was weighted.  Unweighted conditions are ANDed;
one miss and procmail bails out on the whole recipe.

| More specific example.
| 
|    # Check if message is not addressed to me, or if the header
|    # mentions any of my currently subscribed lists.
                ^^^^^^
If you mean "any of", you've coded it wrong.  I think you coded it right,
Bill, but you meant to say "none of" in the comment.

|    :0
|    * ! ^TO_moseley
|    * ! procmail
|    * ! list-ABC
|    * ! list-123
|    * ! list-XYZ

You could condense those five conditions to

     * ! ^TO_moseley|procmail|list-(ABC|123|XYZ)

|    {
|       # Not from anyone I know, or addressed to me.
                                  ^^
Again, if you meant "or", you've coded it wrong.  I'm guessing you coded
it right but meant "nor" in the comment.

|       # Could be spam or I might be on a unknown distribution list.

Or you could have just joined another list and not yet seen anything from
it to know what its headers will look like, so you haven't yet keyed your
.procmailrc to recognize it.

|       INCLUDERC=$PMDIR/checkspam.rc
|    }

That would work; common practice, however, is to put recipes for filing
mail from lists (and, per Bill's preferences, anything mentioning procmail
in the head gets treated the same as mail from this list) first; then the
only remaining condition to consider there would be unexpected blind car-
bons: * ! ^TO_moseley.  This method is good if you get much more spam than
legitimate mail (including mail from list subscriptions as legitimate) and
you want procmail to deal with spam right away.  I belong to several very
active mailing lists, so I actually receive more pieces of legitimate mail
than pieces of spam.

One way to get the best of both worlds is this:

  * $ ! ()\/(^TO_$LOGNAME|procmail|list-(ABC|123|XYZ))

because then, if the regexp matches (and thus the negated condition fails
and you don't detour into $PMDIR/checkspam.rc), MATCH is already set to the
name of the mailing list, and you can do further tests by just examining
MATCH (or a variable you copy it into) instead of a repeating a complete
head search.  [I prefer to use the variable $LOGNAME rather than hard-coding
my name because then others can use the code, and I can use it unchanged on
sites where my logname is different, and if my logname is changed my
.procmailrc will keep up with it.]  For example (I've separated the
conditions into two lines so that, per Bill's preferences, a mention of
procmail in the head will get the message into the Procmail List folder,
even if a match to $^TO_$LOGNAME is also present and appears sooner):

 MATCH # make sure it's unset going in
 :0
 * ! ()\/(procmail|list-(ABC|123|XYZ))
 * $ ! ^TO_$LOGNAME
 { INCLUDERC=$PMDIR/spamcheck.rc }

#The next recipe has an `E' flag, so it will be examined only if the
#preceding one didn't match; thus if $MATCH was set inside spamcheck.rc,
#it won't hurt anything here, and a value for $MATCH set in spamcheck.rc
#won't be mistaken for a list name:

 :0E: # MATCH is non-null only if it matched a list name
 * MATCH ?? .
 $MATCH

#Remaining recipes will be read only for two types of mail: those that met
#$^TO_$LOGNAME but not any expected list name, and those that went through
#spamcheck.rc but came out undelivered.

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