MANIFEST | 1 +
lib/PublicInbox/LEI.pm | 2 ++
lib/PublicInbox/LeiExternal.pm | 2 +-
lib/PublicInbox/LeiLsSync.pm | 29 +++++++++++++++++++++++++++++
t/lei-import-imap.t | 2 ++
t/lei-import-maildir.t | 3 +++
diff --git a/MANIFEST b/MANIFEST
index ce824fcf3276cfc8792085ee6e385430a4fad94d..d4e7d66f9f1b0e63bfaf3d6925159a8732eac542 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -202,6 +202,7 @@ lib/PublicInbox/LeiInput.pm
lib/PublicInbox/LeiInspect.pm
lib/PublicInbox/LeiLsLabel.pm
lib/PublicInbox/LeiLsSearch.pm
+lib/PublicInbox/LeiLsSync.pm
lib/PublicInbox/LeiMailSync.pm
lib/PublicInbox/LeiMirror.pm
lib/PublicInbox/LeiOverview.pm
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 39278de640a0ab9004597d281ae3484caa18b140..c170572bb919d10588961adef7b64b1ce0f54e9e 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -161,6 +161,8 @@ PublicInbox::LeiQuery::curl_opt() ],
'ls-external' => [ '[FILTER]', 'list publicinbox|extindex locations',
qw(format|f=s z|0 globoff|g invert-match|v local remote), @c_opt ],
'ls-label' => [ '', 'list labels', qw(z|0 stats:s), @c_opt ],
+'ls-sync' => [ '', 'list sync folders',
+ qw(z|0 z|0 globoff|g invert-match|v local remote), @c_opt ],
'forget-external' => [ 'LOCATION...|--prune',
'exclude further results from a publicinbox|extindex',
qw(prune), @c_opt ],
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index b0ebe9479b6254294fada399d746933484a7d6e2..3858085ece8cc0c04e49164a0edcaf4b26161837 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -50,7 +50,7 @@ my %re_map = ( '*' => '[^/]*?', '?' => '[^/]',
'[' => '[', ']' => ']', ',' => ',' );
sub glob2re {
- my ($re) = @_;
+ my $re = $_[-1];
my $p = '';
my $in_bracket = 0;
my $qm = 0;
diff --git a/lib/PublicInbox/LeiLsSync.pm b/lib/PublicInbox/LeiLsSync.pm
new file mode 100644
index 0000000000000000000000000000000000000000..71f111a9e625bae7d1fb1a68c1cac968f44b8bf9
--- /dev/null
+++ b/lib/PublicInbox/LeiLsSync.pm
@@ -0,0 +1,29 @@
+# Copyright (C) 2021 all contributors
+# License: AGPL-3.0+
+
+# front-end for the "lei ls-sync" sub-command
+package PublicInbox::LeiLsSync;
+use strict;
+use v5.10.1;
+use PublicInbox::LeiMailSync;
+
+sub lei_ls_sync {
+ my ($lei, $filter) = @_;
+ my $sto = $lei->_lei_store or return;
+ my $lms = $sto->search->lms or return;
+ my $opt = $lei->{opt};
+ my $re;
+ $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
+ $re //= $lei->glob2re($filter // '*');
+ my @f = $lms->folders;
+ @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
+ if ($opt->{'local'} && !$opt->{remote}) {
+ @f = grep(!m!\A[a-z\+]+://!i, @f);
+ } elsif ($opt->{remote} && !$opt->{'local'}) {
+ @f = grep(m!\A[a-z\+]+://!i, @f);
+ }
+ my $ORS = $opt->{z} ? "\0" : "\n";
+ $lei->out(join($ORS, @f, ''));
+}
+
+1;
diff --git a/t/lei-import-imap.t b/t/lei-import-imap.t
index 4a3bd6d8541a2a923016a3edcd88aa9e024938d0..376a8b48673b9c84ed3bf10342a4c8af1cbca3f7 100644
--- a/t/lei-import-imap.t
+++ b/t/lei-import-imap.t
@@ -22,6 +22,8 @@ lei_ok('inspect', $url);
is_deeply(json_utf8->decode($lei_out), {}, 'no inspect stats, yet');
lei_ok('import', $url);
+ lei_ok 'ls-sync';
+ like($lei_out, qr!\A\Q$url\E;UIDVALIDITY=\d+\n\z!, 'ls-sync');
lei_ok('inspect', $url);
my $inspect = json_utf8->decode($lei_out);
diff --git a/t/lei-import-maildir.t b/t/lei-import-maildir.t
index 3e3d9188a2c5c4151fc0cebdbd9fd173fd354676..808e1a73b79bbffe410c7be5c957d56e1caaaf8c 100644
--- a/t/lei-import-maildir.t
+++ b/t/lei-import-maildir.t
@@ -40,6 +40,9 @@ is(ref(delete $inspect->{"lei/store"}), 'ARRAY', 'lei/store IDs');
is_deeply($inspect, { sync => { "maildir:$md" => [ 'x:2,S' ] } },
'maildir sync info as expected');
+ lei_ok qw(ls-sync);
+ is($lei_out, "maildir:$md\n", 'ls-sync as expected');
+
lei_ok(qw(import), $md, \'import Maildir again');
$imp_err = $lei_err;
lei_ok(qw(q -d none s:boolean), \'lei q w/o dedupe');