user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20211022082247.29763-2-e@80x24.org> (raw)
In-Reply-To: <20211022082247.29763-1-e@80x24.org>

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

  reply	other threads:[~2021-10-22  8:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  8:22 [PATCH 0/3] lei: some cleanup stuff Eric Wong
2021-10-22  8:22 ` Eric Wong [this message]
2021-10-22  8:22 ` [PATCH 2/3] lei export-kw: completion returns all Maildir+IMAP Eric Wong
2021-10-22  8:22 ` [PATCH 3/3] lei forget-search: support --prune=<local|remote> Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211022082247.29763-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).