dvazirani(_at_)attmail(_dot_)com (Dilip Vazirani) writes:
I am new to procmail and would appreciate if anyone can
help me with real code of .procmailrc for the following example:
In message body search for :
search for the word Item
if found
search for the word TV or VCR
if found
search for the word price or pricing
if found
put the message in the folder tv-vcr-rice
endif
elseif search for the word radio
if found
write the message to folder radio
You left off two 'endif's :-)
Actually, I must say that the above is *much* clearer in intention.
Thank you.
The description from above appears as comments with one '#' in what
follows. My comments have three '#'s. Note the similarity in
structure between the comments and the code. What follows is not the
_shortest_ way of doing this, but it does match your explanation, which
should make it clearer.
Philip Guenther
#----------------procmailrc recipe starts here-------------------
### I'm still assuming you want case-sensitive matching, so we'll add
### the 'D' to each recipe
### I'm also assuming that by folder you mean standard mbox style mail
### folders, being one file with multiple messages delineated by '^From '.
### These require locking (something I forgot in my original reply). Thus
### you'll see a second colon on both of the recipes that write to a folder.
### Unless told otherwise, procmail effectively stops once it's has
### successfully delivered the message, be that to your mailbox, to a
### folder (as we're doing here), into a program, or to another person
### by forwarding it. Thus, if a message is delivered into the "radio"
### or "tv-vcr-rice" folders by the following, then it won't continue on
### to end up in your mailbox. If you would like procmail to deliver the
### message into your normal mailbox _as_well_as_ the "tv-vcr-rice" or
### "radio" folders, add the 'c' flag to the beginning of the first recipe,
### right after the 'BD' flags below.
# In message body search for :
### This adds 'B' flag to each recipe.
# search for the word Item
# if found
:0 BD
* Item
{
# search for the word TV or VCR
# if found
### To handle the 'or' part, we'll just use the regexp '|' operator
### which matches if either side of it does so. I.e., the condition
### below is a match if the body contains either "TV" or "VCR"
:0 BD
* (TV|VCR)
{
# search for the word price or pricing
# if found
# put the message in the folder tv-vcr-rice
### Don't forget to lock the folder while writing: add a second colon
:0 BD:
* (price|pricing)
tv-vcr-rice
# endif
}
# elseif search for the word radio
### The 'elseif' is actually redundant, as a match on the above will
### result in procmail stopping there. For clarity's sake however,
### I've added the 'E' flag below to highlight the 'elseif' nature
### of this recipe.
# if found
# write the message to folder radio
### Don't forget to lock the folder while writing: add a second colon
:0 BDE:
* radio
radio
}