From 60e5bddd086a8a90d5eaff32bc5c2026fc784ca0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 22 Mar 2021 07:54:00 +0000 Subject: lei_input: common filehandle reader for eml + mbox This improve code regularity, and will let us deal with the "RFC822" messages with "From " line that mutt pipes to. --- lib/PublicInbox/LeiInput.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/PublicInbox/LeiInput.pm') diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index 776b3151..c62b0893 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -23,6 +23,23 @@ sub check_input_format ($;$) { 1; } +# import a single file handle of $name +# Subclass must define ->eml_cb and ->mbox_cb +sub input_fh { + my ($self, $ifmt, $fh, $name, @args) = @_; + if ($ifmt eq 'eml') { + my $buf = do { local $/; <$fh> } // + return $self->{lei}->child_error(1 << 8, <<""); +error reading $name: $! + + $self->eml_cb(PublicInbox::Eml->new(\$buf), @args); + } else { + # prepare_inputs already validated $ifmt + my $cb = PublicInbox::MboxReader->reads($ifmt) // + die "BUG: bad fmt=$ifmt"; + $cb->(undef, $fh, $self->can('mbox_cb'), $self, @args); + } +} sub prepare_inputs { my ($self, $lei, $inputs) = @_; -- cgit v1.2.3-24-ge0c7