X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-mda;h=7e2bee92096e877ae40e34eb847e8149f933eb2e;hb=4eee5af6011cc8cdefb66c9729952c7eff5c0b0b;hp=54d0af01414a64c9458a7cf9d3005143bc5f9616;hpb=4bebfa0c80ad7f4596a7dca98b39121470a42af0;p=public-inbox.git diff --git a/script/public-inbox-mda b/script/public-inbox-mda index 54d0af01..7e2bee92 100755 --- a/script/public-inbox-mda +++ b/script/public-inbox-mda @@ -1,13 +1,23 @@ #!/usr/bin/perl -w -# Copyright (C) 2013-2020 all contributors +# Copyright (C) 2013-2021 all contributors # License: AGPL-3.0+ # # Mail delivery agent for public-inbox, run from your MTA upon mail delivery +my $help = < \$precheck, 'help|h' => \$show_help) or + do { print STDERR $help; exit 1 }; my $do_exit = sub { my ($code) = shift; @@ -15,8 +25,7 @@ my $do_exit = sub { exit $code; }; -use Email::Simple; -use PublicInbox::MIME; +use PublicInbox::Eml; use PublicInbox::MDA; use PublicInbox::Config; use PublicInbox::Emergency; @@ -32,19 +41,19 @@ $ems = PublicInbox::Emergency->new($emergency); my $str = do { local $/; }; $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 $eml = PublicInbox::Eml->new(\$str); +my $cfg = PublicInbox::Config->new; my $key = 'publicinboxmda.spamcheck'; my $default = 'PublicInbox::Spamcheck::Spamc'; -my $spamc = PublicInbox::Spamcheck::get($config, $key, $default); +my $spamc = PublicInbox::Spamcheck::get($cfg, $key, $default); my $dests = []; my $recipient = $ENV{ORIGINAL_RECIPIENT}; if (defined $recipient) { - my $ibx = $config->lookup($recipient); # first check + my $ibx = $cfg->lookup($recipient); # first check push @$dests, $ibx if $ibx; } if (!scalar(@$dests)) { - $dests = PublicInbox::MDA->inboxes_for_list_id($config, $simple); + $dests = PublicInbox::MDA->inboxes_for_list_id($cfg, $eml); if (!scalar(@$dests) && !defined($recipient)) { die "ORIGINAL_RECIPIENT not defined in ENV\n"; } @@ -61,7 +70,7 @@ my $err; 0; # pre-check, MDA has stricter rules than an importer might; } elsif ($precheck) { - !!PublicInbox::MDA->precheck($simple, $ibx->{address}); + !!PublicInbox::MDA->precheck($eml, $ibx->{address}); } else { 1; } @@ -69,7 +78,7 @@ my $err; $do_exit->(67) if $err && scalar(@$dests) == 0; -$simple = undef; +$eml = undef; my $spam_ok; if ($spamc) { $str = ''; @@ -101,9 +110,10 @@ my @rejects; for my $ibx (@$dests) { mda_filter_adjust($ibx); my $filter = $ibx->filter; - my $mime = PublicInbox::MIME->new($str); + my $mime = PublicInbox::Eml->new($str); my $ret = $filter->delivery($mime); - if (ref($ret) && $ret->isa('Email::MIME')) { # filter altered message + if (ref($ret) && ($ret->isa('PublicInbox::Eml') || + $ret->isa('Email::MIME'))) { # filter altered message $mime = $ret; } elsif ($ret == PublicInbox::Filter::Base::IGNORE) { next; # nothing, keep looping @@ -119,7 +129,7 @@ for my $ibx (@$dests) { # destination succeeds $emm->abort; } else { # v1-only - my $mid = $mime->header_obj->header_raw('Message-ID'); + my $mid = $mime->header_raw('Message-ID'); # this message is similar to what ssoma-mda shows: print STDERR "CONFLICT: Message-ID: $mid exists\n"; }