]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: support optional [range] arg in LISTGROUP
authorEric Wong <e@80x24.org>
Sat, 13 Jul 2019 21:42:46 +0000 (21:42 +0000)
committerEric Wong <e@80x24.org>
Sat, 13 Jul 2019 21:49:45 +0000 (21:49 +0000)
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
lib/PublicInbox/NNTP.pm
t/nntpd.t

index 5a89b85a51e297660291f0c4e5477bd2865608da..e74a3aef4e01f8e71410b93ad66a42e2a2eb7cdc 100644 (file)
@@ -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;
index 800ce9265268eec77b240acfee66ecb82c74ca99..7c3f68a2b372390526bf15dea906b9e0b6bb1acd 100644 (file)
@@ -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 ($$;$) {
index bebecc6920d947939f644bae675123fcd1b3f4c3..b47cf7db33a512bcd204a05b6b0fd0ad7ea2e3b4 100644 (file)
--- 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: