X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=script%2Fpublic-inbox-mda;h=7e2bee92096e877ae40e34eb847e8149f933eb2e;hp=9da2d90f8f45f0227cf3083a9a726f322be38947;hb=refs%2Fheads%2Fmaster;hpb=068c551dada218863a82a99e113f44c64a81b819 diff --git a/script/public-inbox-mda b/script/public-inbox-mda index 9da2d90f..7e2bee92 100755 --- a/script/public-inbox-mda +++ b/script/public-inbox-mda @@ -1,13 +1,23 @@ #!/usr/bin/perl -w -# Copyright (C) 2013-2019 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; @@ -29,22 +38,22 @@ use PublicInbox::Spamcheck; # in case there's bugs in our code or user error. my $emergency = $ENV{PI_EMERGENCY} || "$ENV{HOME}/.public-inbox/emergency/"; $ems = PublicInbox::Emergency->new($emergency); -my $str = eval { local $/; }; +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"; }