2 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
8 use PublicInbox::Filter;
10 my $usage = "public-inbox-mda main_repo fail_repo < rfc2822_message";
11 my $filter = Email::Filter->new(emergency => "~/emergency.mbox");
12 my $main_repo = shift @ARGV or die "Usage: $usage\n";
13 my $fail_repo = shift @ARGV or die "Usage: $usage\n";
16 if (PublicInbox->precheck($filter) && do_spamc($filter->simple, \$filtered)) {
17 # update our message with SA headers (in case our filter rejects it)
18 my $simple = Email::Simple->new($filtered);
20 $filter->simple($simple);
22 if (PublicInbox::Filter->run($simple)) {
23 # run spamc again on the HTML-free message
24 if (do_spamc($simple, \$filtered)) {
25 $filter->simple(Email::Simple->new($filtered));
26 $filter->pipe("ssoma-mda", $main_repo);
28 $filter->pipe("ssoma-mda", $fail_repo);
31 # PublicInbox::Filter nuked everything, oops :x
32 $filter->pipe("ssoma-mda", $fail_repo);
35 # if SA thinks it's spam or there's an error:
36 # don't bother with our own filtering
37 $filter->pipe("ssoma-mda", $fail_repo);
39 die "Email::Filter failed to exit\n";
41 # we depend on "report_safe 0" in /etc/spamassassin/*.cf with --headers
42 # not using Email::Filter->pipe here since we want the stdout of
43 # the command even on failure (spamc will set $? on error).
45 my ($simple, $out) = @_;
47 my $orig = $simple->as_string;
48 run([qw/spamc -E --headers/], \$orig, $out);
51 return ($@ || $? || !defined($$out) || length($$out) == 0) ? 0 : 1;