]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
net_reader: avoid IO::Socket::SSL 2.079..2.081 warning
authorEric Wong <e@80x24.org>
Tue, 3 Oct 2023 06:43:46 +0000 (06:43 +0000)
committerEric Wong <e@80x24.org>
Tue, 3 Oct 2023 10:16:05 +0000 (10:16 +0000)
IO::Socket::SSL had an unitialized variable warning from a bad
regexp for a few releases.  This will also prepare us to support
imap.sslverify as git does and possibly other TLS-related
options.

lib/PublicInbox/NetReader.pm

index 32e4c20ff7577e8825c2b1fe6db766b2615e0a52..e14b58054d0047f42893349ecbbffe72988e822e 100644 (file)
@@ -40,6 +40,15 @@ EOM
        die "$val not understood (only socks5h:// is supported)\n";
 }
 
+# gives an arrayref suitable for the Mail::IMAPClient Ssl or Starttls arg
+sub mic_tls_opt ($$) {
+       my ($o, $hostname) = @_;
+       require IO::Socket::SSL;
+       $o = {} if !ref($o);
+       $o->{SSL_hostname} //= $hostname;
+       [ map { ($_, $o->{$_}) } keys %$o ];
+}
+
 sub mic_new ($$$$) {
        my ($self, $mic_arg, $sec, $uri) = @_;
        my %mic_arg = (%$mic_arg, Keepalive => 1);
@@ -54,12 +63,20 @@ sub mic_new ($$$$) {
                $opt{ConnectPort} = delete $mic_arg{Port};
                my $s = IO::Socket::Socks->new(%opt) or die
                        "E: <$uri> ".eval('$IO::Socket::Socks::SOCKS_ERROR');
-               if ($mic_arg->{Ssl}) { # for imaps://
-                       require IO::Socket::SSL;
-                       $s = IO::Socket::SSL->start_SSL($s) or die
+               if (my $o = delete $mic_arg{Ssl}) { # for imaps://
+                       $o = mic_tls_opt($o, $opt{ConnectAddr});
+                       $s = IO::Socket::SSL->start_SSL($s, @$o) or die
                                "E: <$uri> ".(IO::Socket::SSL->errstr // '');
+               } elsif ($o = $mic_arg{Starttls}) {
+                       # Mail::IMAPClient will use this:
+                       $mic_arg{Starttls} = mic_tls_opt($o, $opt{ConnectAddr});
                }
                $mic_arg{Socket} = $s;
+       } elsif ($mic_arg{Ssl} || $mic_arg{Starttls}) {
+               for my $f (qw(Ssl Starttls)) {
+                       my $o = $mic_arg{$f} or next;
+                       $mic_arg{$f} = mic_tls_opt($o, $mic_arg{Server});
+               }
        }
        PublicInbox::IMAPClient->new(%mic_arg);
 }