1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # front-end for the "lei ls-mail-sync" sub-command
5 package PublicInbox::LeiLsMailSync;
8 use PublicInbox::LeiMailSync;
10 sub lei_ls_mail_sync {
11 my ($lei, $filter) = @_;
12 my $sto = $lei->_lei_store or return;
13 my $lms = $sto->search->lms or return;
14 my $opt = $lei->{opt};
15 my $re = $opt->{globoff} ? undef : $lei->glob2re($filter // '*');
16 $re //= qr/\Q$filter\E/;
17 my @f = $lms->folders;
18 @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
19 if ($opt->{'local'} && !$opt->{remote}) {
20 @f = grep(!m!\A[a-z\+]+://!i, @f);
21 } elsif ($opt->{remote} && !$opt->{'local'}) {
22 @f = grep(m!\A[a-z\+]+://!i, @f);
24 my $ORS = $opt->{z} ? "\0" : "\n";
25 $lei->out(join($ORS, @f, ''));