]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mda: support --no-precheck option
authorEric Wong <e@80x24.org>
Wed, 16 Oct 2019 00:39:56 +0000 (00:39 +0000)
committerEric Wong <e@80x24.org>
Wed, 16 Oct 2019 08:13:11 +0000 (08:13 +0000)
Since -mda now supports List-ID to better support mirroring of
existing mailing lists, it probably makes sense to support
disabling the precheck function to provide more accurate (though
potentially spammier) mirrors of lists

Documentation/public-inbox-mda.pod
script/public-inbox-mda
t/mda.t

index 921b7a152fb440a27f623f3a2255bec84e39961c..01bb84764bb1d379df14a9a82bbb9e7f2599e8e5 100644 (file)
@@ -16,6 +16,31 @@ By default, it relies on L<spamc(1)> for filtering mail,
 but may be disabled via
 L<public-inbox-config(5)/publicinboxmda.spamcheck>
 
 but may be disabled via
 L<public-inbox-config(5)/publicinboxmda.spamcheck>
 
+=head1 OPTIONS
+
+=over 8
+
+=item --no-precheck
+
+By default, public-inbox-mda does some simple checks before
+invoking L<spamc(1)> since it is intended to receive mail before
+it goes to a mailing list.
+
+However, some users prefer to use public-inbox-mda to mirror
+mailing lists.  This option exists to support those users.
+
+Using this option, the following prechecks are disabled:
+
+  * multiple Message-IDs
+  * non-existent Message-IDs
+  * Message-IDs longer than 244 characters long
+  * From: header shorter than 3 characters
+  * Subject: header shorter than 2 characters
+  * unusable Date: headers
+  * inbox address specified in To: or Cc: header
+
+=back
+
 =head1 ENVIRONMENT
 
 =over 8
 =head1 ENVIRONMENT
 
 =over 8
index 2655a6c5ed064aad67b97f0c575a3212cde68344..9b8753da1877d320bc4fb0f2d32a6d0f208f3066 100755 (executable)
@@ -5,7 +5,8 @@
 # Mail delivery agent for public-inbox, run from your MTA upon mail delivery
 use strict;
 use warnings;
 # Mail delivery agent for public-inbox, run from your MTA upon mail delivery
 use strict;
 use warnings;
-my $usage = 'public-inbox-mda < rfc2822_message';
+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 ($ems, $emm);
 
 sub do_exit {
@@ -55,7 +56,9 @@ $dst->{mainrepo} or do_exit(67);
 $dst = PublicInbox::InboxWritable->new($dst);
 
 # pre-check, MDA has stricter rules than an importer might;
 $dst = PublicInbox::InboxWritable->new($dst);
 
 # pre-check, MDA has stricter rules than an importer might;
-do_exit(0) unless PublicInbox::MDA->precheck($simple, $dst->{address});
+if ($precheck && !PublicInbox::MDA->precheck($simple, $dst->{address})) {
+       do_exit(0);
+}
 $simple = undef;
 my $spam_ok;
 if ($spamc) {
 $simple = undef;
 my $spam_ok;
 if ($spamc) {
diff --git a/t/mda.t b/t/mda.t
index 3cab590b78f9a9d2728c213706bc229e3ba81aad..92e8ad0dbed26c7824490992cc5cabd0fef7a65d 100644 (file)
--- a/t/mda.t
+++ b/t/mda.t
@@ -293,6 +293,21 @@ EOF
        my $path = mid2path($mid);
        my $msg = `git --git-dir=$maindir cat-file blob HEAD:$path`;
        like($msg, qr/\Q$list_id\E/, 'delivered message w/ List-ID matches');
        my $path = mid2path($mid);
        my $msg = `git --git-dir=$maindir cat-file blob HEAD:$path`;
        like($msg, qr/\Q$list_id\E/, 'delivered message w/ List-ID matches');
+
+       # try a message w/o precheck
+       $simple = Email::Simple->new(<<EOF);
+To: You <you\@example.com>
+List-Id: <$list_id>
+
+this message would not be accepted without --no-precheck
+EOF
+       $in = $simple->as_string;
+       my ($out, $err) = ('', '');
+       IPC::Run::run([$mda, '--no-precheck'], \$in, \$out, \$err);
+       is($?, 0, 'mda OK with List-Id match and --no-precheck');
+       my $cur = `git --git-dir=$maindir diff HEAD~1..HEAD`;
+       like($cur, qr/this message would not be accepted without --no-precheck/,
+               '--no-precheck delivered message anyways');
 }
 
 done_testing();
 }
 
 done_testing();