* [PATCH 1/3] net_reader: fix NNTP credential use
2024-01-10 11:18 [PATCH 0/3] lei NNTP + error handling fixes Eric Wong
@ 2024-01-10 11:18 ` Eric Wong
2024-01-10 11:18 ` [PATCH 2/3] lei+net_reader: show NNTP message in more failures Eric Wong
2024-01-10 11:18 ` [PATCH 3/3] lei_to_mail: show supported mbox formats on error Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2024-01-10 11:18 UTC (permalink / raw)
To: meta
Clearly this was never tested until now, as passwords being
retrieved by git-credential got completely ignored and unused.
This enables users to connect to NNTP(S) servers requiring a
password.
---
lib/PublicInbox/NetReader.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index e3e5d596..751043e9 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -291,7 +291,10 @@ sub nn_for ($$$$) { # nn = Net::NNTP
return if $self->{quit};
$nn // die "E: <$uri> new: $@".onion_hint($lei, $uri);
if ($cred) {
- $cred->fill($lei) unless defined($p); # may prompt user here
+ $p //= do {
+ $cred->fill($lei); # may prompt user here
+ $cred->{password};
+ };
if ($nn->authinfo($u, $p)) {
push @{$nntp_cfg->{-postconn}}, [ 'authinfo', $u, $p ];
} else {
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] lei+net_reader: show NNTP message in more failures
2024-01-10 11:18 [PATCH 0/3] lei NNTP + error handling fixes Eric Wong
2024-01-10 11:18 ` [PATCH 1/3] net_reader: fix NNTP credential use Eric Wong
@ 2024-01-10 11:18 ` Eric Wong
2024-01-10 11:18 ` [PATCH 3/3] lei_to_mail: show supported mbox formats on error Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2024-01-10 11:18 UTC (permalink / raw)
To: meta
Showing absolutely nothing when hitting a server requiring
authentication is a very bad user experience. While we're
at it, use Net::Cmd->message in more places where we experience
failure, too.
---
lib/PublicInbox/LeiLsMailSource.pm | 6 +++++-
lib/PublicInbox/NetReader.pm | 19 +++++++++++--------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm
index 4b427b26..ab6c1e60 100644
--- a/lib/PublicInbox/LeiLsMailSource.pm
+++ b/lib/PublicInbox/LeiLsMailSource.pm
@@ -42,7 +42,11 @@ sub input_path_url { # overrides LeiInput version
my $uri = PublicInbox::URInntps->new($url);
my $nn = $lei->{net}->nn_get($uri) or
return $lei->err("E: $uri");
- my $l = $nn->newsgroups($uri->group); # name => description
+ # $l = name => description
+ my $l = $nn->newsgroups($uri->group) // return $lei->err(<<EOM);
+E: $uri LIST NEWSGROUPS: ${\($lei->{net}->ndump($nn->message))}
+E: login may be required, try adding `-c nntp.debug' to your command
+EOM
my $sec = $lei->{net}->can('uri_section')->($uri);
if ($json) {
my $all = $nn->list;
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 751043e9..ec18818b 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -14,7 +14,7 @@ our @EXPORT = qw(uri_section imap_uri nntp_uri);
sub ndump {
require Data::Dumper;
- Data::Dumper->new(\@_)->Useqq(1)->Terse(1)->Dump;
+ Data::Dumper->new([ $_[-1] ])->Useqq(1)->Terse(1)->Dump;
}
# returns the git config section name, e.g [imap "imaps://user@example.com"]
@@ -240,19 +240,19 @@ sub nn_new ($$$$) {
try_starttls($nn_arg->{Host})) {
# soft fail by default
$nn->starttls or warn <<"";
-W: <$uri> STARTTLS tried and failed (not requested)
+W: <$uri> STARTTLS tried and failed (not requested): ${\(ndump($nn->message))}
} elsif ($nntp_cfg->{starttls}) {
# hard fail if explicitly configured
$nn->starttls or die <<"";
-E: <$uri> STARTTLS requested and failed
+E: <$uri> STARTTLS requested and failed: ${\(ndump($nn->message))}
}
} elsif ($nntp_cfg->{starttls}) {
$nn->can('starttls') or
die "E: <$uri> Net::NNTP too old for STARTTLS\n";
$nn->starttls or die <<"";
-E: <$uri> STARTTLS requested and failed
+E: <$uri> STARTTLS requested and failed: ${\(ndump($nn->message))}
}
$nn;
@@ -298,18 +298,21 @@ sub nn_for ($$$$) { # nn = Net::NNTP
if ($nn->authinfo($u, $p)) {
push @{$nntp_cfg->{-postconn}}, [ 'authinfo', $u, $p ];
} else {
- warn "E: <$uri> AUTHINFO $u XXXX failed\n";
+ warn <<EOM;
+E: <$uri> AUTHINFO $u XXXX: ${\(ndump($nn->message))}
+EOM
$nn = undef;
}
}
-
- if ($nntp_cfg->{compress}) {
+ if ($nn && $nntp_cfg->{compress}) {
# https://rt.cpan.org/Ticket/Display.html?id=129967
if ($nn->can('compress')) {
if ($nn->compress) {
push @{$nntp_cfg->{-postconn}}, [ 'compress' ];
} else {
- warn "W: <$uri> COMPRESS failed\n";
+ warn <<EOM;
+W: <$uri> COMPRESS: ${\(ndump($nn->message))}
+EOM
}
} else {
delete $nntp_cfg->{compress};
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] lei_to_mail: show supported mbox formats on error
2024-01-10 11:18 [PATCH 0/3] lei NNTP + error handling fixes Eric Wong
2024-01-10 11:18 ` [PATCH 1/3] net_reader: fix NNTP credential use Eric Wong
2024-01-10 11:18 ` [PATCH 2/3] lei+net_reader: show NNTP message in more failures Eric Wong
@ 2024-01-10 11:18 ` Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2024-01-10 11:18 UTC (permalink / raw)
To: meta
Users may accidentally or unknowingly write `mbox' and not know
we support 4 incompatible mbox variants.
---
lib/PublicInbox/LeiToMail.pm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index de75e99e..008da52e 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -407,7 +407,9 @@ sub new {
$lei->{opt}->{save} //= \1 if $lei->{cmd} eq 'q';
} elsif (substr($fmt, 0, 4) eq 'mbox') {
require PublicInbox::MboxReader;
- $self->can("eml2$fmt") or die "bad mbox format: $fmt\n";
+ $self->can("eml2$fmt") or die <<EOM;
+E: bad mbox format: $fmt (did you mean: mboxrd, mboxo, mboxcl, or mboxcl2?)
+EOM
$self->{base_type} = 'mbox';
if ($lei->{cmd} eq 'q' &&
(($lei->path_to_fd($dst) // -1) < 0) &&
^ permalink raw reply related [flat|nested] 4+ messages in thread