procmail
[Top] [All Lists]

Re: procmail message body filtering / sorting

1996-04-26 13:20:15

dvazirani(_at_)attmail(_dot_)com (Dilip Vazirani) writes:
I need help with :
How to sort / filter message body with
expressions involving AND / OR conditions.

Also how to sort using nested if then else conditions.

Please send me live examples if possible.
An example of what I am looking for in message body is :
search for Item in message body
next search for TV or VCR in message body 
if found then write mail to TV-VCR file
else if search for radio
if found then write to radio folder.


--------

I would also like to know how to forward the mail in if found condition 

Please send me any live examples for procmailrc file if possible.


First of all, you really should look at the procmailex(5) manpage, as
it covers at least some of the above.  Against the possibilty that your
fingers are broken, I'll provide a rough sketch below of what you're
looking for.  As for asking for 'live' examples, consider that no one
is doing exactly what you describe, such that anything you get will
probably either be a) not exactly what you need, or b) untested.  What
follows falls in the latter of those categories.  To paraphrase the GPL:

    What follows is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



I'm making a large assumption that when you said

        search for Item in message body
        next search for TV or VCR in message body
        ...

you mean that if "Item" _doesn't_ occur in the body, then don't do
anything.  Your text could alternatively be interpreted to mean that
you only want a match if the word "TV" (or "VCR" or "radio") occurs
later on the same line as "Item".  This is doable as well, and only
slightly more complicated, but I'm not going to bother showing it
below.


# Look in the body for "Item".  The 'B' indicates that we're going to
# look in the body, while the 'D' makes the match case-sensitive.
:0 BD
* Item
{
    # We found "item", look for "TV" or "VCR".  Once again, add the 'D'
    # flag for case-sensitivity.  The third line below will *append*
    # the message to the "TV-VCR" file if a match is made.
    :0 B
    * (TV|VCR)
    TV-VCR

    # Okay, no match on TV or VCR, how about "radio"?
    :0 B
    * radio
    radio
}


The mail forwarding can be accomplished by adding a recipe with
the 'A' flag, thus 'chaining' it off another recipe, to which you
add the 'c' flag.  The exact placement in the above depends on the
conditions you want the mail forward.  Do you want it forwarded
whenever the word "Item" occurs in the body?  Or perhaps you want
to forward a message if it was written to the 'TV-VCR' file?

Philip Guenther

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