unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] lei lcat: support maildir: paths, too
Date: Sun, 30 May 2021 06:33:57 +0000	[thread overview]
Message-ID: <20210530063358.25095-4-e@80x24.org> (raw)
In-Reply-To: <20210530063358.25095-1-e@80x24.org>

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;

  parent reply	other threads:[~2021-05-30  6:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30  6:33 [PATCH 0/4] lei lcat usability things Eric Wong
2021-05-30  6:33 ` [PATCH 1/4] lei lcat+inspect: start wiring up completion Eric Wong
2021-05-30  6:33 ` [PATCH 2/4] lei lcat: allow IMAP folder URLs w/o UIDVALIDITY Eric Wong
2021-05-30  6:33 ` Eric Wong [this message]
2021-05-30  6:33 ` [PATCH 4/4] lei: support implicit stdin by default Eric Wong
2021-05-30 11:52 ` [PATCH 0/4] lei lcat usability things Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210530063358.25095-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).