about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiConvert.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/LeiConvert.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/LeiConvert.pm')
-rw-r--r--lib/PublicInbox/LeiConvert.pm30
1 files changed, 10 insertions, 20 deletions
diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm
index 8685c194..51a233bd 100644
--- a/lib/PublicInbox/LeiConvert.pm
+++ b/lib/PublicInbox/LeiConvert.pm
@@ -10,13 +10,18 @@ use PublicInbox::Eml;
 use PublicInbox::LeiStore;
 use PublicInbox::LeiOverview;
 
-sub mbox_cb {
+sub mbox_cb { # MboxReader callback used by PublicInbox::LeiInput::input_fh
         my ($eml, $self) = @_;
         my $kw = PublicInbox::MboxReader::mbox_keywords($eml);
         $eml->header_set($_) for qw(Status X-Status);
         $self->{wcb}->(undef, { kw => $kw }, $eml);
 }
 
+sub eml_cb { # used by PublicInbox::LeiInput::input_fh
+        my ($self, $eml) = @_;
+        $self->{wcb}->(undef, { kw => [] }, $eml);
+}
+
 sub net_cb { # callback for ->imap_each, ->nntp_each
         my (undef, undef, $kw, $eml, $self) = @_; # @_[0,1]: url + uid ignored
         $self->{wcb}->(undef, { kw => $kw }, $eml);
@@ -27,30 +32,15 @@ sub mdir_cb {
         $self->{wcb}->(undef, { kw => $kw }, $eml);
 }
 
-sub convert_fh ($$$$) {
-        my ($self, $ifmt, $fh, $name) = @_;
-        if ($ifmt eq 'eml') {
-                my $buf = do { local $/; <$fh> } //
-                        return $self->{lei}->child_error(1 << 8, <<"");
-error reading $name: $!
-
-                my $eml = PublicInbox::Eml->new(\$buf);
-                $self->{wcb}->(undef, { kw => [] }, $eml);
-        } else {
-                PublicInbox::MboxReader->$ifmt($fh, \&mbox_cb, $self);
-        }
-}
-
 sub do_convert { # via wq_do
         my ($self) = @_;
         my $lei = $self->{lei};
-        my $in_fmt = $lei->{opt}->{'in-format'};
-        my $mics;
+        my $ifmt = $lei->{opt}->{'in-format'};
         if (my $stdin = delete $self->{0}) {
-                convert_fh($self, $in_fmt, $stdin, '<stdin>');
+                $self->input_fh($ifmt, $stdin, '<stdin>');
         }
         for my $input (@{$self->{inputs}}) {
-                my $ifmt = lc($in_fmt // '');
+                my $ifmt = lc($ifmt // '');
                 if ($input =~ m!\Aimaps?://!) {
                         $lei->{net}->imap_each($input, \&net_cb, $self);
                         next;
@@ -65,7 +55,7 @@ sub do_convert { # via wq_do
                                         ($ifmt eq 'eml' ? ['none'] :
                                         PublicInbox::MboxLock->defaults);
                         my $mbl = PublicInbox::MboxLock->acq($input, 0, $m);
-                        convert_fh($self, $ifmt, $mbl->{fh}, $input);
+                        $self->input_fh($ifmt, $mbl->{fh}, $input);
                 } elsif (-d _) {
                         PublicInbox::MdirReader::maildir_each_eml($input,
                                                         \&mdir_cb, $self);