From 466df3e029fecdabac373d73989c7fceebe6ae28 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Jul 2018 10:05:13 +0000 Subject: mda: allow configuring globally without spamc support 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. --- script/public-inbox-mda | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'script/public-inbox-mda') 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; -- cgit v1.2.3-24-ge0c7