diff options
author | Eric Wong <e@80x24.org> | 2021-06-13 18:12:05 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-06-14 20:00:47 +0000 |
commit | 499aea505f58be23a125f4fe2e3af654d42eea9f (patch) | |
tree | 3845ef8f8e8535e68fd1beea196940871f780ffc /lib | |
parent | d1dbf32d5b747deb4610f98b0befdb8b6a32243a (diff) | |
download | public-inbox-499aea505f58be23a125f4fe2e3af654d42eea9f.tar.gz |
This will eventually be useful for supporting inotify watches on Maildir. It will also allow users to script their own FS watchers more easily.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/LeiInput.pm | 27 |
1 files changed, 26 insertions, 1 deletions
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 _) { |