dspam: added check for autolearn

don't try to use autolearn if it's not set
added tests that exercise and exorcise the bug
This commit is contained in:
Matt Simerson 2012-05-11 01:50:06 -04:00 committed by Robert
parent ab258cfc2e
commit 25a099e20b
2 changed files with 24 additions and 6 deletions

View File

@ -377,9 +377,9 @@ sub get_dspam_results {
sub get_filter_cmd {
my ($self, $transaction, $user) = @_;
my $dspam_bin = $self->{_args}->{dspam_bin} || '/usr/local/bin/dspam';
my $dspam_bin = $self->{_args}{dspam_bin} || '/usr/local/bin/dspam';
my $default = "$dspam_bin --user $user --mode=tum --process --deliver=summary --stdout";
my $min_score = $self->{_args}->{learn_from_sa} or return $default;
my $min_score = $self->{_args}{learn_from_sa} or return $default;
#$self->log(LOGDEBUG, "attempting to learn from SA");
@ -391,6 +391,8 @@ sub get_filter_cmd {
return $default;
};
return $default if ! $sa->{autolearn};
if ( $sa->{is_spam} eq 'Yes' && $sa->{autolearn} eq 'spam' ) {
return "$dspam_bin --user $user --mode=tum --source=corpus --class=spam --deliver=summary --stdout";
}

View File

@ -11,7 +11,7 @@ my $r;
sub register_tests {
my $self = shift;
$self->register_test('test_get_filter_cmd', 2);
$self->register_test('test_get_filter_cmd', 5);
$self->register_test('test_get_dspam_results', 6);
$self->register_test('test_dspam_reject', 6);
}
@ -39,19 +39,19 @@ sub test_dspam_reject {
# requires agreement
$self->{_args}->{reject} = 'agree';
$transaction->notes('spamassassin', { is_spam => 'Yes' } );
$transaction->notes('spamassassin', { is_spam => 'Yes', score => 25 } );
$transaction->notes('dspam', { class=> 'Spam', probability => .90, confidence=>1 } );
($r) = $self->dspam_reject( $transaction );
cmp_ok( $r, '==', DENY, "dspam_reject ($r)");
# requires agreement
$transaction->notes('spamassassin', { is_spam => 'No' } );
$transaction->notes('spamassassin', { is_spam => 'No', score => 15 } );
$transaction->notes('dspam', { class=> 'Spam', probability => .96, confidence=>1 } );
($r) = $self->dspam_reject( $transaction );
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
# requires agreement
$transaction->notes('spamassassin', { is_spam => 'Yes' } );
$transaction->notes('spamassassin', { is_spam => 'Yes', score => 10 } );
$transaction->notes('dspam', { class=> 'Innocent', probability => .96, confidence=>1 } );
($r) = $self->dspam_reject( $transaction );
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
@ -94,4 +94,20 @@ sub test_get_filter_cmd {
my $r = $self->get_filter_cmd($transaction, 'smtpd');
cmp_ok( $r, 'eq', $answer, "get_filter_cmd $user" );
};
$transaction->notes('spamassassin', { is_spam => 'No', autolearn => 'ham' } );
my $r = $self->get_filter_cmd($transaction, 'smtpd');
cmp_ok( $r, 'eq', "$dspam --user smtpd --mode=tum --source=corpus --class=innocent --deliver=summary --stdout",
"get_filter_cmd smtpd, ham" );
$transaction->notes('spamassassin', { is_spam => 'Yes', autolearn => 'spam', score => 110 } );
$r = $self->get_filter_cmd($transaction, 'smtpd');
cmp_ok( $r, 'eq', "$dspam --user smtpd --mode=tum --source=corpus --class=spam --deliver=summary --stdout",
"get_filter_cmd smtpd, spam" );
$transaction->notes('spamassassin', { is_spam => 'No', autolearn => 'spam' } );
$r = $self->get_filter_cmd($transaction, 'smtpd');
cmp_ok( $r, 'eq', "$dspam --user smtpd --mode=tum --process --deliver=summary --stdout",
"get_filter_cmd smtpd, spam" );
};