]> Sergey Matveev's repositories - public-inbox.git/commitdiff
net_reader: imap_each: add UIDVALIDITY to URL arg
authorEric Wong <e@80x24.org>
Sat, 24 Apr 2021 09:28:43 +0000 (09:28 +0000)
committerEric Wong <e@80x24.org>
Sat, 24 Apr 2021 20:10:01 +0000 (16:10 -0400)
This will allow the callback to reliably maintain OID <=> UID
mappings between lei/store and the IMAP folder.

lib/PublicInbox/NetReader.pm
t/net_reader-imap.t

index 39129b342f0134f59e42033d1748a798ac271aac..5978752f5c0297c3e32a4ef340158d146320e086 100644 (file)
@@ -347,7 +347,7 @@ sub errors {
 }
 
 sub _imap_do_msg ($$$$$) {
-       my ($self, $uri, $uid, $raw, $flags) = @_;
+       my ($self, $url, $uid, $raw, $flags) = @_;
        # our target audience expects LF-only, save storage
        $$raw =~ s/\r\n/\n/sg;
        my $kw = [];
@@ -358,12 +358,12 @@ sub _imap_do_msg ($$$$$) {
                } elsif ($f eq "\\Deleted") { # not in JMAP
                        return;
                } elsif ($self->{verbose}) {
-                       warn "# unknown IMAP flag $f <$uri;uid=$uid>\n";
+                       warn "# unknown IMAP flag $f <$url/;UID=$uid>\n";
                }
        }
        @$kw = sort @$kw; # for all UI/UX purposes
        my ($eml_cb, @args) = @{$self->{eml_each}};
-       $eml_cb->($uri, $uid, $kw, PublicInbox::Eml->new($raw), @args);
+       $eml_cb->($url, $uid, $kw, PublicInbox::Eml->new($raw), @args);
 }
 
 sub run_commit_cb ($) {
@@ -396,6 +396,9 @@ sub _imap_fetch_all ($$$) {
                return "E: $uri cannot get UIDVALIDITY";
        $r_uidnext //= $mic->uidnext($mbx) //
                return "E: $uri cannot get UIDNEXT";
+       my $url = ref($uri)->new($$uri);
+       $url->uidvalidity($r_uidval);
+       $url = $$url;
        my $itrk = _itrk($self, $uri);
        my $l_uid;
        $l_uid = $itrk->get_last($r_uidval) if $itrk;
@@ -455,7 +458,7 @@ sub _imap_fetch_all ($$$) {
                                # messages get deleted, so holes appear
                                my $per_uid = delete $r->{$uid} // next;
                                my $raw = delete($per_uid->{$key}) // next;
-                               _imap_do_msg($self, $uri, $uid, \$raw,
+                               _imap_do_msg($self, $url, $uid, \$raw,
                                                $per_uid->{FLAGS});
                                $last_uid = $uid;
                                last if $self->{quit};
index e478ee07fdced399e7d37e5158af438779d88868..5de8f92b809b654af2e76753cc3b99bc585bc261 100644 (file)
@@ -33,7 +33,9 @@ is(scalar(@w), 0, 'no warnings');
 ok($nr, 'got some emails');
 is($eml{'PublicInbox::Eml'}, $nr, 'got expected Eml objects');
 is(scalar keys %eml, 1, 'only got Eml objects');
-is($urls{$url}, $nr, 'one URL expected number of times');
+is(scalar(grep(/\A\Q$url\E;UIDVALIDITY=\d+\z/, keys %urls)), scalar(keys %urls),
+       'UIDVALIDITY added to URL passed to callback');
+is_deeply([values %urls], [$nr], 'one URL expected number of times');
 is(scalar keys %urls, 1, 'only got one URL');
 is($args{blah}, $nr, 'got arg expected number of times');
 is(scalar keys %args, 1, 'only got one arg');