X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiLsMailSource.pm;h=5eb7032d78b7252e47dd861c76f1e48ad14b7dad;hb=cb04d2ddfd53c36eaf1a49cadb8158ae76622683;hp=f012e10e89c2d10a71da50414be285ebe4a65d0f;hpb=ddfa726e55411277c5f8fda6a5f2c82d062b3fe2;p=public-inbox.git diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index f012e10e..5eb7032d 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -12,15 +12,9 @@ use parent qw(PublicInbox::IPC PublicInbox::LeiInput); sub input_path_url { # overrides LeiInput version my ($self, $url) = @_; # TODO: support ndjson and other JSONs we support elsewhere - my $json; my $lei = $self->{lei}; - my $ORS = "\n"; - if ($self->{lei}->{opt}->{l}) { - $json = ref(PublicInbox::Config->json)->new->utf8->canonical; - $json->ascii(1) if $lei->{opt}->{ascii}; - } elsif ($self->{lei}->{opt}->{z}) { - $ORS = "\0"; - } + my $json = $lei->{json}; + my $ORS = $self->{lei}->{opt}->{z} ? "\0" : "\n"; my @f; if ($url =~ m!\Aimaps?://!i) { my $uri = PublicInbox::URIimap->new($url); @@ -59,10 +53,10 @@ sub input_path_url { # overrides LeiInput version # $desc =~ s/\r\z//; - my ($hwm, $lwm, $status) = @{$all->{$ng}}; + my ($high, $low, $status) = @{$all->{$ng}}; push @x, { name => $ng, url => "$sec/$ng", - lwm => $lwm + 0, - hwm => $hwm + 0, status => $status, + low => $low + 0, + high => $high + 0, status => $status, description => $desc }; } @f = map { "$sec/$_" } keys %$all; @@ -93,11 +87,17 @@ sub lei_ls_mail_source { my $self = bless { pfx => $pfx, -ls_ok => 1 }, __PACKAGE__; $self->{cfg} = $lei->_lei_cfg; # may be undef $self->prepare_inputs($lei, [ $url ]) or return; - $lei->start_pager if -t $lei->{1}; + my $isatty = -t $lei->{1}; + if ($lei->{opt}->{l}) { + my $json = ref(PublicInbox::Config->json)->new->utf8->canonical; + $lei->{json} = $json; + $json->ascii(1) if $lei->{opt}->{ascii}; + $json->pretty(1)->indent(2) if $isatty || $lei->{opt}->{pretty}; + } + $lei->start_pager if $isatty; my $ops = {}; - $lei->{auth}->op_merge($ops, $self); - my $j = $self->{-wq_nr_workers} = 1; # locked - (my $op_c, $ops) = $lei->workers_start($self, $j, $ops); + $lei->{auth}->op_merge($ops, $self, $lei); + (my $op_c, $ops) = $lei->workers_start($self, 1, $ops); $lei->{wq1} = $self; $lei->{-err_type} = 'non-fatal'; net_merge_all_done($self) unless $lei->{auth}; @@ -107,12 +107,13 @@ sub lei_ls_mail_source { sub _complete_ls_mail_source { my ($lei, @argv) = @_; my $match_cb = $lei->complete_url_prepare(\@argv); - my @m = map { $match_cb->($_) } $lei->url_folder_cache->keys; - my %f = map { $_ => 1 } @m; + my @k = $lei->url_folder_cache->keys($argv[-1] // undef, 1); + my @m = map { $match_cb->($_) } @k; + my %f = map { $_ => 1 } (@m ? @m : @k); if (my $lms = $lei->lms) { - @m = map { $match_cb->($_) } grep( - m!\A(?:imaps?|nntps?|s?news)://!, $lms->folders); - @f{@m} = @m; + @k = $lms->folders($argv[-1] // undef, 1); + @m = map { $match_cb->($_) } grep(m!\A[a-z]+://!, @k); + if (@m) { @f{@m} = @m } else { @f{@k} = @k } } keys %f; }