]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei import: support UIDVALIDITY in IMAP URL
authorEric Wong <e@80x24.org>
Thu, 29 Apr 2021 09:46:19 +0000 (09:46 +0000)
committerEric Wong <e@80x24.org>
Fri, 30 Apr 2021 06:41:36 +0000 (06:41 +0000)
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
lib/PublicInbox/NetReader.pm
t/lei-import-imap.t

index ce675f40b136d48ee683cd1a11a03c663b876a98..277ad88d99dd06b777a8469e28f42966b25c9c76 100644 (file)
@@ -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 {
index 81d25ead34f3e5b31a73acb7a0d0a5a1c995c4ad..3fc37b10f8b22efa52ca6ad223b3aa65a009f76a 100644 (file)
@@ -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;
 }
index 611328b4c1567ce4626cf9bea901189fdf1d9ba6..c977c68ef380d17129ef977ecd5136665ee2171b 100644 (file)
@@ -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);