about summary refs log tree commit homepage
path: root/script
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-07-29 10:05:13 +0000
committerEric Wong <e@80x24.org>2018-07-29 10:20:36 +0000
commit466df3e029fecdabac373d73989c7fceebe6ae28 (patch)
treeebd6e15fd155202ef251d14dedb39828dc983ca6 /script
parent9015a8af2909b0071e54b332bfafc4e5b8d0f6c2 (diff)
downloadpublic-inbox-466df3e029fecdabac373d73989c7fceebe6ae28.tar.gz
This reuses some of the configuration from -watch, but remains
independent since some configurations will use -watch for some
inboxes and -mda for others.

The default remains "spamc" for -mda users so nothing changes
without explicit configuration.

Per-inbox configurations may also be supported in the future.
Diffstat (limited to 'script')
-rwxr-xr-xscript/public-inbox-mda27
1 files changed, 19 insertions, 8 deletions
diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 2b7f298c..183b915d 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -20,8 +20,8 @@ use PublicInbox::MDA;
 use PublicInbox::Config;
 use PublicInbox::Emergency;
 use PublicInbox::Filter::Base;
-use PublicInbox::Spamcheck::Spamc;
 use PublicInbox::InboxWritable;
+use PublicInbox::Spamcheck;
 
 # n.b: hopefully we can setup the emergency path without bailing due to
 # user error, we really want to setup the emergency destination ASAP
@@ -33,7 +33,9 @@ $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
 $ems->prepare(\$str);
 my $simple = Email::Simple->new(\$str);
 my $config = PublicInbox::Config->new;
-
+my $key = 'publicinboxmda.spamcheck';
+my $default = 'PublicInbox::Spamcheck::Spamc';
+my $spamc = PublicInbox::Spamcheck::get($config, $key, $default);
 my $recipient = $ENV{ORIGINAL_RECIPIENT};
 defined $recipient or die "ORIGINAL_RECIPIENT not defined in ENV\n";
 my $dst = $config->lookup($recipient); # first check
@@ -43,13 +45,22 @@ $dst = PublicInbox::InboxWritable->new($dst);
 
 # pre-check, MDA has stricter rules than an importer might;
 do_exit(0) unless PublicInbox::MDA->precheck($simple, $dst->{address});
-my $spamc = PublicInbox::Spamcheck::Spamc->new;
-$str = '';
-my $spam_ok = $spamc->spamcheck($ems->fh, \$str);
 $simple = undef;
-$emm = PublicInbox::Emergency->new($emergency);
-$emm->prepare(\$str);
-$ems = $ems->abort;
+my $spam_ok;
+if ($spamc) {
+        $str = '';
+        $spam_ok = $spamc->spamcheck($ems->fh, \$str);
+        # update the emergency dump with the new message:
+        $emm = PublicInbox::Emergency->new($emergency);
+        $emm->prepare(\$str);
+        $ems = $ems->abort;
+} else { # no spam checking configured:
+        $spam_ok = 1;
+        $emm = $ems;
+        my $fh = $emm->fh;
+        read($fh, $str, -s $fh);
+}
+
 my $mime = PublicInbox::MIME->new(\$str);
 do_exit(0) unless $spam_ok;