From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/6] nntp: improve protocol error messages
Date: Fri, 15 Nov 2024 02:59:29 +0000 [thread overview]
Message-ID: <20241115025932.1647240-4-e@80x24.org> (raw)
In-Reply-To: <20241115025932.1647240-1-e@80x24.org>
NNTP clients (e.g. lei :P) may display the message from the
server, so it's helpful to tell them the article number or
Message-ID that's missing.
---
lib/PublicInbox/NNTP.pm | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 603cf094..1749a755 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -26,8 +26,8 @@ use constant {
r502 => "502 Command unavailable\r\n",
r221 => "221 Header follows\r\n",
r225 => "225 Headers follow (multi-line)\r\n",
- r430 => "430 No article with that message-id\r\n",
};
+sub r430 ($) { "430 No article with that message-id <$_[0]>\r\n" }
use Errno qw(EAGAIN);
my $ONE_MSGID = qr/\A$MID_EXTRACT\z/;
my @OVERVIEW = qw(Subject From Date Message-ID References);
@@ -466,17 +466,16 @@ sub set_nntp_headers ($$) {
sub art_lookup ($$$) {
my ($self, $art, $code) = @_;
- my ($ibx, $n);
- my $err;
+ my ($ibx, $n, $mid, $err);
if (defined $art) {
if ($art =~ /\A[0-9]+\z/) {
- $err = \"423 no such article number in this group\r\n";
+ $err = \"423 no such article (#$art) in this group\r\n";
$n = int($art);
goto find_ibx;
} elsif ($art =~ $ONE_MSGID) {
- ($ibx, $n) = mid_lookup($self, $1);
+ ($ibx, $n) = mid_lookup($self, $mid = $1);
goto found if $ibx;
- return \r430;
+ return \r430 $mid;
} else {
return \r501;
}
@@ -488,7 +487,13 @@ find_ibx:
return \"412 no newsgroup has been selected\r\n";
}
found:
- my $smsg = $ibx->over(1)->get_art($n) or return $err;
+ my $smsg = $ibx->over(1)->get_art($n) or do {
+ if (defined $mid) {
+ warn "BUG: $ibx->{newsgroup} <$mid> #$n missing";
+ return r430 $mid;
+ }
+ return $err;
+ };
$smsg->{-ibx} = $ibx;
if ($code == 223) { # STAT
set_art($self, $n);
@@ -632,8 +637,8 @@ sub hdr_message_id ($$$) { # optimize XHDR Message-ID [range] for slrnpull.
my ($self, $xhdr, $range) = @_;
if (defined $range && $range =~ $ONE_MSGID) {
- my ($ibx, $n) = mid_lookup($self, $1);
- return r430 unless $n;
+ my ($ibx, $n) = mid_lookup($self, my $mid = $1);
+ return r430 $mid unless $n;
hdr_mid_response($self, $xhdr, $ibx, $n, $range, $range);
} else { # numeric range
$range = $self->{article} unless defined $range;
@@ -703,7 +708,7 @@ sub hdr_xref ($$$) { # optimize XHDR Xref [range] for rtin
if (defined $range && $range =~ $ONE_MSGID) {
my $mid = $1;
my ($ibx, $n) = mid_lookup($self, $mid);
- return r430 unless $n;
+ return r430 $mid unless defined $n;
my $smsg = $ibx->over(1)->get_art($n) or return;
hdr_mid_response($self, $xhdr, $ibx, $n, $range,
xref($self, $ibx, $smsg));
@@ -747,8 +752,8 @@ sub smsg_range_i {
sub hdr_smsg ($$$$) {
my ($self, $xhdr, $field, $range) = @_;
if (defined $range && $range =~ $ONE_MSGID) {
- my ($ibx, $n) = mid_lookup($self, $1);
- return r430 unless defined $n;
+ my ($ibx, $n) = mid_lookup($self, my $mid = $1);
+ return r430 $mid unless defined $n;
my $v = over_header_for($ibx, $n, $field);
hdr_mid_response($self, $xhdr, $ibx, $n, $range, $v);
} else { # numeric range
@@ -849,9 +854,12 @@ sub over_line ($$$) {
sub cmd_over ($;$) {
my ($self, $range) = @_;
if ($range && $range =~ $ONE_MSGID) {
- my ($ibx, $n) = mid_lookup($self, $1);
- defined $n or return r430;
- my $smsg = $ibx->over(1)->get_art($n) or return r430;
+ my ($ibx, $n) = mid_lookup($self, my $mid = $1);
+ defined $n or return r430 $mid;
+ my $smsg = $ibx->over(1)->get_art($n) or do {
+ warn "BUG: $ibx->{newsgroup} <$mid> #$n missing";
+ return r430 $mid;
+ };
$self->msg_more(
"224 Overview information follows (multi-line)\r\n");
next prev parent reply other threads:[~2024-11-15 2:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 2:59 [PATCH 0/6] a few random small fixes and improvements Eric Wong
2024-11-15 2:59 ` [PATCH 1/6] tests: fix missing modules under TEST_RUN_MODE=0 Eric Wong
2024-11-15 2:59 ` [PATCH 2/6] test_common: disable fsync in git(1) commands Eric Wong
2024-11-15 2:59 ` Eric Wong [this message]
2024-11-15 2:59 ` [PATCH 4/6] nntp: integerize {article} to save memory Eric Wong
2024-11-15 2:59 ` [PATCH 5/6] view: reduce ops for <b> encasement Eric Wong
2024-11-15 2:59 ` [PATCH 6/6] view: fix obfuscation in message/* attachments 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=20241115025932.1647240-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.
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).