procmail
[Top] [All Lists]

Re: subject change via procmail

1997-09-17 09:36:44
    > At first, where can i find a documentation ? Especially for the
    > commands.rc file ?

Within the "commands.rc" file: read the comments and then read the
source.  If you do not understand procmail recipe syntax, you should
read "procmailrc", as well as "procmail", "procmailsc" and "procmailex".

    > If you have a little bit time, please read the
    > following. Otherwise tell me only the URL for the doku !
    > 
    > procmail is installed at our web hosting company. usually it is
    > used there for auto responders. but i think, i can do something
    > other with procmail, too:
    > 
    > we have variuos eMail addresses, like info(_at_)global-owl(_dot_)com,
    > dave(_at_)global-owl(_dot_)  com and info(_at_)dekora-design(_dot_)com 
...  these eMails
    > all go to some POP eMail adresses AND (!) all go to my mobil phone
    > via SMS.  Actually i can't see, to whom the were written
    > originally. (which may be VERY important )
    > 
    > What I'm thinking of now, is to change the SUBJECT, so if a eMail
    > was written to 'Info(_at_)Global-OWL(_dot_)com' and the Subject was 'Test
    > eMail' - the subject will be changed to 'Info(_at_)go - Test eMail' for
    > example.
    > 
    > I think, that this job can be done with procmail, but i need
    > detailed informations about the syntax.
    > 
    > Perhaps, there is already a script, which can do, what i want ?
    > please tell me, what you think about that.

The part of inserting something into the subject is easy.

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?  

The design of any filter depends upon the context in which the procmail
filter is going to be run.

If you have many mailing lists all coming to your personal email
address, then you must use the addresses within the "To:", "Cc:", and
sometimes "Apparently-To:" header fields to figure out which mailing
list submitted mail.  

It is possible for two or more mailing lists to be involved:

    To: info(_at_)global-owl(_dot_)com
    Cc: info(_at_)dekora-design(_dot_)com

In this case, which address should appear in the subject?  Do you prefer
to prioritize by the header (ie: To: over Cc:), or by the list name
(info(_at_)global-owl(_dot_)com over info(_at_)dekora-design(_dot_)com), or 
both?

In any case, here's a sample procmail recipe file for use in a personal
mail filter, doing something like you ask:

    # Define HEADERS to include those headers you care about.  Pick one
    # of the definitions below (and remove or comment out the others).
    HEADERS='^To:(.*\<)?'                       # use only To: header
    HEADERS='^(To|Cc):(.*\<)?'                  # use either To: or Cc: headers
    HEADERS='^((Apparently-)?To|Cc):(.*\<)?'    # use any of To:, Cc:, or 
Apparently-To:

    # Examine headers, create a subject tag if we recognize a list
    :0
    * $ ${HEADERS}info(_at_)global-owl\(_dot_)com
    { TAG=info(_at_)go }

    :0E
    * $ ${HEADERS}info(_at_)dekora-design\(_dot_)com
    { TAG=info(_at_)dd }

    :0E
    * $ ${HEADERS}dave(_at_)global-owl\(_dot_)com
    { TAG=dave(_at_)go }

    #... other recipes added for additional lists

    # now, if TAG is set, insert it into the subject 
    MATCH
    :0 fhw
    * TAG ?? [^ ]
    * ^Subject: *\/[^ ].*
    | formail -I"Subject: $TAG - ${MATCH:-<no subject>}"

This recipe is full of subtleties.  If you wish to understand them, you
really need to read the man pages "procmailrc" and "procmailsc", and
then peruse the procmail archives.  

I'll give you some hints.  Look up, in the "procmailrc" or "sh" man
pages, the meaning of:

    somevar     (a variable standing all by itself, surrounded by whitespace)
    somevar ?? someregexp
    the regular expression: [^ ]
    regular expressions (in general)
    the special, procmail regular expression: \/
    `$' recipe flag
    `f' recipe flag
    `h' recipe flag
    `w' recipe flag
    the MATCH variable
    the shell expression: ${somevar:-alternate value}

Good luck

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

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