]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NetReader.pm
net_reader: fix single NNTP article fetch, test ranges
[public-inbox.git] / lib / PublicInbox / NetReader.pm
index a5aab65024fedadf64ac6b04de12c9ac151a5a08..236e824cd26d48ec2326b97455b139d0b5841a65 100644 (file)
@@ -71,19 +71,21 @@ sub onion_hint ($$) {
        my ($lei, $uri) = @_;
        $uri->host =~ /\.onion\z/i or return "\n";
        my $t = $uri->isa('PublicInbox::URIimap') ? 'imap' : 'nntp';
-       my $url = uri_section($uri);
+       my $url = PublicInbox::Config::squote_maybe(uri_section($uri));
        my $set_cfg = 'lei config';
        if (!$lei) { # public-inbox-watch
-               my $f = $ENV{PI_CONFIG} || '~/.public-inbox/config';
+               my $f = PublicInbox::Config::squote_maybe(
+                               $ENV{PI_CONFIG} || '~/.public-inbox/config');
                $set_cfg = "git config -f $f";
        }
+       my $dq = substr($url, 0, 1) eq "'" ? '"' : '';
        <<EOM
 
 Assuming you have Tor configured and running locally on port 9050,
 try configuring a socks5h:// proxy:
 
        url=$url
-       $set_cfg $t.\$url.proxy socks5h://127.0.0.1:9050
+       $set_cfg $t.$dq\$url$dq.proxy socks5h://127.0.0.1:9050
 
 ...before retrying your current command
 EOM
@@ -182,6 +184,7 @@ sub nn_new ($$$) {
        } else {
                $nn = Net::NNTP->new(%$nn_arg) or return;
        }
+       setsockopt($nn, Socket::SOL_SOCKET(), Socket::SO_KEEPALIVE(), 1);
 
        # default to using STARTTLS if it's available, but allow
        # it to be disabled for localhost/VPN users
@@ -722,21 +725,24 @@ sub _nntp_fetch_all ($$$) {
                my $msg = ndump($nn->message);
                return "E: GROUP $group <$sec> $msg";
        }
+       (defined($num_a) && defined($num_b) && $num_a > $num_b) and
+               return "E: $uri: backwards range: $num_a > $num_b";
 
        # IMAPTracker is also used for tracking NNTP, UID == article number
        # LIST.ACTIVE can get the equivalent of UIDVALIDITY, but that's
        # expensive.  So we assume newsgroups don't change:
        my ($itrk, $l_art) = itrk_last($self, $uri);
 
-       # allow users to specify articles to refetch
-       # cf. https://tools.ietf.org/id/draft-gilman-news-url-01.txt
-       # nntp://example.com/inbox.foo/$num_a-$num_b
-       $beg = $num_a if defined($num_a) && $num_a < $beg;
-       $end = $num_b if defined($num_b) && $num_b < $end;
-       if (defined $l_art) {
+       if (defined($l_art) && !defined($num_a)) {
                return if $l_art >= $end; # nothing to do
                $beg = $l_art + 1;
        }
+       # allow users to specify articles to refetch
+       # cf. https://tools.ietf.org/id/draft-gilman-news-url-01.txt
+       # nntp://example.com/inbox.foo/$num_a-$num_b
+       $beg = $num_a if defined($num_a) && $num_a > $beg && $num_a <= $end;
+       $end = $num_b if defined($num_b) && $num_b >= $beg && $num_b < $end;
+       $end = $beg if defined($num_a) && !defined($num_b);
        my ($err, $art, $last_art, $kw); # kw stays undef, no keywords in NNTP
        unless ($self->{quiet}) {
                warn "# $uri fetching ARTICLE $beg..$end\n";