procmail
[Top] [All Lists]

Re: automatically adding names to a file

1997-01-27 13:55:46
Timothy J Luoma <luomat(_at_)nerc(_dot_)com> writes:
I get email from a SPAM fighting group with the subject like this:

Subject: spam: waltercan(_at_)worldnet(_dot_)att(_dot_)net: Hello

Where the first word is "spam: " the second word is the offending  
email address, and the third word is the subject of the message that  
this offendee sent.

I would like to take the second argument (the email address) and  
REMOVE the ":" at the end of the email address and paste that to a  
file of known spammers:

I've been thinking about this:

:0
* ^From spam-list-owner(_at_)toby(_dot_)han(_dot_)de
* ^Subject: spam: \/.*$
{
      spammer=`echo $MATCH | awk '{print $1}' |tr -d ":"`
      
      
      :0hi: spamfile.lock
      * ! ? grep -s -i -w "$spammer" $PROCDIR/killfile-by-from-line
      |/bin/echo "$spammer" >> $PROCDIR/killfile-by-from-line

      :0
      |appnmail DuplicateSpam

}

The only thing I am worried about is the "tr -d" line.  Should I be  
worried about that?  is there a better way to do this?

Yes, do the extraction in procmail.  Just match the first string of
non-space characters after the colon, and that should do it, no?


# You *must* use "[^ ]+" instead of "[^ ]*" as the latter will never
# match anything (probably).
:0
* ^From spam-list-owner(_at_)toby\(_dot_)han\(_dot_)de
* ^Subject: spam: *\/[^ ]+
{
    # Lock the file for the search and the insertion
    LOCKFILE = spamfile.lock

    :0
    * ! ? grep -siw -e "$MATCH" $PROCDIR/killfile-by-from-line
    {
        # Be really efficient by doing the appending in procmail.
        # Yes, this is obfuscated, but it should be fast.
        # If you use LOGABSTRACT = all, this'll not show up in the log.
        OLOGFILE = $LOGFILE
        LOGFILE = $PROCDIR/killfile-by-from-line
        LOG = "$MATCH
"
        LOGFILE = $OLOGFILE

        # Now exit (quickly)
        HOST
    }

    # Unlock...
    LOCKFILE

    :0
    |appnmail DuplicateSpam
}


Philip Guenther

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