From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 86DAF1FC0B for ; Mon, 22 Mar 2021 07:54:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 7/8] lei_input: drop "From " line on single "eml" (message/rfc822) Date: Mon, 22 Mar 2021 07:54:01 +0000 Message-Id: <20210322075402.27834-8-e@80x24.org> In-Reply-To: <20210322075402.27834-1-e@80x24.org> References: <20210322075402.27834-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 4 ++++ t/lei-import.t | 10 ++++++++++ 2 files changed, 14 insertions(+) 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: