]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiLsMailSync.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / LeiLsMailSync.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # front-end for the "lei ls-mail-sync" sub-command
5 package PublicInbox::LeiLsMailSync;
6 use strict;
7 use v5.10.1;
8 use PublicInbox::LeiMailSync;
9
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);
23         }
24         my $ORS = $opt->{z} ? "\0" : "\n";
25         $lei->out(join($ORS, @f, ''));
26 }
27
28 1;