]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
mda: fix and test some usage problems
authorEric Wong <e@80x24.org>
Sat, 11 Nov 2023 09:04:58 +0000 (09:04 +0000)
committerEric Wong <e@80x24.org>
Sat, 11 Nov 2023 21:20:44 +0000 (21:20 +0000)
-mda now honors `--help' properly and invocations missing
ORIGINAL_RECIPIENT now fail with EX_NOUSER.

Helped-by: Leah Neukirchen <leah@vuxu.org>
Link: https://public-inbox.org/meta/87msvlguqu.fsf@vuxu.org/
script/public-inbox-mda
t/mda.t

index 04fd8aad4d4956a10816156b3752df9bf3910c31..b2e0908d52403bab6058746f36f4f8e930aadd21 100755 (executable)
@@ -20,6 +20,10 @@ use PublicInbox::Import;
 local $PublicInbox::Import::DROP_UNIQUE_UNSUB; # does this need a CLI switch?
 GetOptions('precheck!' => \$precheck, 'help|h' => \$show_help) or
        do { print STDERR $help; exit 1 };
+if ($show_help) {
+       print $help;
+       exit;
+}
 
 my $do_exit = sub {
        my ($code) = shift;
@@ -59,7 +63,8 @@ if (defined $recipient) {
 if (!scalar(@$dests)) {
        $dests = PublicInbox::MDA->inboxes_for_list_id($cfg, $eml);
        if (!scalar(@$dests) && !defined($recipient)) {
-               die "ORIGINAL_RECIPIENT not defined in ENV\n";
+               warn "ORIGINAL_RECIPIENT not defined in ENV\n";
+               $do_exit->(67); # EX_NOUSER
        }
        scalar(@$dests) or $do_exit->(67); # EX_NOUSER 5.1.1 user unknown
 }
diff --git a/t/mda.t b/t/mda.t
index 5144f3cace1022a1d9e6f5e44ccb89d08be3156d..1d9e237ba7098cae45e68210967dd8ac0dd3b027 100644 (file)
--- a/t/mda.t
+++ b/t/mda.t
@@ -82,6 +82,13 @@ die $@ if $@;
        local $ENV{PI_EMERGENCY} = $faildir;
        local $ENV{HOME} = $home;
        local $ENV{ORIGINAL_RECIPIENT} = $addr;
+       ok(run_script([qw(-mda --help)], undef,
+               { 1 => \my $out, 2 => \my $err }), '-mda --help');
+       like $out, qr/usage:/, 'usage shown w/ --help';
+       ok(!run_script([qw(-mda --bogus)], undef,
+               { 1 => \$out, 2 => \$err }), '-mda --bogus fails');
+       like $err, qr/usage:/, 'usage shown on bogus switch';
+
        my $in = <<EOF;
 From: Me <me\@example.com>
 To: You <you\@example.com>
@@ -91,6 +98,17 @@ Subject: hihi
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 EOF
+       {
+               local $ENV{PATH} = $main_path;
+               ok(!run_script(['-mda'], { ORIGINAL_RECIPIENT => undef },
+                       { 0 => \$in, 2 => \$err }),
+                       'missing ORIGINAL_RECIPIENT fails');
+               is($? >> 8, 67, 'got EX_NOUSER');
+               like $err, qr/\bORIGINAL_RECIPIENT\b/,
+                       'ORIGINAL_RECIPIENT noted in stderr';
+               is unlink(glob("$faildir/*/*")), 1, 'unlinked failed message';
+       }
+
        # ensure successful message delivery
        {
                local $ENV{PATH} = $main_path;