]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei import: set +(L|kw) on already-imported blobs
authorEric Wong <e@80x24.org>
Thu, 15 Jun 2023 08:46:37 +0000 (08:46 +0000)
committerEric Wong <e@80x24.org>
Thu, 15 Jun 2023 19:40:55 +0000 (19:40 +0000)
When import hits blobs it's already seen, we'll add labels
regardless in order to match the behavior of other inexact
matches.  This is useful when importing exact copies of
messages which exist in multiple mailboxes.

I noticed this when I had a message imported from my normal IMAP
`INBOX', but also copied it to a different folder for future
reference.

Documentation/RelNotes/v2.0.0.wip
lib/PublicInbox/LeiStore.pm
t/lei-import.t

index cd90bdae8f9391f0265324643ab57832c130b971..cccf11ae587df8a121a8ccd6a8b9b0f83f2a0a47 100644 (file)
@@ -60,6 +60,9 @@ lei
   * fix `lei q -tt' on locally-indexed messages (still broken for remotes:
     https://public-inbox.org/meta/20230226170931.M947721@dcvr/ )
 
+  * `lei import' now set labels+keywords consistently on all
+     already-imported messages
+
 solver (used by lei (rediff|blob), and PublicInbox::WWW)
 
   * handle copies in patches properly
index cf5a03a0e9e351fe6df6085f085c7c766cd7c929..727de0663f939c306349f7d8a145923be6692981 100644 (file)
@@ -387,8 +387,14 @@ sub add_eml {
                _lms_rw($self)->set_src($smsg->oidbin, @{$vmd->{sync_info}});
        }
        unless ($im_mark) { # duplicate blob returns undef
-               return unless wantarray;
+               return unless wantarray || $vmd;
                my @docids = $oidx->blob_exists($smsg->{blob});
+               if ($vmd) {
+                       for my $docid (@docids) {
+                               my $idx = $eidx->idx_shard($docid);
+                               _add_vmd($self, $idx, $docid, $vmd);
+                       }
+               }
                return _docids_and_maybe_kw $self, \@docids;
        }
 
index 6e9a853cf421d8a6ce6c2fbbe1bb06c45b65c7b3..c9e668a3ddac64aa0abf4bae8cfc454206d70297 100644 (file)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 test_lei(sub {
@@ -110,6 +110,21 @@ $res = json_utf8->decode($lei_out);
 is_deeply($res->[0]->{kw}, ['seen'], 'keyword set');
 is_deeply($res->[0]->{L}, ['inbox'], 'label set');
 
+# idempotent import can add label
+lei_ok([qw(import -F eml - +L:boombox)],
+       undef, { %$lei_opt, 0 => \$eml_str });
+lei_ok(qw(q m:inbox@example.com));
+$res = json_utf8->decode($lei_out);
+is_deeply($res->[0]->{kw}, ['seen'], 'keyword remains set');
+is_deeply($res->[0]->{L}, [qw(boombox inbox)], 'new label added');
+
+# idempotent import can add keyword
+lei_ok([qw(import -F eml - +kw:answered)],
+       undef, { %$lei_opt, 0 => \$eml_str });
+lei_ok(qw(q m:inbox@example.com));
+$res = json_utf8->decode($lei_out);
+is_deeply($res->[0]->{kw}, [qw(answered seen)], 'keyword added');
+is_deeply($res->[0]->{L}, [qw(boombox inbox)], 'labels preserved');
 
 # see t/lei_to_mail.t for "import -F mbox*"
 });