You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Justin Mason <jm...@jmason.org> on 2004/02/26 22:28:17 UTC
Re: CRM114 plugin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Eugene Morozov writes:
>I've created a beta version of crm114 plugin for
>SpamAssassin. I didn't implemented config options
>(is it possible without hacking SA Conf.pm?), so crm114
>command is hardcoded in the module code.
Looks cool.
The config can be parsed by registering a callback for "parse_config";
any unrecognised config lines are passed through that so that
plugins can use them.
- --j.
> Here's my
>sample configuration:
>
>loadplugin crm114 /home/jmv/projects/spamassassin/crm114.pm
>ifplugin crm114
> # This is probably lame, but I've just started using
> # crm114 and doesn't fully understand yet how it
> # works and what its pR really mean
> body CRM114_SPAM_00 eval:check_crm('-10.00', '-0.01')
> body CRM114_SPAM_10 eval:check_crm('-50.00', '-10.00')
> body CRM114_SPAM_50 eval:check_crm('-100.00', '-50.00')
> body CRM114_SPAM_99 eval:check_crm('undef', '-100.00')
>
> body CRM114_HAM_00 eval:check_crm('0.00', '10.00')
> body CRM114_HAM_10 eval:check_crm('10.00', '50.00')
> body CRM114_HAM_50 eval:check_crm('50.00', '100.00')
> body CRM114_HAM_99 eval:check_crm('100.00', 'undef')
>
> score CRM114_SPAM_00 1
> score CRM114_SPAM_10 1.5
> score CRM114_SPAM_50 3
> score CRM114_SPAM_99 4
>
> score CRM114_HAM_00 -1
> score CRM114_HAM_10 -1.5
> score CRM114_HAM_50 -3
> score CRM114_HAM_99 -4
>
> tflags CRM114_SPAM_00 learn
> tflags CRM114_SPAM_10 learn
> tflags CRM114_SPAM_50 learn
> tflags CRM114_SPAM_99 learn
> tflags CRM_114_HAM_00 nice learn
> tflags CRM_114_HAM_10 nice learn
> tflags CRM_114_HAM_50 nice learn
> tflags CRM_114_HAM_99 nice learn
>
> describe CRM114_SPAM_00 CRM114 pR from -0.01 to -10.00
> describe CRM114_SPAM_10 CRM114 pR from -10.00 to -50.00
> describe CRM114_SPAM_50 CRM114 pR from -50.00 to -100.00
> describe CRM114_SPAM_99 CRM114 pR from -100.00 to -999.99
>
> describe CRM114_HAM_00 CRM114 pR from 0.00 to 10.00
> describe CRM114_HAM_10 CRM114 pR from 10.00 to 50.00
> describe CRM114_HAM_50 CRM114 pR from 50.00 to 100.00
> describe CRM114_HAM_99 CRM114 pR from 100.00 to 999.99
>endif
>
>Module code is in the attachment. Comments are welcome.
>Eugene
>
>--
>Email: jmv /at/ online.ru
>
>--=-=-=
>Content-Type: text/x-perl
>Content-Disposition: inline; filename=crm114.pm
>
>package crm114;
>
>use strict;
>use IPC::Open3;
>use Mail::SpamAssassin::Plugin;
>use vars qw(@ISA);
>@ISA = qw(Mail::SpamAssassin::Plugin);
>
>sub new {
> my $class = shift;
> my $mailsaobject = shift;
>
> # the usual perlobj boilerplate to create a subclass object
> $class = ref($class) || $class;
> my $self = $class->SUPER::new($mailsaobject);
> bless ($self, $class);
>
> $self->{crm_command} = "/usr/bin/crm114 -u /home/jmv/crm114 mailfilter.crm";
>
> # then register an eval rule
> $self->register_eval_rule ("check_crm");
>
> # and return the new plugin object
> return $self;
>}
>
>sub check_crm {
> my ($self, $status, $fulltext, $min, $max) = @_;
>
> my $msg = $status->get_message()->get_pristine();
>
> if (!exists($self->{crm114_score})) {
> my $pid;
> eval {
> open3(\*CRM_OUT, \*CRM_IN, \*CRM_ERR, $self->{crm_command});
> };
> if ($@) { printf "\@: %s\n", $@; }
>
> print CRM_OUT $msg;
> close(CRM_OUT);
>
> while(<CRM_IN>) {
> if (/^open3: (.*)/) {
> die $1;
> }
>
> if (/^X-CRM114-Status: \w+\s+\( pR: ([-\d.]+) \)/) {
> $self->{crm114_score} = $1;
> }
> }
>
> close(CRM_OUT);
> close(CRM_IN);
>
> if (!exists($self->{crm114_score})) {
> die "CRM114 didn't return spamicity value.";
> }
>
> dbg(sprintf ("CRM114 score: %3.4f", $self->{crm114_score}));
> }
>
> if (($min eq "undef" || $self->{crm114_score} > $min)
> && ($max eq "undef" || $self->{crm114_score} <= $max))
> {
> return 1
> }
>
> return 0;
>}
>
>sub dbg { Mail::SpamAssassin::dbg (@_); }
>
>1;
>
>--=-=-=--
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Exmh CVS
iD8DBQFAPmTxQTcbUG5Y7woRAqYFAKCZnQ+KKNpInNxVILHh2mu1DT0fUACeNYK+
qN59A4caOY6ew6AVt65l7+Y=
=nJnj
-----END PGP SIGNATURE-----