end user - procmail filter

Michael Janssen Janssen at RZ.UNI-FRANKFURT.DE
Wed Sep 18 20:43:01 IST 2002


> > ### SA-Scoring
> > :0
> > * ^X-MailScanner-SpamCheck: SpamAssassin .score=\/[^\., ]*
> > * ? test ${MATCH} -ge 15
> > $MAILDIR/spam/high
> >
> > filling the score (everything after \/ till dot, comma, space) to $MATCH
> > and then process with (bash-builtin) test. "?" let procmail take the
> > return value of the given programm as a test.
> >
> > since "test" doesn't handel floats the regexp has to cut the score to int.
>
> I haven't had a chance to experiment with this yet, but just off the top
> of my head might it be possible to just remove the decimal point somehow
> and deal with the larger two digit integer rather than just truncating it?
>
> Or would that be unnecessary added value? (nonetheless, it would be a cool
> thing to know how to do, for us types that are entertained by such things)
>
> Eric
>
yes! There is a way to use fine tweaked filters:

# abc=`echo "4.9" | sed s/\\\\.//`; test $abc -gt 48 && echo yes
yes
# abc=`echo "4.7" | sed s/\\\\.//`; test $abc -gt 48 && echo yes
#

BUT this is only the first approach, wich will fails when the score has no
dot. Therefore we need a sed-subtitution which padded 0 to e.g.
4 or 42:
sed s/^[1-9][0-9]\\?$/'&'0/  --> if string is one or two decimals
(without dot) then take the match and padd 0. Otherwise leave string
untouched.

the complete pipe:

# echo "4" | sed s/^[1-9][0-9]\\?$/'&'0/ | sed s/\\.//
40
# echo "4.2" | sed s/^[1-9][0-9]\\?$/'&'0/ | sed s/\\.//
42
# echo "42" | sed s/^[1-9][0-9]\\?$/'&'0/ | sed s/\\.//
420
# echo "42.6" | sed s/^[1-9][0-9]\\?$/'&'0/ | sed s/\\.//
426

the procmail-repipe is (dubbel escaped):
* ? abc=`echo $MATCH | sed s/^[1-9][0-9]\\\\?$/"'&'"0/ | sed s/\\\\.//`; \
test $abc -gt 4.1

keep care: no spaces in $MATCH allowed

Another way might be to figure out how "bc" works, wich can handel floats
(man bc).

Michael

By the way, $MATCH is suggested on this side:
http://www.uwasa.fi/~ts/info/proctips.html



More information about the MailScanner mailing list