procmail
[Top] [All Lists]

Re: Two small questions / problems

2004-02-22 04:42:15
On Sun, Feb 22, 2004 at 04:46:07AM +0100, Ruud H.G. van Tol wrote:

Toen ik Dallman Ross kietelde, kwam er dit uit:

Boo on me!


    SCMAX = 2147483647
    SPACE = " "
    TAB   = "    "
    WS    = "$SPACE$TAB"


    H_To
    :0
    *$ ^To:[$WS]*\/[^$WS].*
    { H_To = "$MATCH" }

    H_Cc
    :0
    *$ ^Cc:[$WS]*\/[^$WS].*
    { H_Cc = "$MATCH" }

That's fine, and not so far off from what is in
my rc.  (Now I am awake.  I was nodding off last
night at 2 a.m. when I wrote that other.  Still
haven't had enough coffee, though.)

I don't use the first [$WS] at all, because zero
or more of something is still nothing.  But if
you want it as a stylistic marker, that's okay.


    TooMuch = 4  # set your own number

    :0:
    *$ -$TooMuch^0
    *$    $SCMAX^0
    *          1^1  H_To ?? @
    *          1^1  H_Cc ?? @
    red-spam

While trying to fall asleep last night (procmail
before bed is dangerous!), I thought of a sneaky way
to neutralize, for our purposes, the MATCH inside
a condition set.  That way, it could, indeed, all be
done in one recipe.  Of course, "sneaky" isn't necessarily
better.  But I thought this was sort of fun, at least while
in my pre-sleep alpha-phase:


   :0:
   * $ -$SMALL^0 ^To:\/.*
   *         1^1  MATCH ?? @
   * $ -$SMALL^0  MATCH ?? ^^\/.
   * $ -$SMALL^0 ^Cc:\/.*
   *         1^1  MATCH ?? @
   * $ -$LIMIT^0
   red-spam


The third condition is where we're :neutralizing" MATCH
to something certainly not a @.

(We could be *absolutely* certain it's not one if we started
the original match-capture before the : at the end of the
header field.  But I'll wager that in 100,000 spam messages,
we're likely to find zero, or maybe one, with a @ as the first
character after : on a To or Cc header-line.  And most of the
first chars will of course be a space.)

We could improve the above more and set $MATCH to something
positive but non-harmful up-top, thereby eliminating the need
for the score and shell-y expansor ($) on that third line:

   MATCH = .
   :0:
   * $ -$SMALL^0 ^To:\/.*
   *         1^1  MATCH ?? @
   *              MATCH ?? ^^\/.
   * $ -$SMALL^0 ^Cc:\/.*
   *         1^1  MATCH ?? @
   * $ -$LIMIT^0
   red-spam

But now we're just letting our (my) need for trickiness get
out of hand.  That's merely an exercize in thinking through
the problem, not something particularly useful for everyday
application.

No, while the above seems to do it all in one recipe,
your way (close to my actual way practiced in my rc) is
stylistically better.  Better at self-documenting, and not
overwrought with "cleverness" that hides its real purpose
from easy view.

The use of the upper limit in yours is also a plus to
stop needless counting (though that could be incorporated
in this one, too).[1]

Last, we might want to get the total @-count if the message
passed that recipe (count is >= $LIMIT).  Next recipe:

  :0
  { AT_COUNT = $= }


[1] Hooray for the Infinity Shuffle!  :-)

-- 
dman

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail