From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 24ACC1FA18 for ; Sun, 2 May 2021 06:05:43 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/6] net_writer: use "FLAGS.SILENT" to set keywords Date: Sun, 2 May 2021 06:05:41 +0000 Message-Id: <20210502060542.11598-6-e@80x24.org> In-Reply-To: <20210502060542.11598-1-e@80x24.org> References: <20210502060542.11598-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Instead of "+FLAGS.SILENT" which merely adds to the keywords. We store all keywords together, so it's unlikely we will rely on the "+FLAGS.SILENT" or "-FLAGS.SILENT". --- lib/PublicInbox/NetWriter.pm | 14 ++++++-------- xt/net_writer-imap.t | 9 +++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/NetWriter.pm b/lib/PublicInbox/NetWriter.pm index 49ac02a6..06d69f27 100644 --- a/lib/PublicInbox/NetWriter.pm +++ b/lib/PublicInbox/NetWriter.pm @@ -53,17 +53,15 @@ sub imap_delete_1 { $$delete_mic->delete_message($uid); } -sub imap_set_kw { - my ($self, $url, $uid, $kw) = @_; - my $mic = mic_for_folder($self, my $uri = $url) or return; - $mic->set_flag(kw2flags($kw), $uid); +sub imap_add_kw { + my ($self, $mic, $uid, $kw) = @_; + $mic->store($uid, '+FLAGS.SILENT', '('.kw2flags($kw).')'); $mic; # caller must ->expunge } -sub imap_unset_kw { - my ($self, $url, $uid, $kw) = @_; - my $mic = mic_for_folder($self, my $uri = $url) or return; - $mic->unset_flag(kw2flags($kw), $uid); +sub imap_set_kw { + my ($self, $mic, $uid, $kw) = @_; + $mic->store($uid, 'FLAGS.SILENT', '('.kw2flags($kw).')'); $mic; # caller must ->expunge } diff --git a/xt/net_writer-imap.t b/xt/net_writer-imap.t index 007de35e..1298b958 100644 --- a/xt/net_writer-imap.t +++ b/xt/net_writer-imap.t @@ -157,8 +157,13 @@ test_lei(sub { lei_ok qw(import -F eml), $f, \'import local copy w/o keywords'; - $nwr->imap_set_kw($folder_uri, $uid[0], [ 'seen' ])->expunge - or BAIL_OUT "expunge $@"; + $mic = $nwr->mic_for_folder($folder_uri); + # dummy set to ensure second set_kw clobbers + $nwr->imap_set_kw($mic, $uid[0], [ qw(seen answered flagged) ] + )->expunge or BAIL_OUT "expunge $@"; + $nwr->imap_set_kw($mic, $uid[0], [ 'seen' ] + )->expunge or BAIL_OUT "expunge $@"; + $mic = undef; @res = (); $nwr->imap_each($folder_uri, $imap_slurp_all, \@res); is_deeply(\@res, [ [ ['seen'], $exp ] ], 'seen flag set') or