procmail
[Top] [All Lists]

Re: Redirect Based on any header

1997-05-01 11:15:00
Does anyone know how to redirect mail to a folder based on who the mail
was sent to? 

I realize I can split this out header by header as follows, but I'm not
sure how this would cover mail sent to listservs and bcc's.  I am just
looking for a recipe that says any use of user(_at_)virtual(_dot_)com in the 
header
(except From field) should execute the said action. 

The first thing you need to do is take a close look at the procmail man
pages -- in particular, procmailrc and procmailex.  You'll find the
following section especially appropriate:

MISCELLANEOUS
     If the regular expression contains `^TO_' it will be substi-
     tuted by `(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope
     |Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?)', which
     should catch all destination specifications containing a
     specific address.
 
     If the regular expression contains `^TO' it will be  substi-
     tuted by `(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope
     |Apparently(-Resent)?)-To):(.*[^a-zA-Z])?)', which should
     catch all destination specifications containing a specific
     word.

You'll probably want to use the first form (^TO_), as you're trying to
match an address.  This would make your recipe look like:

  :0
  *  ^TO_user(_at_)virtual(_dot_)com
  ! user(_at_)real(_dot_)com

Notice that I've taken out the second colon on the recipe header; you
don't need :0:.  The second colon implies the use of a local lock file,
and since you're forwarding this out via sendmail a local lock file does
nothing.

Also note that you could have combined your two example recipes into a
single recipe:

  :0
  * ^(to|cc)(_dot_)*user(_at_)virtual(_dot_)com
  ! user(_at_)real(_dot_)com

This may have been obvious from the expansion of ^TO_, given above, but I
figured it was worth mentioning -- perhaps you'll find the technique
useful elsewhere.

-- Lars

---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University

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