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 die
+ "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
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
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';
require PublicInbox::IMAPClient;
- my $mic = mic_new($self, $mic_arg, $sec, $uri) or
+ my $mic = mic_new($self, $mic_arg, $sec, $uri);
+ ($mic && $mic->IsConnected) or
die "E: <$uri> new: $@".onion_hint($lei, $uri);
# default to using STARTTLS if it's available, but allow
} 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