procmail
[Top] [All Lists]

Re: Follow: Recipe woes

2003-06-01 02:18:06
On Sat, May 31, 2003 at 11:28:33PM -0500, Justin Shore wrote:

I can't figure out a regex way to remove all occurences of
"***SPAM***" from the Subject line.  This happens when I bounce a
piece of spam that SpamAssassin has already marked up to a spamtrap
address anymore.  My only fix is to check for that string twice.  A
regex fix for this would be handy.

One assumes you are sending the mail to SA higher up in your rc.
There are several considerations here.  One, why don't you catch
the value of Subject: before SA ever sees the mail and changes it?
Two, there are options to stop SA from writing to the Subject:
line.  Perhaps you should use them?  Three, SA's -d option, or
the razor-report program's submit option, can strip the ***SPAM***
stuff out.  But I'd go with No. 1 here, because you hav an
unaltered piece of mail, which you then alter with SA, then try
to unalter with some other tool inside procmail.  Seems like
a counterproductive way to go.

So simply capture SUBJECT on all your mail up-top in your rc.  Then,
when a particular piece is spam, you already have the value to send
in your custom report action.

That said, if you really want to remove the lines, you could use sed:

        SUBJECT = "`echo $SUBJECT | sed 's/\*\*\*SPAM\*\*\*//g'`


Along the same lines I can't figure out how to apply that regex to
$SUBJECT that I initially match.  I use it later when I forward mail
to the FTC and NANAS.  Any tips on this that take into account the
problem of multiple ***SPAM*** strings would be gladly accepted.

You should be using the -d flag to SA to strip out changes to the
headers before you make reports.

# Extract subject and assign it to SUBJECT
:0
* ^Subject:[  ]*\/[^  ].*
{
        SUBJECT=$MATCH
}

## Report spam to Pyzor, Razor, the FTC, and NANAS.
:0 BH
# Hopefully this will prevent mail loops.
* $ ! ^X-Spam-Loop: $BOUNCER
* !   ^FROM_DAEMON
{
      :0f
      # Clean up the spam by removing the SA headers, Subject change
      # and other misc headers.
      | spamassassin -d \
      | sed -e "s/^Subject: \*\*\*SPAM\*\*\*/Subject:/" \
            -e "s/^Subject: \*\*\*SPAM\*\*\*/Subject:/" \

Use the g option to sed.  Anyway, you have already bothered to
extract SUBJECT above, so do your operation on that, not on a
newly extracted copy of the same line that you have to parse
the whole message again for.

It might be preferable for you to run SA without having it change
headers at all.  That's how I run it (for some value of the infrequent
times that I end up running SA, since my own recipes catch the spam all
but maybe once a fortnight).  I think you can start by putting this in
your user_prefs file:

        rewrite_subject       0


But here is another way:


       :0 W  # this is an assignment recipe, not a delivering one
        SA_OUT=| /users/zconcept/bin/spamc -c

       :0 e  # if exit status warrants, tag as spam
        { RX = SpamAssassin }

       :0 E:  # check for possible spamc failure
        * SA_OUT ?? ^^0/0^^
        spamc_failure

Now the original message is untouched, but procmail knows it's spam.  I
have used this method for many months.  Btw, the spamc_failure check is
there simply for completion's sake; but I have never, ever seen it get
invoked.

-- 
dman

_______________________________________________
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>