about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-03 06:43:46 +0000
committerEric Wong <e@80x24.org>2023-10-03 10:16:05 +0000
commitf751ae24b9a4595f2feb493a21d2b18c27210688 (patch)
tree81dddb6640cf7e8cb6ce801d3f02e6ec840ef439 /lib/PublicInbox
parent699eeb49a23399671f8ed0fa142d6cdaa0593b60 (diff)
downloadpublic-inbox-f751ae24b9a4595f2feb493a21d2b18c27210688.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/NetReader.pm23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 32e4c20f..e14b5805 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -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);
 }