]> Sergey Matveev's repositories - public-inbox.git/blobdiff - public-inbox-mda
mda: rename PI_FAILBOX to PI_EMERGENCY
[public-inbox.git] / public-inbox-mda
index 411ac15f7f396a35b95b23387cd133f0f1e4deed..1f4d339f63eaa1e561586cae84ed9334634d9d90 100755 (executable)
@@ -7,6 +7,8 @@ my $usage = 'public-inbox-mda < rfc2822_message';
 
 use Email::Filter;
 use Email::Address;
+use Encode qw/decode encode/;
+use Encode::MIME::Header;
 use File::Path::Expand qw/expand_filename/;
 use IPC::Run qw(run);
 use constant MDA => 'ssoma-mda';
@@ -14,14 +16,14 @@ use PublicInbox;
 use PublicInbox::Filter;
 use PublicInbox::Config;
 
-# n.b: hopefully we can setup the failbox path without bailing due to
+# n.b: hopefully we can setup the emergency path without bailing due to
 # user error, we really want to setup the emergency destination ASAP
 # in case there's bugs in our code or user error.
-my $failbox = $ENV{PI_FAILBOX} || '~/public-inbox-fail.mbox';
-$failbox = expand_filename($failbox);
+my $emergency = $ENV{PI_EMERGENCY} || '~/.public-inbox/emergency/';
+$emergency = expand_filename($emergency);
 
 # this reads the message from stdin
-my $filter = Email::Filter->new(emergency => $failbox);
+my $filter = Email::Filter->new(emergency => $emergency);
 my $config = PublicInbox::Config->new;
 
 my $recipient = $ENV{RECIPIENT};
@@ -42,9 +44,11 @@ if (PublicInbox->precheck($filter, $recipient) &&
                # run spamc again on the HTML-free message
                if (do_spamc($simple, \$filtered)) {
                        $simple = Email::Simple->new($filtered);
+                       set_list_headers($simple, $dst);
                        $filter->simple($simple);
 
-                       my $from = $filter->from;
+                       my $from = decode('MIME-Header', $filter->from);
+                       $from = encode("utf8", $from);
                        my @from = Email::Address->parse($from);
                        my $name = $from[0]->name;
                        defined $name or $name = "";
@@ -60,7 +64,7 @@ if (PublicInbox->precheck($filter, $recipient) &&
                }
        }
 }
-exit 0; # goes to failbox
+exit 0; # goes to emergency
 
 # we depend on "report_safe 0" in /etc/spamassassin/*.cf with --headers
 # not using Email::Filter->pipe here since we want the stdout of
@@ -74,3 +78,17 @@ sub do_spamc {
 
        return ($@ || $? || !defined($$out) || length($$out) == 0) ? 0 : 1;
 }
+
+# RFC2919 and RFC2369
+sub set_list_headers {
+       my ($simple, $dst) = @_;
+       my $pa = "<$dst->{-primary_address}>";
+       $simple->header_set("List-Id", $pa);
+       $simple->header_set("List-Post", $pa);
+
+       my $url = $dst->{url};
+       if (defined $url) {
+               $simple->header_set("List-Archive", "<$url>");
+               $simple->header_set("List-Help", "<${url}help>");
+       }
+}