about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-22 07:54:01 +0000
committerEric Wong <e@80x24.org>2021-03-23 00:07:14 +0000
commitbbf3bbfe8e45fb79e2b848966aac5792268b3d8f (patch)
treebbf5fb59241358b996aa7ca970cf182c1c9fad0f
parent60e5bddd086a8a90d5eaff32bc5c2026fc784ca0 (diff)
downloadpublic-inbox-bbf3bbfe8e45fb79e2b848966aac5792268b3d8f.tar.gz
This matches the long-standing behavior of public-inbox-mda,
public-inbox-learn and our other tools.  It is useful because
mutt, "git format-patch", and likely other tools will
pipe a single message with a "From " header line, but with
no further "From " escaping or Content-Length: header.
-rw-r--r--lib/PublicInbox/LeiInput.pm4
-rw-r--r--t/lei-import.t10
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm
index c62b0893..859fdb11 100644
--- a/lib/PublicInbox/LeiInput.pm
+++ b/lib/PublicInbox/LeiInput.pm
@@ -32,6 +32,10 @@ sub input_fh {
                         return $self->{lei}->child_error(1 << 8, <<"");
 error reading $name: $!
 
+                # mutt pipes single RFC822 messages with a "From " line,
+                # but no Content-Length or "From " escaping.
+                # "git format-patch" also generates such files by default.
+                $buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
                 $self->eml_cb(PublicInbox::Eml->new(\$buf), @args);
         } else {
                 # prepare_inputs already validated $ifmt
diff --git a/t/lei-import.t b/t/lei-import.t
index e0b517f4..eef1e4e2 100644
--- a/t/lei-import.t
+++ b/t/lei-import.t
@@ -29,6 +29,16 @@ lei_ok(qw(q s:boolean -f mboxrd), \'blob accessible after import');
 lei_ok(qw(import -F eml), 't/data/message_embed.eml',
         \'import single file by path');
 
+lei_ok(qw(q m:testmessage@example.com));
+is($lei_out, "[null]\n", 'no results, yet');
+my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
+my $eml = eml_load('t/utf8.eml');
+my $in = 'From x@y Fri Oct  2 00:00:00 1993'."\n".$eml->as_string;
+lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => \$in });
+lei_ok(qw(q m:testmessage@example.com));
+is(json_utf8->decode($lei_out)->[0]->{'blob'}, $oid,
+        'got expected OID w/o From');
+
 my $str = <<'';
 From: a@b
 Message-ID: <x@y>