unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/5] lei_mail_sync: hoist out --all handling from export-kw
Date: Wed,  9 Jun 2021 07:47:50 +0000	[thread overview]
Message-ID: <20210609074751.29217-5-e@80x24.org> (raw)
In-Reply-To: <20210609074751.29217-1-e@80x24.org>

We'll be reusing it in other commands, too.
---
 lib/PublicInbox/LeiExportKw.pm | 32 ++----------------------------
 lib/PublicInbox/LeiMailSync.pm | 36 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm
index f8579221..671a84df 100644
--- a/lib/PublicInbox/LeiExportKw.pm
+++ b/lib/PublicInbox/LeiExportKw.pm
@@ -94,36 +94,8 @@ EOM
 lei mail_sync uninitialized, see lei-import(1)
 EOM
 	my $opt = $lei->{opt};
-	my $all = $opt->{all};
-	if (defined $all) { # --all=<local|remote>
-		my %x = map { $_ => $_ } split(/,/, $all);
-		my @ok = grep(defined, delete(@x{qw(local remote), ''}));
-		my @no = keys %x;
-		if (@no) {
-			@no = (join(',', @no));
-			return $lei->fail(<<EOM);
---all=@no not accepted (must be `local' and/or `remote')
-EOM
-		}
-		my (%seen, @inc);
-		my @all = $lms->folders;
-		for my $ok (@ok) {
-			if ($ok eq 'local') {
-				@inc = grep(!m!\A[a-z0-9\+]+://!i, @all);
-			} elsif ($ok eq 'remote') {
-				@inc = grep(m!\A[a-z0-9\+]+://!i, @all);
-			} elsif ($ok ne '') {
-				return $lei->fail("--all=$all not understood");
-			} else {
-				@inc = @all;
-			}
-			for (@inc) {
-				push(@folders, $_) unless $seen{$_}++;
-			}
-		}
-		return $lei->fail(<<EOM) if !@folders;
-no --mail-sync folders known to lei
-EOM
+	if (defined(my $all = $opt->{all})) { # --all=<local|remote>
+		$lms->group2folders($lei, $all, \@folders) or return;
 	} else {
 		my $err = $lms->arg2folder($lei, \@folders);
 		$lei->qerr(@{$err->{qerr}}) if $err->{qerr};
diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index ec05404a..af47439a 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -315,6 +315,42 @@ sub match_imap_url {
 			"E: `$url' is ambiguous:\n\t".join("\n\t", @match)."\n";
 }
 
+# returns undef on failure, number on success
+sub group2folders {
+	my ($self, $lei, $all, $folders) = @_;
+	return $lei->fail(<<EOM) if @$folders;
+--all= not compatible with @$folders on command-line
+EOM
+	my %x = map { $_ => $_ } split(/,/, $all);
+	my @ok = grep(defined, delete(@x{qw(local remote), ''}));
+	my @no = keys %x;
+	if (@no) {
+		@no = (join(',', @no));
+		return $lei->fail(<<EOM);
+--all=@no not accepted (must be `local' and/or `remote')
+EOM
+	}
+	my (%seen, @inc);
+	my @all = $self->folders;
+	for my $ok (@ok) {
+		if ($ok eq 'local') {
+			@inc = grep(!m!\A[a-z0-9\+]+://!i, @all);
+		} elsif ($ok eq 'remote') {
+			@inc = grep(m!\A[a-z0-9\+]+://!i, @all);
+		} elsif ($ok ne '') {
+			return $lei->fail("--all=$all not understood");
+		} else {
+			@inc = @all;
+		}
+		for (@inc) {
+			push(@$folders, $_) unless $seen{$_}++;
+		}
+	}
+	scalar(@$folders) || $lei->fail(<<EOM);
+no --mail-sync folders known to lei
+EOM
+}
+
 # map CLI args to folder table entries, returns undef on failure
 sub arg2folder {
 	my ($self, $lei, $folders) = @_;

  parent reply	other threads:[~2021-06-09  7:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09  7:47 [PATCH 0/5] lei Maildir stuff Eric Wong
2021-06-09  7:47 ` [PATCH 1/5] inbox_writable: fix import_maildir Eric Wong
2021-06-09  7:47 ` [PATCH 2/5] mdir_reader: maildir_each_file: pass flags, skip Trash Eric Wong
2021-06-09  7:47 ` [PATCH 3/5] lei tag: parallelize Maildir access Eric Wong
2021-06-09  7:47 ` Eric Wong [this message]
2021-06-09  7:47 ` [PATCH 5/5] lei prune-mail-sync: new command to prune invalid sync data 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=20210609074751.29217-5-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.
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).