X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-mda;h=42d0e00cbb72687bbdaf5e67e1fb0c6c379ba9b1;hb=46742d95647c7a80cb2f60d5c134717dd91e22e2;hp=dca8a0ea0e8aa64f859676773e736d4cae77a3a1;hpb=74a3206babe0572a1494500d21267a31873af7b0;p=public-inbox.git diff --git a/script/public-inbox-mda b/script/public-inbox-mda index dca8a0ea..42d0e00c 100755 --- a/script/public-inbox-mda +++ b/script/public-inbox-mda @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright (C) 2013-2019 all contributors +# Copyright (C) 2013-2020 all contributors # License: AGPL-3.0+ # # Mail delivery agent for public-inbox, run from your MTA upon mail delivery @@ -9,14 +9,13 @@ my $usage = 'public-inbox-mda [OPTIONS] < rfc2822_message'; my $precheck = grep(/\A--no-precheck\z/, @ARGV) ? 0 : 1; my ($ems, $emm); -sub do_exit { +my $do_exit = sub { my ($code) = shift; $emm = $ems = undef; # trigger DESTROY exit $code; -} +}; -use Email::Simple; -use PublicInbox::MIME; +use PublicInbox::Eml; use PublicInbox::MDA; use PublicInbox::Config; use PublicInbox::Emergency; @@ -29,10 +28,10 @@ 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 $eml = PublicInbox::Eml->new(\$str); my $config = PublicInbox::Config->new; my $key = 'publicinboxmda.spamcheck'; my $default = 'PublicInbox::Spamcheck::Spamc'; @@ -44,11 +43,11 @@ if (defined $recipient) { push @$dests, $ibx if $ibx; } if (!scalar(@$dests)) { - $dests = PublicInbox::MDA->inboxes_for_list_id($config, $simple); + $dests = PublicInbox::MDA->inboxes_for_list_id($config, $eml); if (!scalar(@$dests) && !defined($recipient)) { die "ORIGINAL_RECIPIENT not defined in ENV\n"; } - scalar(@$dests) or do_exit(67); # EX_NOUSER 5.1.1 user unknown + scalar(@$dests) or $do_exit->(67); # EX_NOUSER 5.1.1 user unknown } my $err; @@ -61,15 +60,15 @@ 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; } } @$dests; -do_exit(67) if $err && scalar(@$dests) == 0; +$do_exit->(67) if $err && scalar(@$dests) == 0; -$simple = undef; +$eml = undef; my $spam_ok; if ($spamc) { $str = ''; @@ -84,7 +83,7 @@ if ($spamc) { my $fh = $emm->fh; read($fh, $str, -s $fh); } -do_exit(0) unless $spam_ok; +$do_exit->(0) unless $spam_ok; # -mda defaults to the strict base filter which we won't use anywhere else sub mda_filter_adjust ($) { @@ -101,9 +100,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 @@ -131,4 +131,4 @@ if (scalar(@rejects) && scalar(@rejects) == scalar(@$dests)) { die join("\n", @rejects, ''); } -do_exit(0); +$do_exit->(0);