From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] lei import: support UIDVALIDITY in IMAP URL
Date: Thu, 29 Apr 2021 09:46:19 +0000 [thread overview]
Message-ID: <20210429094620.15195-4-e@80x24.org> (raw)
In-Reply-To: <20210429094620.15195-1-e@80x24.org>
Specifying a UIDVALIDITY value allows the user to enforce
a strict match and force failure. This necessitated changes
to NetReader to allow die() and make error reporting more
suitable for CLI usage rather than daemonized usage of -watch.
---
lib/PublicInbox/LeiInput.pm | 10 +++++++++-
lib/PublicInbox/NetReader.pm | 7 +++++++
t/lei-import-imap.t | 4 ++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm
index ce675f40..277ad88d 100644
--- a/lib/PublicInbox/LeiInput.pm
+++ b/lib/PublicInbox/LeiInput.pm
@@ -293,6 +293,7 @@ $input is `eml', not --in-format=$in_fmt
$lei->err("# --sync is not supported for: @{$sync->{no}}");
}
if ($net) {
+ $net->{-can_die} = 1;
if (my $err = $net->errors) {
return $lei->fail($err);
}
@@ -306,10 +307,17 @@ $input is `eml', not --in-format=$in_fmt
sub process_inputs {
my ($self) = @_;
+ my $err;
for my $input (@{$self->{inputs}}) {
- $self->input_path_url($input);
+ eval { $self->input_path_url($input) };
+ next unless $@;
+ $err = "$input: $@";
+ last;
}
+ # always commit first, even on error partial work is acceptable for
+ # lei <import|tag|convert>
my $wait = $self->{lei}->{sto}->ipc_do('done') if $self->{lei}->{sto};
+ $self->{lei}->fail($err) if $err;
}
sub input_only_atfork_child {
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 81d25ead..3fc37b10 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -407,6 +407,11 @@ sub _imap_fetch_all ($$$) {
return "E: $orig_uri cannot get UIDVALIDITY";
$r_uidnext //= $mic->uidnext($mbx) //
return "E: $orig_uri cannot get UIDNEXT";
+ my $expect = $orig_uri->uidvalidity // $r_uidval;
+ return <<EOF if $expect != $r_uidval;
+E: $orig_uri UIDVALIDITY mismatch (got $r_uidval)
+EOF
+
my $uri = $orig_uri->clone;
my ($itrk, $l_uid, $l_uidval) = _itrk_last($self, $uri, $r_uidval);
return <<EOF if $l_uidval != $r_uidval;
@@ -520,6 +525,7 @@ sub imap_each {
} else {
$err = "E: <$uri> not connected: $!";
}
+ die $err if $err && $self->{-can_die};
warn $err if $err;
$mic;
}
@@ -620,6 +626,7 @@ sub nntp_each {
} else {
$err = "E: <$uri> not connected: $!";
}
+ die $err if $err && $self->{-can_die};
warn $err if $err;
$nn;
}
diff --git a/t/lei-import-imap.t b/t/lei-import-imap.t
index 611328b4..c977c68e 100644
--- a/t/lei-import-imap.t
+++ b/t/lei-import-imap.t
@@ -24,6 +24,10 @@ test_lei({ tmpdir => $tmpdir }, sub {
lei_ok('import', $url);
lei_ok 'ls-sync';
like($lei_out, qr!\A\Q$url\E;UIDVALIDITY=\d+\n\z!, 'ls-sync');
+ chomp(my $u = $lei_out);
+ lei_ok('import', $u, \'UIDVALIDITY match in URL');
+ $u =~ s/;UIDVALIDITY=(\d+)\s*/;UIDVALIDITY=9$1/s;
+ ok(!lei('import', $u), 'UIDVALIDITY mismatch in URL rejected');
lei_ok('inspect', $url);
my $inspect = json_utf8->decode($lei_out);
next prev parent reply other threads:[~2021-04-29 9:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 9:46 [PATCH 0/4] some lei synchronization work Eric Wong
2021-04-29 9:46 ` [PATCH 1/4] content_hash: git_sha: allow unblessed SCALAR refs Eric Wong
2021-04-29 9:46 ` [PATCH 2/4] lei import: avoid IMAPTracker, use LeiMailSync more Eric Wong
2021-04-29 9:46 ` Eric Wong [this message]
2021-04-29 9:46 ` [PATCH 4/4] lei import: support shell completion of known folders Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210429094620.15195-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).