procmail
[Top] [All Lists]

continue scoring on next recipe

2002-01-18 12:50:56
Hi list,

I started to think about extending my spam filters, and, inspired by
spamassassin, I wanted to use a weighted scoring technique. I wanted to
keep as much as possible in procmail/formail (I don't know Perl :-).
However, I ran into a problem when I wanted to accumulate the score over
several recipes. 

I solved it by creating a short C program called `add' that just adds up
its commandline arguments (if they are numbers). If the program is
called with the `-f' option, it will return the sum of its arguments as
its exit code. However, I am not sure that is the Correct Way(tm) to do
it. One problem with this is that the return value that procmail sees is
unsigned, and it wraps at 256. It is not a big problem, I can just
design the score values around that. However, it would be nice to have
the dynamics of procmail's full scoring-range to work with.

A few pointers to what can be a good idea to include checks for (and
their severity) is appreciated; e.g. do spammers usually skip or add any
headers?  

Here is an example:

LIMIT=20

# this checks the header only
:0 Df
* 2^1.5 (!|?|\*|\$)
* 10^1  ^(SUBJECT|TO|FROM|DATE)
| formail -A"X-Score: $="

# do some checks in the body as well
:0 Bf
* 20^1 (flame|sex)
| formail -A "X-Score: $="

# file as spam if accumulated score is more than 50
:0:
* -1^1 ! ? add -f $LIMIT
* 1^1 ! ? add -f `formail -x"X-Score:"`
spam

Here is the C program source:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
        double sum = 0.0;

        while (argc-- > 0)
                sum += atof(argv[argc]);

        if (strcmp(argv[1], "-f")) {
                fprintf(stdout, "%.2f\n", sum);
                return 0;
        }
        
        if (sum > 255.0)
                return 255;
        else if (sum < 0.0)
                return 0;
        else
                return (int) sum;
}

Stig

-- 
brautaset.org
Registered Linux User 107343

``Oh, how I wish `undo' was ported to everyday life.''
_______________________________________________
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>