]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_input: drop "From " line on single "eml" (message/rfc822)
authorEric Wong <e@80x24.org>
Mon, 22 Mar 2021 07:54:01 +0000 (07:54 +0000)
committerEric Wong <e@80x24.org>
Tue, 23 Mar 2021 00:07:14 +0000 (00:07 +0000)
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.

lib/PublicInbox/LeiInput.pm
t/lei-import.t

index c62b0893b000c05fdfd0050be489a01dc83e10bb..859fdb110636f9847136e9724161180e3e5a3765 100644 (file)
@@ -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
index e0b517f4d2f41bc36b91a72308795c8955e7471f..eef1e4e2d621a78c65fc3449b04454f3cf15e1f5 100644 (file)
@@ -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>