From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 88D711F542 for ; Thu, 15 Jun 2023 08:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1686818797; bh=Qhjr19tmo7tcKlSJf+CEOlcFOeWpTermoxIhnSQXnoY=; h=From:To:Subject:Date:From; b=KuVDQ2oweqUNIClODq2j8xQgPwkJbI77zp5sQTTmX3Cs8c3h7VGYdIb18or9KgrEa vHEHuu4pjGfbSLV+OJE0WDAdSearFTRWx3msU8dQ3lDDaJG2NQ1Q6h/xxP62h7Zojx jictXmVN2bRkVy3+o2QDJknY4FqHoHe3iwbWj3uo= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei import: set +(L|kw) on already-imported blobs Date: Thu, 15 Jun 2023 08:46:37 +0000 Message-ID: <20230615084637.374646-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 3 +++ lib/PublicInbox/LeiStore.pm | 8 +++++++- t/lei-import.t | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Documentation/RelNotes/v2.0.0.wip b/Documentation/RelNotes/v2.0.0.wip index cd90bdae..cccf11ae 100644 --- a/Documentation/RelNotes/v2.0.0.wip +++ b/Documentation/RelNotes/v2.0.0.wip @@ -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 diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index cf5a03a0..727de066 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -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; } diff --git a/t/lei-import.t b/t/lei-import.t index 6e9a853c..c9e668a3 100644 --- a/t/lei-import.t +++ b/t/lei-import.t @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2020-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ 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*" });