user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] nntp: support optional [range] arg in LISTGROUP
Date: Sat, 13 Jul 2019 21:42:46 +0000
Message-ID: <20190713214246.6344-1-e@80x24.org> (raw)

RFC3977 6.1.2.2 LISTGROUP allows a [range] arg after [group],
and supporting it allows NNTP support in neomutt to work again.

Tested with NeoMutt 20170113 (1.7.2) on Debian stretch
(oldstable)
---
 lib/PublicInbox/Msgmap.pm |  7 ++++---
 lib/PublicInbox/NNTP.pm   | 34 +++++++++++++++++++++++-----------
 t/nntpd.t                 |  1 +
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 5a89b85a..e74a3aef 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -211,11 +211,12 @@ ORDER BY num ASC LIMIT 1000
 }
 
 sub msg_range {
-	my ($self, $beg, $end) = @_;
+	my ($self, $beg, $end, $cols) = @_;
+	$cols //= 'num,mid';
 	my $dbh = $self->{dbh};
 	my $attr = { Columns => [] };
-	my $mids = $dbh->selectall_arrayref(<<'', $attr, $$beg, $end);
-SELECT num,mid FROM msgmap WHERE num >= ? AND num <= ?
+	my $mids = $dbh->selectall_arrayref(<<"", $attr, $$beg, $end);
+SELECT $cols FROM msgmap WHERE num >= ? AND num <= ?
 ORDER BY num ASC LIMIT 1000
 
 	$$beg = $mids->[-1]->[0] + 1 if @$mids;
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 800ce926..7c3f68a2 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -221,22 +221,34 @@ sub cmd_list ($;$$) {
 	'.'
 }
 
-sub cmd_listgroup ($;$) {
-	my ($self, $group) = @_;
+sub cmd_listgroup ($;$$) {
+	my ($self, $group, $range) = @_;
 	if (defined $group) {
 		my $res = cmd_group($self, $group);
 		return $res if ($res !~ /\A211 /);
 		more($self, $res);
 	}
-
-	$self->{ng} or return '412 no newsgroup selected';
-	my $n = 0;
-	long_response($self, sub {
-		my $ary = $self->{ng}->mm->ids_after(\$n);
-		scalar @$ary or return;
-		more($self, join("\r\n", @$ary));
-		1;
-	});
+	my $ng = $self->{ng} or return '412 no newsgroup selected';
+	my $mm = $ng->mm;
+	if (defined $range) {
+		my $r = get_range($self, $range);
+		return $r unless ref $r;
+		my ($beg, $end) = @$r;
+		long_response($self, sub {
+			$r = $mm->msg_range(\$beg, $end, 'num');
+			scalar(@$r) or return;
+			more($self, join("\r\n", map { "$_->[0]\r\n" } @$r));
+			1;
+		});
+	} else { # grab every article number
+		my $n = 0;
+		long_response($self, sub {
+			my $ary = $mm->ids_after(\$n);
+			scalar(@$ary) or return;
+			more($self, join("\r\n", @$ary));
+			1;
+		});
+	}
 }
 
 sub parse_time ($$;$) {
diff --git a/t/nntpd.t b/t/nntpd.t
index bebecc69..b47cf7db 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -100,6 +100,7 @@ EOF
 	is_deeply($list, { $group => [ qw(1 1 n) ] }, 'LIST works');
 	is_deeply([$n->group($group)], [ qw(0 1 1), $group ], 'GROUP works');
 	is_deeply($n->listgroup($group), [1], 'listgroup OK');
+	# TODO: Net::NNTP::listgroup does not support range at the moment
 
 	{
 		my $expect = [ qw(Subject: From: Date: Message-ID:
-- 
EW


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publically 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=20190713214246.6344-1-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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox