procmail
[Top] [All Lists]

Re: Procmail ruleset: what is wrong?

2000-05-10 04:51:06
David Collantes wrote,

| I want to create a recipe that will check for HTML messages and/or
| messages with attachments (of any kind), add a banner -message- before the
| body and then let the message go to normal delivery.
| 
| The recipe I have is not working. It reads as follows:

It would help if you would say what is happening instead of what you expect
so that we'd have more detail than "not working."

| :0:
| * !^FROM_DAEMON
| * !^From TRC
| * !^majordomo(_at_)bus\(_dot_)ucf\(_dot_)edu
| * !^majordomo-owner(_at_)bus\(_dot_)ucf\(_dot_)edu
| * !^owner-cba(fac|stf|adj)?(_at_)bus\(_dot_)ucf\(_dot_)edu
| * ^Content-Type:\<*text/html
| * ^Content-Type:\<*multipart/(mixed|alternative)
| {
|    :0 fhw
|    | /bin/cat -; /bin/echo "<<< WARNING >>>"; /bin/echo " "
| }

I see a number of suboptimal things there, but probably the main reason for
trouble is that you're expecting two matches to Content-Type: of which at 
most one is going to be there: you're ANDing them and I guess you meant to
OR them.

Let's revamp this from scratch.  First, there's no reason to ask for a local
lockfile on opening a brace next (unless you're cloning) and there's no
reason to open a brace nest to do one unconditional recipe.  Second, the
"majordomo" and "owner-cba" conditions shouldn't be left-anchored; no message
will have those words left-anchored in the head, so no message will ever fail
conditions that make sure the impossible didn't happen.  Also, if we take the
angle brackets out of $SHELLMETAS (or if you use some other symbol around the
word "warning") we can insert the text without invoking a shell.  Moreover,
I believe in setting the PATH variable properly so that other programs can be
called by their basenames rather than typing out the absolute path to each
one or cluttering the environment with a variable for the absolute path of
each one, but if you want to specify /bin/sed or /usr/bin/sed (wherever it
lives on your system), go right ahead:

savemetas=$SHELLMETAS
SHELLMETAS

 :0fhw
 * ! ^FROM_DAEMON
 * ! ^From TRC
 * ! (majordomo(-owner)?|owner-cba(fac|stf|adj)?)@bus\.ucf\.edu
 * ^Content-Type:\<*(text/html|multipart/(mixed|alternative))
 | sed "$ a\\
<<< WARNING >>\\
\\
"

SHELLMETAS=$savemetas

Your version of sed might not need the extra line of double backslashes.
If you get two blank lines below the word "WARNING" instead of just one,
take the additional line of backslashes out.

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