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-sync" sub-command
5 package PublicInbox::LeiLsSync;
8 use PublicInbox::LeiMailSync;
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};
16 $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
17 $re //= $lei->glob2re($filter // '*');
18 my @f = $lms->folders;
19 @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
20 if ($opt->{'local'} && !$opt->{remote}) {
21 @f = grep(!m!\A[a-z\+]+://!i, @f);
22 } elsif ($opt->{remote} && !$opt->{'local'}) {
23 @f = grep(m!\A[a-z\+]+://!i, @f);
25 my $ORS = $opt->{z} ? "\0" : "\n";
26 $lei->out(join($ORS, @f, ''));