From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 154451F9F4 for ; Sun, 30 May 2021 06:33:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/4] lei lcat: support maildir: paths, too Date: Sun, 30 May 2021 06:33:57 +0000 Message-Id: <20210530063358.25095-4-e@80x24.org> In-Reply-To: <20210530063358.25095-1-e@80x24.org> References: <20210530063358.25095-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This could be helpful in case when a Maildir is on a slow or unmounted filesystem and lei/store is on fast storage. --- lib/PublicInbox/LeiLcat.pm | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm index 5bd20c1f..cb5eb5b4 100644 --- a/lib/PublicInbox/LeiLcat.pm +++ b/lib/PublicInbox/LeiLcat.pm @@ -11,10 +11,26 @@ use PublicInbox::LeiViewText; use URI::Escape qw(uri_unescape); use PublicInbox::MID qw($MID_EXTRACT); +sub lcat_folder ($$$) { + my ($lei, $lms, $folder) = @_; + $lms //= $lei->{lse}->lms // return; + my $folders = [ $folder]; + my $err = $lms->arg2folder($lei, $folders); + $lei->qerr(@{$err->{qerr}}) if $err && $err->{qerr}; + if ($err && $err->{fail}) { + $lei->child_error(1 << 8, "# unknown folder: $folder"); + } else { + for my $f (@$folders) { + my $fid = $lms->fid_for($f); + push @{$lei->{lcat_fid}}, $fid; + } + } +} + sub lcat_imap_uri ($$) { my ($lei, $uri) = @_; my $lms = $lei->{lse}->lms or return; - # cf. LeiToMail->wq_atexit_child + # cf. LeiXsearch->lcat_dump if (defined $uri->uid) { my $oidhex = $lms->imap_oid($lei, $uri); if (ref(my $err = $oidhex)) { # art2folder error @@ -24,17 +40,7 @@ sub lcat_imap_uri ($$) { } elsif (defined(my $fid = $lms->fid_for($$uri))) { push @{$lei->{lcat_fid}}, $fid; } else { - my $folders = [ $$uri ]; - my $err = $lms->arg2folder($lei, $folders); - $lei->qerr(@{$err->{qerr}}) if $err && $err->{qerr}; - if ($err && $err->{fail}) { - $lei->child_error(1 << 8, "# unknown folder: $uri"); - } else { - for my $f (@$folders) { - my $fid = $lms->fid_for($f); - push @{$lei->{lcat_fid}}, $fid; - } - } + lcat_folder($lei, $lms, $$uri); } } @@ -44,7 +50,10 @@ sub extract_1 ($$) { my $u = $1; require PublicInbox::URIimap; lcat_imap_uri($lei, PublicInbox::URIimap->new($u)); - '""'; # blank query, using {lcat_blob} or {lcat + '""'; # blank query, using {lcat_blob} or {lcat_fid} + } elsif ($x =~ m!\b(maildir:.+)!i) { + lcat_folder($lei, undef, $1); + '""'; # blank query, using {lcat_blob} or {lcat_fid} } elsif ($x =~ m!\b([a-z]+?://\S+)!i) { my $u = $1; $u =~ s/[\>\]\)\,\.\;]+\z//; @@ -147,7 +156,7 @@ sub _complete_lcat { my $sto = $lei->_lei_store or return; my $lms = $sto->search->lms or return; my $match_cb = $lei->complete_url_prepare(\@argv); - grep(m!\A[a-z]+://!, map { $match_cb->($_) } $lms->folders); + map { $match_cb->($_) } $lms->folders; } 1;