Era beat me to it. I didn't like the looks of Philip's posting either. The
name HEADERLINES didn't agree with the regexp, which only picked up a
single line, and I didn't see any reason to pick up the trailing <eol>. I
fixed it a bit differently. The major differences are:
1) It doesn't invoke the incursive procedure unless there is a target
header with a comma.
2) It doesn't slurp a lot of header lines into a variable at once, but
instead looks at one at a time.
3) It doesn't provide the same opportunity for an 'easy out' when the
limit is exceeded.
(To use this, remove the comments, at least from the condition lines. $PMRC
is a directory which holds ancillary rc files, $MAXRECIP is the maximum
number of recipients I recognize before flagging a message as suspicious,
and $RULE is a list of the rules which have been violated by a suspicious
message.)
In the main rc body:
############################################### spam ................... RECIP-#
## Count number of recipients. This adds one for each named header, and, if ##
## any named header has a comma, uses a recursive routine to count commas. ##
## This overcounts if any commas are present in comments, which are allowed. ##
## Some folks sum Resent-xx *or* non-Resent-xx headers. This sums 'em all. ##
################################################################################
COMMAS=0 ## initially none
THDR_=((resent|apparently)-)?(to|b?cc): ## to headers
:0 ##
* $ ^\/$THDR_.*,.* ## any commas?
INCLUDERC=$PMRC/commacnt.rc } ## use recursive counter
:0 ## add
* $ $COMMAS^0 ## comma count to
* $ 1^1 ^$THDR_ ## count of headers
* $ -$MAXRECIP_^0 ## less max allowed (+ if toooo many)
* -2147483647^0 ## less bigmin (large -, not bigmin, if too many)
* 2147483647^0 ## add back bigmax if still here
* $ $MAXRECIP_^0 ## add back MAXRECIP to make # right
{ RULE="$RULE RECIP-$=" } ## add recipient violation to broken rules list
File $PMRC/commacnt.rc:
## commacnt.rc #################################################################
:0 ##
* 1^1 MATCH ?? , ## count commas in this matched line
* $ $COMMAS^0 ## add previous count, if any
{ COMMAS=$= } ## save new count
:0 ## now, see if there are any more
* $ $\MATCH(.*$)*\/$THDR_.*,.* ## any more
{ INCLUDERC=$_ } ## curse again!
Looking at this again, I believe that the trailing ,.* can be reduced to ,
in both places.
On Wed, 02 Jun 1999 15:37:45 -0500, Philip Guenther
<guenther(_at_)gac(_dot_)edu>
wrote:
> Tony Lam <Tony(_dot_)Lam+procmail(_at_)eng(_dot_)sun(_dot_)com> writes:
>> Is there a easy way to detect number of recipients of a message?
> Here's the last I mail I have from that thread, with one small bugfix
> applied. In this case the goal was to bounce any message with more
> than 19 recipients.
<...>
>> # Put the string to match against into $HEADERLINES
>> :0 # H is implicit
>> * $ ()\/$REGEXP(.*)$
There seems to be a typo here. In another version I found in the
archives, this was
> # Put the string to match against into $HEADERLINES
> :0 # H is implicit
> * $ ()\/$REGEXP(.*$)*
--
Rik Kabel Old enough to be an adult
rik(_at_)netcom(_dot_)com