dattier(_at_)wwa(_dot_)com (David W. Tamkin) writes:
Philip Guenther suggested for Ken Marsh [comments deleted; see Philip's
original post if you want to reread them],
| :0
| * ^Resent-(From|Date|To|Cc|Message-Id):
| { R="Resent-" }
| :0E
| { R= }
|
| :0
| * -19^0
| * ^^\/
| * 1^0 $ ^${R}To:\/.*
| * 1^1 MATCH ?? ,
| * ^^\/
| * 1^0 $ ^${R}Cc:\/.*
| * 1^1 MATCH ?? ,
| { EXITCODE=77 HOST }
The problem here is that if there are more than one ${R}To: header or
more than one ${R}Cc: header, only recipients in the first of each will
be counted. It can be slightly improved:
Well, I'd be tempted to simply drop any message that had more than one
${R}To: or ${R}Cc: header, just on principle. Similar for Apparently-To:
headers.
* ^^\/
* 1^1 $ ^${R}To:\/.*
* 1^1 MATCH ?? ,
* ^^\/
* 1^1 $ ^${R}Cc:\/.*
* 1^1 MATCH ?? ,
That will count one address for every ${R}To: header except the last
and all the addresses in the last one, and likewise for the ${R}Cc:
headers.
So far the only way I see to do this without an external program is a
recursive INCLUDERC, and those things can be vicious.
That sounded like a challenge, so I crafted the following. It works
for the tests I threw at it, and should be a good way to see how to do
some procmail tricks. In your main .procmailrc put:
# Put the regexp of the lines to examine in REGEXP
:0
* ^Resent-(From|Date|To|Cc|Message-Id):
{ REGEXP = "^Resent-(To|Cc):" }
:0E
{ REGEXP = "^(To|Cc):" }
# Put the string to match against in HEADER
:0
* ^^\/.*^^
{ HEADER = $MATCH }
# Count'em
INCLUDERC = count_comma_sep.rc
# Beware: if there were no matches, then COUNT will be unset, so use
# ${COUNT:-0} ala Bourne shell.
:0
* $ ${COUNT:-0}^0
* -19^0
{ EXITCODE=77 HOST }
Then in the file count_comma_sep.rc put:
# Goal: count the number of commas separated items in HEADER at the
# end of the lines that match $REGEXP. COUNT will keep the running
# total.
# Clear MATCH, then count the items in the first match, if any.
MATCH=
:0
* 1^0 HEADER ?? $ $REGEXP\/.*
* 1^1 MATCH ?? ,
{
# Okay, increment COUNT by $=. Beware, COUNT may be unset, so use
# ${COUNT:-0} to get it's value if any, or zero if none.
:0
* $ $=^0
* $ ${COUNT:-0}^0
{ COUNT = $= }
# Now, do we need to recurse? Only if there's more than one
# match of $REGEXP.
:0
* -1^0
* 1^1 HEADER ?? $ $REGEXP
{
# We do. We'll need to reset HEADER to only contain everything
# *after* the first match.
:0
* HEADER ?? $ $REGEXP.*($)\/(.*($)?)*
{ HEADER = $MATCH }
# Recurse!
INCLUDERC = $_
}
}
Philip Guenther