user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] mda: fix and test some usage problems
Date: Sat, 11 Nov 2023 09:04:58 +0000	[thread overview]
Message-ID: <20231111090459.605791-4-e@80x24.org> (raw)
In-Reply-To: <20231111090459.605791-1-e@80x24.org>

-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 |  7 ++++++-
 t/mda.t                 | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 04fd8aad..b2e0908d 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -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 5144f3ca..1d9e237b 100644
--- 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;

  parent reply	other threads:[~2023-11-11  9:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-11  9:04 [PATCH 0/4] support publicinboxImport.dropUniqueUnsubscribe Eric Wong
2023-11-11  9:04 ` [PATCH 1/4] learn: fix redundant ham import on dual matches Eric Wong
2023-11-11  9:04 ` [PATCH 2/4] mda|learn|watch: support dropUniqueUnsubscribe config Eric Wong
2023-11-11  9:04 ` Eric Wong [this message]
2023-11-11  9:04 ` [PATCH 4/4] doc: update README.unsubscribe Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231111090459.605791-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).