about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiInput.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-22 07:54:00 +0000
committerEric Wong <e@80x24.org>2021-03-23 00:07:13 +0000
commit60e5bddd086a8a90d5eaff32bc5c2026fc784ca0 (patch)
tree436ddfcf7853ad9bd1c8adf5c6fe5f2c4f1454fa /lib/PublicInbox/LeiInput.pm
parentd4b8980b9d2305c3004ff076a83006cc20502e56 (diff)
downloadpublic-inbox-60e5bddd086a8a90d5eaff32bc5c2026fc784ca0.tar.gz
This improve code regularity, and will let us deal with
the "RFC822" messages with "From " line that mutt pipes
to.
Diffstat (limited to 'lib/PublicInbox/LeiInput.pm')
-rw-r--r--lib/PublicInbox/LeiInput.pm17
1 files changed, 17 insertions, 0 deletions
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) = @_;