]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei index+import: reject keywords from R/O IMAP
authorEric Wong <e@80x24.org>
Sun, 13 Jun 2021 18:12:06 +0000 (18:12 +0000)
committerEric Wong <e@80x24.org>
Mon, 14 Jun 2021 20:00:48 +0000 (20:00 +0000)
Since users can't set IMAP flags in read-only IMAP folders,
we won't clobber local flags when importing from IMAP.  This
also enables the local_blob fallback used for lei-index to
be used for index deduplication.

lib/PublicInbox/LeiStore.pm
lib/PublicInbox/NetReader.pm
t/lei-index.t

index 5446873e4e2ebd327033ce9513e66e7388500a14..f978288a81612985f97673b520c9a1caf4c36016 100644 (file)
@@ -151,7 +151,8 @@ sub _docids_for ($$) {
                        my $oid = $cur->{blob};
                        my $docid = $cur->{num};
                        my $bref = $im ? $im->cat_blob($oid) : undef;
-                       $bref //= $eidx->git->cat_file($oid) // do {
+                       $bref //= $eidx->git->cat_file($oid) //
+                               _lms_rw($self)->local_blob($oid, 1) // do {
                                warn "W: $oid (#$docid) <$mid> not found\n";
                                next;
                        };
index 30784199e5b7018b5bbced09da66cff91525f971..0c2288d86c3bbbcafeab103fda215b59ab6b0934 100644 (file)
@@ -420,7 +420,8 @@ sub _imap_do_msg ($$$$$) {
        my ($self, $uri, $uid, $raw, $flags) = @_;
        # our target audience expects LF-only, save storage
        $$raw =~ s/\r\n/\n/sg;
-       my $kw = flags2kw($self, $uri, $uid, $flags) // return;
+       my $kw = defined($flags) ?
+               (flags2kw($self, $uri, $uid, $flags) // return) : undef;
        my ($eml_cb, @args) = @{$self->{eml_each}};
        $eml_cb->($uri, $uid, $kw, PublicInbox::Eml->new($raw), @args);
 }
@@ -537,8 +538,8 @@ E: $uri strangely, UIDVALIDLITY matches ($l_uidval)
 EOF
        $mic->Uid(1); # the default, we hope
        my $err;
-       if (!defined($single_uid) && $self->{each_old} &&
-                               perm_fl_ok($perm_fl)) {
+       my $use_fl = perm_fl_ok($perm_fl);
+       if (!defined($single_uid) && $self->{each_old} && $use_fl) {
                $err = each_old_flags($self, $mic, $uri, $l_uid);
                return $err if $err;
        }
@@ -593,8 +594,8 @@ EOF
                                # 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,
-                                               $per_uid->{FLAGS});
+                               my $fl = $use_fl ? $per_uid->{FLAGS} : undef;
+                               _imap_do_msg($self, $uri, $uid, \$raw, $fl);
                                $last_uid = $uid;
                                last if $self->{quit};
                        }
index c142e79c3617b140e7905aa75b8513a2630de480..eeda5196f411022100ba7bf9313f097ad1c86088 100644 (file)
@@ -80,6 +80,19 @@ test_lei({ tmpdir => $tmpdir }, sub {
        lei_ok('index', "nntp://$nntp_host_port/t.v2");
        lei_ok('index', "imap://$imap_host_port/t.v2.0");
        is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');
+
+       lei_ok qw(q m:multipart-html-sucks@11);
+       $res_a = json_utf8->decode($lei_out)->[0];
+       is_deeply($res_a->{'kw'}, ['seen'],
+               'keywords still set after NNTP + IMAP import');
+
+       # ensure import works after lms->local_blob fallback in lei/store
+       lei_ok('import', 't/mda-mime.eml');
+       lei_ok qw(q m:multipart-html-sucks@11);
+       $res_b = json_utf8->decode($lei_out)->[0];
+       my $t = xqx(['git', "--git-dir=$store_path/ALL.git",
+                       qw(cat-file -t), $res_b->{blob}]);
+       is($t, "blob\n", 'got blob');
 });
 
 done_testing;