]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NetReader.pm
net_reader: drop support for IgnoreSizeErrors option
[public-inbox.git] / lib / PublicInbox / NetReader.pm
index 30b8f810d8fd4fa17653733536973446d022ddee..2b74af4142155a76a632369ebfed81b240c50f4b 100644 (file)
@@ -91,6 +91,16 @@ try configuring a socks5h:// proxy:
 EOM
 }
 
+# Net::NNTP doesn't support CAPABILITIES, yet; and both IMAP+NNTP
+# servers may have multiple listen sockets.
+sub try_starttls ($) {
+       my ($host) = @_;
+       return if $host =~ /\.onion\z/si;
+       return if $host =~ /\A127\.[0-9]+\.[0-9]+\.[0-9]+\z/s;
+       return if $host eq '::1';
+       1;
+}
+
 # mic_for may prompt the user and store auth info, prepares mic_get
 sub mic_for ($$$$) { # mic = Mail::IMAPClient
        my ($self, $uri, $mic_common, $lei) = @_;
@@ -122,6 +132,7 @@ sub mic_for ($$$$) { # mic = Mail::IMAPClient
        # it to be disabled since I usually connect to localhost
        if (!$mic_arg->{Ssl} && !defined($mic_arg->{Starttls}) &&
                        $mic->has_capability('STARTTLS') &&
+                       try_starttls($host) &&
                        $mic->can('starttls')) {
                $mic->starttls or die "E: <$uri> STARTTLS: $@\n";
        }
@@ -164,15 +175,6 @@ sub mic_for ($$$$) { # mic = Mail::IMAPClient
        $mic;
 }
 
-# Net::NNTP doesn't support CAPABILITIES, yet
-sub try_starttls ($) {
-       my ($host) = @_;
-       return if $host =~ /\.onion\z/s;
-       return if $host =~ /\A127\.[0-9]+\.[0-9]+\.[0-9]+\z/s;
-       return if $host eq '::1';
-       1;
-}
-
 sub nn_new ($$$) {
        my ($nn_arg, $nntp_cfg, $uri) = @_;
        my $nn;
@@ -326,7 +328,7 @@ sub imap_common_init ($;$) {
                my $sec = uri_section($uri);
 
                # knobs directly for Mail::IMAPClient->new
-               for my $k (qw(Starttls Debug Compress Ignoresizeerrors)) {
+               for my $k (qw(Starttls Debug Compress)) {
                        my $bool = cfg_bool($cfg, "imap.$k", $$uri) // next;
                        $mic_common->{$sec}->{$k} = $bool;
                }
@@ -342,10 +344,10 @@ sub imap_common_init ($;$) {
                }
                my $k = 'imap.fetchBatchSize';
                my $bs = $cfg->urlmatch($k, $$uri) // next;
-               if ($bs =~ /\A([0-9]+)\z/) {
+               if ($bs =~ /\A([0-9]+)\z/ && $bs > 0) {
                        $self->{cfg_opt}->{$sec}->{batch_size} = $bs;
                } else {
-                       warn "$k=$bs is not an integer\n";
+                       warn "$k=$bs is not a positive integer\n";
                }
        }
        # make sure we can connect and cache the credentials in memory
@@ -725,21 +727,27 @@ 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";
+       if (defined($num_a)) { # no article numbers in mail_sync.sqlite3
+               $uri = $uri->clone;
+               $uri->group($group);
+       }
        # 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";