procmail
[Top] [All Lists]

Re: Detecting multiple To: headers?

1999-06-02 14:50:59
You asked:
Is there a easy way to detect number of recipients of a message? I.e. It
should detect there are 5 recipients in the following message:


  From: Doe John <doe(_at_)some(_dot_)edu>
  To: Person1  <person1(_at_)some(_dot_)com>, "Person2 LastName" 
<person2(_at_)some(_dot_)edu>
  cc: Person3 <person3(_at_)some(_dot_)com>,
      Person4 <person4(_at_)some(_dot_)com>,
      Person5 <person5(_at_)some(_dot_)com>
  Subject: Re: Welcome to our list!

There is no easy way to reliably count the recipients. You can reliably sum
the number of to, cc, apparently-to, ... headers, and you can count the
number of commas in each and add that to the total, but there are still
problems.

You cannot rely on commas as a separator of addressee names because there may
be comments with commas which do not serve to separate addressee names. Even
if you remove comments (and please share your method) there may be list names
( friends:; ) which may or may not generate addresses. You cannot rely on @
for the same reasons, along with the problem of local addresses with no @.

Nonetheless, you can get a reasonable count (for some values of reasonable)
with something akin to this:
      :0
      * 1^1 ^((resent|apparently)-)?(to|b?cc):\/.*
      * 1^1 MATCH ?? ,
      { MAYBETO=$= }

(Note: this counts both resents and apparentlys. Both are rare, and rarer
still is to find both in the same message.)

This will count each of the selected headers, and will add in the number
commas in the last of those headers. If there are 2 To: headers, the first of
which has 100 addresses and the second of which has 1 address (and no
commas), this will score 2. If the first has 1 address, and the second 100
addresses (and excatly 99 commas), this will score 101. On your example, it
scores 4.

I'd love to see a relatively inexpensive, accurate recipe.

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com