diff --git a/plugins/dspam b/plugins/dspam index 3a92741..84d1d7d 100644 --- a/plugins/dspam +++ b/plugins/dspam @@ -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"; } diff --git a/t/plugin_tests/dspam b/t/plugin_tests/dspam index aafab8a..6ab8e5c 100644 --- a/t/plugin_tests/dspam +++ b/t/plugin_tests/dspam @@ -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" ); }; +