procmail
[Top] [All Lists]

Re: multiple addresses ?

1999-11-21 03:42:48
On Sat, 20 Nov 1999 11:10:49 -0800 (PST), "S.Toms"
<tomas(_at_)primenet(_dot_)com> wrote:
On Sat, 20 Nov 1999, James Stevenson wrote:
 js> how can i get procmail to tell if there is more than one address
 js> in a to box and do something if there is a certin address in
 js> there ?

(Does "to box" refer to the To: header? Or a mailbox, perhaps?
Assuming the former here ...)

Note that there can be several To: headers, like this:

    To: recipient one
    To: recipient two

Normally, if you want to look for two addresses in the same physical
header line, they will be separated by commas. But there can also be
commas which are not address separators:

    To: me (not you, stupid)
    To: another example, maybe <e(_dot_)g(_dot_)(_at_)example(_dot_)com>

Theoretically, these constructs are impossible to handle with mere
regular expressions (universally, i.e. you want a solution which
handles all possible cases, including nested parentheses and all the
other intricacies of RFC822) but you can probably get away with
something that doesn't work all the time, especially if it's only for
your own private use.

So in very simple terms, you could have two recipes for the two
distinct cases of (a) more than one To: line and (b) a To: line with a
comma in it.

    :0  # case a
    * ^To:(.*($))*To:
    { action }

    :0  # case b
    * ^To:.*,
    { action }

If { action } is anything more complex than a simple save or forward,
perhaps you want to change it into something like this instead:

    :0  # if neither of the two are true, do nothing
    * ! ^To:(.*($))*To:
    * ! ^To:*,
    { } # note: there +must+ be a space between the braces

    :0E # else, do this:
    { action }

but that's merely simpler to maintain, not necessarily "better" in any
other sense.

Finally, you should probably be aware already that there is no
meaningful correspondence between "who a message is for" and the
actual headers you see. A message could have been Bcc:ed to someone
(or even yourself!) leaving no trace of this information in the
headers. Also, trivially, you may want to cope with Cc: as well as To:
if you are trying to figure out who received a message (+and+ left a
trace in the headers). The ^TO macro is a nice shorthand for most
plausible variations (Cc:, Resent-To:, etc):

    :0
    * ! ^TO(.*($))*^TO
    * ! ^TO.*,
    { }
    :0E
    { action }

For even more tricky things, as S. Toms, points out:

If [you're] looking for a particular [quantity] of addresses in the
To line, there have been several posts in the recent past regarding
this. Don't recall where the archives are though, sorry.

At <http://www.rosat.mpe-garching.mpg.de/mailing-lists/procmail/>
you'll find a searchable archive of postings to this mailing list.
A pointer to an earlier thread about this very topic is in the
"pearls" section of <http://www.iki.fi/era/procmail/links.html>;
look for "Counting the Number of Recipients".

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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