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 E668B1F9FE for ; Wed, 9 Jun 2021 07:47:51 +0000 (UTC) From: Eric Wong 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 Message-Id: <20210609074751.29217-5-e@80x24.org> In-Reply-To: <20210609074751.29217-1-e@80x24.org> References: <20210609074751.29217-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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= - 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(<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(<{all})) { # --all= + $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(< $_ } split(/,/, $all); + my @ok = grep(defined, delete(@x{qw(local remote), ''})); + my @no = keys %x; + if (@no) { + @no = (join(',', @no)); + return $lei->fail(<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(<