procmail
[Top] [All Lists]

Re: modify the subject

2002-04-04 10:34:24
At 14:46 2002-04-04 +0200, svenwurth(_at_)braunstein(_dot_)de did say:
I want to add the word "spam" to the subject for every incoming suspect mail.
[snip]
:0fhw
* ^From:.*(all(_at_)microsoft(_dot_)com)
| formail -A "Subject: Spam"

You don't describe what about this filter isn't doing exactly what you asked for. Is is that the subject is now "Spam" instead of "Spam orignalsubject" ? Is it that you have TWO subject lines (-A "append" adds a header - it doesn't add text _to_ a header)?


:0
* whatever condition(s) you're triggering on
{
        :0
        * ^Subject:[    ]*\/[^  ].*
        {
                SUBJECT=$MATCH
        }

        :0hf
        | formail -I "Subject: SPAM $SUBJECT"
}


Okay, why all the bracing? Well, What if there ISN'T a subject header on the message? If we tossed that condition line from the first internal recipe up into the outter one, then messages that matched your other conditions, but which just happened to not have a subject header, would fail to trigger the whole lot. And that's unlikely something you want to do. So we brace it. Within the brace, it's separate from the actual filter for the same reason.

The 'w' flag on such simple formail filtering is generally unnecessary - that's usually used on something wherein the filter program itself is something that analyses the message (say for spam), and returns its status as its exit code. If you check the list archives, you'll see that most people using formail to change headers don't use 'w'.

FTR, in my own fiters, I extract the From, To, Subject, and sender before running other rules, so I have this data kicking around in a variable already and don't need to take this extra step in a rule (after you build up enough rules, it becomes a lot more streamlined do it this way). In my case, the filter would look like:

:0hf
* whatever condition(s) you're triggering on
| formail -I "Subject: SPAM $SUBJECT"


Alternatley, you could do the same as you are now, but use -i (see 'man formail'):

:0fhw
* ^From:.*(all(_at_)microsoft(_dot_)com)
| formail -i "Subject: Spam"

Which (as per the manpage), would rename the original subject Old-Subject:

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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