]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiLsMailSync.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / LeiLsMailSync.pm
1 # Copyright (C) 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 $lms = $lei->lms or return;
13         my $opt = $lei->{opt};
14         my $re = $opt->{globoff} ? undef : $lei->glob2re($filter // '*');
15         $re .= '/?\\z' if defined $re;
16         $re //= index($filter, '/') < 0 ?
17                         qr!/\Q$filter\E/?\z! : # exact basename match
18                         qr/\Q$filter\E/; # grep -F semantics
19         my @f = $lms->folders;
20         @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
21         if ($opt->{'local'} && !$opt->{remote}) {
22                 @f = grep(!m!\A[a-z\+]+://!i, @f);
23         } elsif ($opt->{remote} && !$opt->{'local'}) {
24                 @f = grep(m!\A[a-z\+]+://!i, @f);
25         }
26         my $ORS = $opt->{z} ? "\0" : "\n";
27         $lei->out(join($ORS, @f, ''));
28 }
29
30 1;