It's possible that a user will want to disabe SpamAssassin
via "publicinboxmda.spamcheck=none" in public-inbox-config(5)
when injecting ham into an inbox.

Fixes: 466df3e029fe ("mda: allow configuring globally without spamc support")
---
 script/public-inbox-learn | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/script/public-inbox-learn b/script/public-inbox-learn
index 3073294a..145f41ea 100644
--- a/script/public-inbox-learn
+++ b/script/public-inbox-learn
@@ -11,21 +11,23 @@ use PublicInbox::Config;
 use PublicInbox::InboxWritable;
 use PublicInbox::MIME;
 use PublicInbox::Address;
-use PublicInbox::Spamcheck::Spamc;
+use PublicInbox::Spamcheck;
 my $train = shift or die "usage: $usage\n";
 if ($train !~ /\A(?:ham|spam|rm)\z/) {
        die "`$train' not recognized.\nusage: $usage\n";
 }
 
-my $spamc = PublicInbox::Spamcheck::Spamc->new;
 my $pi_config = PublicInbox::Config->new;
+my $key = 'publicinboxmda.spamcheck';
+my $default = 'PublicInbox::Spamcheck::Spamc';
+my $spamc = PublicInbox::Spamcheck::get($pi_config, $key, $default);
 my $err;
 my $mime = PublicInbox::MIME->new(eval {
        local $/;
        my $data = scalar <STDIN>;
        $data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
 
-       if ($train ne 'rm') {
+       if ($train ne 'rm' && defined($spamc)) {
                eval {
                        if ($train eq 'ham') {
                                $spamc->hamlearn(\$data);
--
unsubscribe: [email protected]
archive: https://public-inbox.org/meta/

Reply via email to