lib/PublicInbox/LeiInput.pm | 27 ++++++++++++++++++++++++++- t/lei-index.t | 9 +++++++++ diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index 92d67715194b4f10bdc7750793b3e656a2fdf773..38d3d36df27248b94bd05ebe307498dc73f01ae9 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 @@ if ($input =~ s!\A([a-z0-9]+):!!i) { $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 @@ } elsif ($input =~ /\.(?:eml|patch)\z/i && -f $input) { 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(<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 9a45d8856da497673449cf719a6f09f6f16a0dfb..c142e79c3617b140e7905aa75b8513a2630de480 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 { @@ -30,6 +31,9 @@ }; # mbsync and offlineimap both put ":2," in "new/" files: 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 { @@ -67,6 +71,11 @@ lei_ok(qw(q z:0.. -o), "$tmpdir/all-results") for (1..2); 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");