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 7D2B21F9F3 for ; Fri, 22 Oct 2021 08:22:47 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] lei export-kw: don't recreate deleted IMAP folders Date: Fri, 22 Oct 2021 08:22:45 +0000 Message-Id: <20211022082247.29763-2-e@80x24.org> In-Reply-To: <20211022082247.29763-1-e@80x24.org> References: <20211022082247.29763-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: In case an IMAP folder is deleted, just set an error and ignore it rather than creating an empty folder which we attempt to export keywords to for non-existent messages. --- lib/PublicInbox/LeiExportKw.pm | 11 ++++++++--- lib/PublicInbox/NetReader.pm | 1 + xt/net_writer-imap.t | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm index ceeef7f21d54..12c8f4067e9e 100644 --- a/lib/PublicInbox/LeiExportKw.pm +++ b/lib/PublicInbox/LeiExportKw.pm @@ -67,9 +67,13 @@ sub input_path_url { $self->{lms}->each_src($input, \&export_kw_md, $self, $mdir); } elsif ($input =~ m!\Aimaps?://!i) { my $uri = PublicInbox::URIimap->new($input); - my $mic = $self->{nwr}->mic_for_folder($uri); - $self->{lms}->each_src($$uri, \&export_kw_imap, $self, $mic); - $mic->expunge; + if (my $mic = $self->{nwr}->mic_for_folder($uri)) { + $self->{lms}->each_src($$uri, \&export_kw_imap, + $self, $mic); + $mic->expunge; + } else { + $self->{lei}->child_error(0, "$input unavailable: $@"); + } } else { die "BUG: $input not supported" } } @@ -108,6 +112,7 @@ EOM $self->{nwr} = bless $net, 'PublicInbox::NetWriter'; $self->{imap_mod_kw} = $net->can($self->{-merge_kw} ? 'imap_add_kw' : 'imap_set_kw'); + $self->{nwr}->{-skip_creat} = 1; } my $ops = {}; $lei->{auth}->op_merge($ops, $self) if $lei->{auth}; diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm index 4da19ab969b5..032b4fda557c 100644 --- a/lib/PublicInbox/NetReader.pm +++ b/lib/PublicInbox/NetReader.pm @@ -359,6 +359,7 @@ sub imap_common_init ($;$) { mic_for($self, $uri, $mic_common, $lei) // die "Unable to continue\n"; next unless $self->isa('PublicInbox::NetWriter'); + next if $self->{-skip_creat}; my $dst = $orig_uri->mailbox // next; next if $mic->exists($dst); # already exists $mic->create($dst) or die "CREATE $dst failed <$orig_uri>: $@"; diff --git a/xt/net_writer-imap.t b/xt/net_writer-imap.t index cb2ea61ff8e3..afa4bcc3e881 100644 --- a/xt/net_writer-imap.t +++ b/xt/net_writer-imap.t @@ -83,8 +83,11 @@ my $mics = do { }; my $mic = (values %$mics)[0]; my $cleanup = PublicInbox::OnDestroy->new($$, sub { - my $mic = $nwr->mic_get($uri); - $mic->delete($folder) or fail "delete $folder <$folder_uri>: $@"; + if (defined($folder)) { + my $mic = $nwr->mic_get($uri); + $mic->delete($folder) or + fail "delete $folder <$folder_uri>: $@"; + } if ($tmpdir && -f "$tmpdir/.gitconfig") { local $ENV{HOME} = $tmpdir; system(qw(git credential-cache exit)); @@ -250,6 +253,14 @@ EOM lei_ok qw(q m:testmessage --no-external -o), $folder_url; lei_ok qw(up), $folder_url; lei_ok qw(up --all=remote); + $mic = $nwr->mic_get($uri); + $mic->delete($folder) or fail "delete $folder <$folder_uri>: $@"; + $mic->expunge; + undef $mic; + undef $folder; + ok(!lei(qw(export-kw), $folder_url), + 'export-kw fails w/ non-existent folder'); + }); undef $cleanup; # remove temporary folder