procmail
[Top] [All Lists]

Re: subject change via procmail

1997-09-17 11:44:43
The part about figuring out by what mailing list you received a
particular email is not as easy.  It can be done, but some
assumptions and decisions based on these may be required.

First, how do you know by which mailing list you are going to
receive a piece of mail?

I dont mean mailing LISTS - these are NORMAL Forward eMail
Adresses. For example Dave(_at_)Global-OWL(_dot_)com goes to
S(_dot_)Dawitz(_at_)Bielefeld(_dot_)Netsurf(_dot_)De <- my REAL eMail Adress 
So the filter
must ONLY examine the original SEND-TO field. It does NOT depend on
the sender

Another example:
Dave(_at_)Global-OWL(_dot_)com <- privat
Angebot(_at_)Global-OWL(_dot_)com <- Angebot means offer
Info(_at_)Global-OWL(_dot_)com <- the mean company eMail

now, ALL these 3 forward eMail addresses send the mail to
S(_dot_)Dawitz(_at_)Bielefeld .Netsurf.De.  But - BEFORE they are directed 
there
- i want to use PROCMAIL to put the ORIGINAL reciever ( where the mail
was send to at first - for example Info(_at_)Global-OWL(_dot_)com) to the 
subject
- no matter WHO wrote it.  The reason for al that is, that all mails
are send to my mobile phone via SMS ( 160 chars Short Messaging System
here in Europe ) and i cant see the Header there.  So i dont know,
where this mail was written to. Was it only a privat eMail or was it a
eMail to our company. Thats the point ...
...
So, do you understand ? Any suggestions now ?

Yes.  Read the man page of "procmailrc" to understand the syntax of the
recipe file below, which implements what you would like to do:

cat <<'EOF' >/usr/local/lib/procmail/tagit.rc

    # tagit.rc -- recipe file to tag the subject line

    # Check for the mail being addressed to certain aliases, and if one
    # of our aliases has been used, insert a corresponding tag onto the
    # subject which will help identify the original destination address.

    :0
    * ^To:(.*\<)?Dave(_at_)Global-OWL\(_dot_)com
    { TAG=dave(_at_)go }

    :0E
    * ^To:(.*\<)?Angebot(_at_)Global-OWL\(_dot_)com
    { TAG=angebot(_at_)go }

    :0E
    * ^To:(.*\<)?Info(_at_)Global-OWL\(_dot_)com
    { TAG=info(_at_)go }

    # ... other similar recipes for any more aliases

    # If TAG is set, place it in front of the current subject.
    # If there is no current subject, use <no subject> by default.
    MATCH
    :0 fhw
    * TAG ?? [^ ]
    * 1^0 ^Subject: *\/[^ ].*
    * 1^0
    | formail -I "Subject: $TAG - ${MATCH:-<no subject>}"

    # Other recipes as you desire..

    # Finally, forward the modified mail to the real destination
    :0
    ! S(_dot_)Dawitz(_at_)Bielefeld(_dot_)Netsurf(_dot_)De
EOF

To cause this procmail filter to be invoked, you can set up your aliases
like this (assuming that you are using sendamil):

dave:    "|/usr/local/bin/procmail -m /usr/local/etc/tagit.rc"
angebot: "|/usr/local/bin/procmail -m /usr/local/etc/tagit.rc"
info:    "|/usr/local/bin/procmail -m /usr/local/etc/tagit.rc"

If your system manager has configured "smrsh" or some other restricted
shell for "Mprog" (in sendmail.cf), then the path to procmail will have
to be added to the list of "approved" delivery/filter programs.

Then, assuming that the system is "global-OWL.com", mail to
"dave(_at_)global-owl(_dot_)com" will get filtered, the subject tagged with
"dave(_at_)go", and then forwarded as defined in the recipe file.

As I said earlier, this recipe has some subtleties which you may not
appreciate without having read the "procmailrc" man pages well.

Of course, there are other ways to apply the procmail filtering.  You
could use a global filter in /etc/procmailrcs; you could have individual
accounts for these "aliases"; you could modify sendmail.cf to apply the
filtering before delivery or forwarding; etc.  As David Tamkin has
already said, "there is more than one way to skin a cat" (actually, he
used a pun and then had to explain it :^).

G'luck.
___________________________________________________________
Alan Stebbens <aks(_at_)sgi(_dot_)com>      http://reality.sgi.com/aks

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