user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] lei: support keywords off a single Maildir file
@ 2021-06-13 18:12 Eric Wong
  2021-06-13 18:12 ` [PATCH 1/2] lei_input: allow keywords when importing 1 file from Maildir Eric Wong
  2021-06-13 18:12 ` [PATCH 2/2] lei index+import: reject keywords from R/O IMAP Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2021-06-13 18:12 UTC (permalink / raw)
  To: meta

I noticed the bug fixed by 2/2 while working on 1/2

Eric Wong (2):
  lei_input: allow keywords when importing 1 file from Maildir
  lei index+import: reject keywords from R/O IMAP

 lib/PublicInbox/LeiInput.pm  | 27 ++++++++++++++++++++++++++-
 lib/PublicInbox/LeiStore.pm  |  3 ++-
 lib/PublicInbox/NetReader.pm | 11 ++++++-----
 t/lei-index.t                | 22 ++++++++++++++++++++++
 4 files changed, 56 insertions(+), 7 deletions(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] lei_input: allow keywords when importing 1 file from Maildir
  2021-06-13 18:12 [PATCH 0/2] lei: support keywords off a single Maildir file Eric Wong
@ 2021-06-13 18:12 ` Eric Wong
  2021-06-13 18:12 ` [PATCH 2/2] lei index+import: reject keywords from R/O IMAP Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-06-13 18:12 UTC (permalink / raw)
  To: meta

This will eventually be useful for supporting inotify watches
on Maildir.  It will also allow users to script their own FS
watchers more easily.
---
 lib/PublicInbox/LeiInput.pm | 27 ++++++++++++++++++++++++++-
 t/lei-index.t               |  9 +++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm
index 92d67715..38d3d36d 100644
--- a/lib/PublicInbox/LeiInput.pm
+++ b/lib/PublicInbox/LeiInput.pm
@@ -7,6 +7,7 @@ use strict;
 use v5.10.1;
 use PublicInbox::DS;
 use PublicInbox::Spawn qw(which popen_rd);
+use PublicInbox::InboxWritable qw(eml_from_path);
 
 # JMAP RFC 8621 4.1.1
 # https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
@@ -127,6 +128,16 @@ sub input_path_url {
 		$ifmt = lc($1);
 	} elsif ($input =~ /\.(?:patch|eml)\z/i) {
 		$ifmt = 'eml';
+	} elsif (-f $input && $input =~ m{\A(?:.+)/(?:new|cur)/([^/]+)\z}) {
+		my $bn = $1;
+		my $fl = PublicInbox::MdirReader::maildir_basename_flags($bn);
+		return if index($fl, 'T') >= 0;
+		return $self->pmdir_cb($input, $fl) if $self->can('pmdir_cb');
+		my $eml = eml_from_path($input) or return
+			$lei->qerr("# $input not readable");
+		my $kw = PublicInbox::MdirReader::flags2kw($fl);
+		$self->can('input_maildir_cb')->($input, $kw, $eml, $self);
+		return;
 	}
 	my $devfd = $lei->path_to_fd($input) // return;
 	if ($devfd >= 0) {
@@ -266,8 +277,22 @@ sub prepare_inputs { # returns undef on error
 			lc($in_fmt//'eml') eq 'eml' or return $lei->fail(<<"");
 $input is `eml', not --in-format=$in_fmt
 
-			require PublicInbox::Eml;
 			push @{$sync->{no}}, $input if $sync;
+		} elsif (-f $input && $input =~ m{\A(.+)/(new|cur)/([^/]+)\z}) {
+			# single file in a Maildir
+			my ($mdir, $nc, $bn) = ($1, $2, $3);
+			my $other = $mdir . ($nc eq 'new' ? '/cur' : '/new');
+			return $lei->fail(<<EOM) if !-d $other;
+No `$other' directory for `$input'
+EOM
+			lc($in_fmt//'eml') eq 'eml' or return $lei->fail(<<"");
+$input is `eml', not --in-format=$in_fmt
+
+			if ($sync) {
+				$input = $lei->abs_path($mdir) . "/$nc/$bn";
+				push @{$sync->{ok}}, $input;
+			}
+			require PublicInbox::MdirReader;
 		} else {
 			my $devfd = $lei->path_to_fd($input) // return;
 			if ($devfd >= 0 || -f $input || -p _) {
diff --git a/t/lei-index.t b/t/lei-index.t
index 9a45d885..c142e79c 100644
--- a/t/lei-index.t
+++ b/t/lei-index.t
@@ -20,6 +20,7 @@ my $imap_host_port = tcp_host_port($sock);
 undef $sock;
 for ('', qw(cur new)) {
 	mkdir "$tmpdir/md/$_" or xbail "mkdir: $!";
+	mkdir "$tmpdir/md1/$_" or xbail "mkdir: $!";
 }
 symlink(File::Spec->rel2abs('t/plack-qp.eml'), "$tmpdir/md/cur/x:2,");
 my $expect = do {
@@ -32,6 +33,9 @@ my $expect = do {
 symlink(File::Spec->rel2abs('t/utf8.eml'), "$tmpdir/md/new/u:2,") or
 	xbail "symlink $!";
 
+symlink(File::Spec->rel2abs('t/mda-mime.eml'), "$tmpdir/md1/cur/x:2,S") or
+	xbail "symlink $!";
+
 test_lei({ tmpdir => $tmpdir }, sub {
 	my $store_path = "$ENV{HOME}/.local/share/lei/store/";
 
@@ -68,6 +72,11 @@ test_lei({ tmpdir => $tmpdir }, sub {
 	is_deeply([xqx($all_obj)], \@objs,
 		'no new objects after 2x q to trigger implicit import');
 
+	lei_ok 'index', "$tmpdir/md1/cur/x:2,S";
+	lei_ok qw(q m:multipart-html-sucks@11);
+	is_deeply(json_utf8->decode($lei_out)->[0]->{'kw'},
+		['seen'], 'keyword set');
+
 	lei_ok('index', "nntp://$nntp_host_port/t.v2");
 	lei_ok('index', "imap://$imap_host_port/t.v2.0");
 	is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] lei index+import: reject keywords from R/O IMAP
  2021-06-13 18:12 [PATCH 0/2] lei: support keywords off a single Maildir file Eric Wong
  2021-06-13 18:12 ` [PATCH 1/2] lei_input: allow keywords when importing 1 file from Maildir Eric Wong
@ 2021-06-13 18:12 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-06-13 18:12 UTC (permalink / raw)
  To: meta

Since users can't set IMAP flags in read-only IMAP folders,
we won't clobber local flags when importing from IMAP.  This
also enables the local_blob fallback used for lei-index to
be used for index deduplication.
---
 lib/PublicInbox/LeiStore.pm  |  3 ++-
 lib/PublicInbox/NetReader.pm | 11 ++++++-----
 t/lei-index.t                | 13 +++++++++++++
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index 5446873e..f978288a 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -151,7 +151,8 @@ sub _docids_for ($$) {
 			my $oid = $cur->{blob};
 			my $docid = $cur->{num};
 			my $bref = $im ? $im->cat_blob($oid) : undef;
-			$bref //= $eidx->git->cat_file($oid) // do {
+			$bref //= $eidx->git->cat_file($oid) //
+				_lms_rw($self)->local_blob($oid, 1) // do {
 				warn "W: $oid (#$docid) <$mid> not found\n";
 				next;
 			};
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 30784199..0c2288d8 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -420,7 +420,8 @@ sub _imap_do_msg ($$$$$) {
 	my ($self, $uri, $uid, $raw, $flags) = @_;
 	# our target audience expects LF-only, save storage
 	$$raw =~ s/\r\n/\n/sg;
-	my $kw = flags2kw($self, $uri, $uid, $flags) // return;
+	my $kw = defined($flags) ?
+		(flags2kw($self, $uri, $uid, $flags) // return) : undef;
 	my ($eml_cb, @args) = @{$self->{eml_each}};
 	$eml_cb->($uri, $uid, $kw, PublicInbox::Eml->new($raw), @args);
 }
@@ -537,8 +538,8 @@ E: $uri strangely, UIDVALIDLITY matches ($l_uidval)
 EOF
 	$mic->Uid(1); # the default, we hope
 	my $err;
-	if (!defined($single_uid) && $self->{each_old} &&
-				perm_fl_ok($perm_fl)) {
+	my $use_fl = perm_fl_ok($perm_fl);
+	if (!defined($single_uid) && $self->{each_old} && $use_fl) {
 		$err = each_old_flags($self, $mic, $uri, $l_uid);
 		return $err if $err;
 	}
@@ -593,8 +594,8 @@ EOF
 				# messages get deleted, so holes appear
 				my $per_uid = delete $r->{$uid} // next;
 				my $raw = delete($per_uid->{$key}) // next;
-				_imap_do_msg($self, $uri, $uid, \$raw,
-						$per_uid->{FLAGS});
+				my $fl = $use_fl ? $per_uid->{FLAGS} : undef;
+				_imap_do_msg($self, $uri, $uid, \$raw, $fl);
 				$last_uid = $uid;
 				last if $self->{quit};
 			}
diff --git a/t/lei-index.t b/t/lei-index.t
index c142e79c..eeda5196 100644
--- a/t/lei-index.t
+++ b/t/lei-index.t
@@ -80,6 +80,19 @@ test_lei({ tmpdir => $tmpdir }, sub {
 	lei_ok('index', "nntp://$nntp_host_port/t.v2");
 	lei_ok('index', "imap://$imap_host_port/t.v2.0");
 	is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');
+
+	lei_ok qw(q m:multipart-html-sucks@11);
+	$res_a = json_utf8->decode($lei_out)->[0];
+	is_deeply($res_a->{'kw'}, ['seen'],
+		'keywords still set after NNTP + IMAP import');
+
+	# ensure import works after lms->local_blob fallback in lei/store
+	lei_ok('import', 't/mda-mime.eml');
+	lei_ok qw(q m:multipart-html-sucks@11);
+	$res_b = json_utf8->decode($lei_out)->[0];
+	my $t = xqx(['git', "--git-dir=$store_path/ALL.git",
+			qw(cat-file -t), $res_b->{blob}]);
+	is($t, "blob\n", 'got blob');
 });
 
 done_testing;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-13 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-13 18:12 [PATCH 0/2] lei: support keywords off a single Maildir file Eric Wong
2021-06-13 18:12 ` [PATCH 1/2] lei_input: allow keywords when importing 1 file from Maildir Eric Wong
2021-06-13 18:12 ` [PATCH 2/2] lei index+import: reject keywords from R/O IMAP Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).