From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3290E1FC0B for ; Sat, 18 Sep 2021 09:33:34 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 7/9] net_reader: support imaps:// w/ socks5h:// proxy Date: Sat, 18 Sep 2021 09:33:30 +0000 Message-Id: <20210918093332.16054-8-e@80x24.org> In-Reply-To: <20210918093332.16054-1-e@80x24.org> References: <20210918093332.16054-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While Non-TLS IMAP worked perfectly with IO::Socket::Socks and Mail::IMAPClient; we need to wrap the IO::Socket::Socks object with IO::Socket::SSL before handing it to Mail::IMAPClient. --- lib/PublicInbox/NetReader.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm index 8eff847e..403df952 100644 --- a/lib/PublicInbox/NetReader.pm +++ b/lib/PublicInbox/NetReader.pm @@ -43,21 +43,26 @@ EOM sub mic_new ($$$$) { my ($self, $mic_arg, $sec, $uri) = @_; - my %mic_arg = %$mic_arg; + my %mic_arg = (%$mic_arg, Keepalive => 1); my $sa = $self->{cfg_opt}->{$sec}->{-proxy_cfg} || $self->{-proxy_cli}; if ($sa) { # this `require' needed for worker[1..Inf], since socks_args # only got called in worker[0] require IO::Socket::Socks; - - my %opt = %$sa; + my %opt = (%$sa, Keepalive => 1); $opt{SocksDebug} = 1 if $mic_arg{Debug}; $opt{ConnectAddr} = delete $mic_arg{Server}; $opt{ConnectPort} = delete $mic_arg{Port}; - $mic_arg{Socket} = IO::Socket::Socks->new(%opt) or die - "E: <$$uri> ".eval('$IO::Socket::Socks::SOCKS_ERROR'); + 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 + "E: <$uri> ".(IO::Socket::SSL->errstr // ''); + } + $mic_arg{Socket} = $s; } - PublicInbox::IMAPClient->new(%mic_arg, Keepalive => 1); + PublicInbox::IMAPClient->new(%mic_arg); } sub auth_anon_cb { '' }; # for Mail::IMAPClient::Authcallback @@ -103,7 +108,6 @@ sub mic_for ($$$$) { # mic = Mail::IMAPClient my $mic_arg = { Port => $uri->port, Server => $host, - Ssl => $uri->scheme eq 'imaps', %$common, # may set Starttls, Compress, Debug .... }; $mic_arg->{Ssl} = 1 if $uri->scheme eq 'imaps';