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-ASN: 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 5065F1FA01 for ; Tue, 26 Oct 2021 10:35:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/9] eml: keep body if no headers are found Date: Tue, 26 Oct 2021 10:35:51 +0000 Message-Id: <20211026103557.2738-4-e@80x24.org> In-Reply-To: <20211026103557.2738-1-e@80x24.org> References: <20211026103557.2738-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This easily allows us to treat "git diff" output as header-less "messages" for commands such as "lei p2q". --- lib/PublicInbox/Eml.pm | 7 ++++--- t/eml.t | 11 +++++++++++ t/mbox_reader.t | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 3c681ba5bc2e..485f637a3e7b 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -122,9 +122,10 @@ sub new { my $hdr = substr($$ref, 0, $header_size_limit + 1); hdr_truncate($hdr) if length($hdr) > $header_size_limit; bless { hdr => \$hdr, crlf => $1 }, __PACKAGE__; - } else { # nothing useful - my $hdr = $$ref = ''; - bless { hdr => \$hdr, crlf => "\n" }, __PACKAGE__; + } else { # just a body w/o header? + my $hdr = ''; + my $eol = ($$ref =~ /(\r?\n)/) ? $1 : "\n"; + bless { hdr => \$hdr, crlf => $eol, bdy => $ref }, __PACKAGE__; } } diff --git a/t/eml.t b/t/eml.t index 0cf48f225a45..2d8993a51075 100644 --- a/t/eml.t +++ b/t/eml.t @@ -216,6 +216,17 @@ if ('one newline before headers') { is($eml->body, ""); } +if ('body only') { + my $str = <new($str); + is($eml->body, $str, 'body-only accepted'); +} + for my $cls (@classes) { # XXX: matching E::M, but not sure about this my $s = <$m($fh, sub { push @x, $_[0]->as_string }); - is_deeply(\@x, [], "messages in invalid $m"); + if ($m =~ /\Amboxcl/) { + is_deeply(\@x, [], "messages in invalid $m"); + } else { + is_deeply(\@x, [ "\n$html" ], "body-only $m"); + } is_deeply([grep(!/^W: leftover/, @w)], [], "no extra warnings besides leftover ($m)"); }