diff options
author | Eric Wong <e@80x24.org> | 2021-10-26 10:35:51 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-10-26 17:43:52 +0000 |
commit | 584721cf9c98beabce9b779faafa1eabb5c24de6 (patch) | |
tree | 1d5c0978fc275bcc2f1b7712904e28ff844fa3e0 | |
parent | 273090c96e3b5c214605decf5a755546116cc9bd (diff) | |
download | public-inbox-584721cf9c98beabce9b779faafa1eabb5c24de6.tar.gz |
This easily allows us to treat "git diff" output as header-less "messages" for commands such as "lei p2q".
-rw-r--r-- | lib/PublicInbox/Eml.pm | 7 | ||||
-rw-r--r-- | t/eml.t | 11 | ||||
-rw-r--r-- | 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 3c681ba5..485f637a 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__; } } @@ -216,6 +216,17 @@ if ('one newline before headers') { is($eml->body, ""); } +if ('body only') { + my $str = <<EOM; +--- a/lib/PublicInbox/Eml.pm ++++ b/lib/PublicInbox/Eml.pm +@@ -122,9 +122,10 @@ sub new { +\x20 +EOM + my $eml = PublicInbox::Eml->new($str); + is($eml->body, $str, 'body-only accepted'); +} + for my $cls (@classes) { # XXX: matching E::M, but not sure about this my $s = <<EOF; Content-Type: multipart/mixed; boundary="b" diff --git a/t/mbox_reader.t b/t/mbox_reader.t index e5f57d7b..87e8f397 100644 --- a/t/mbox_reader.t +++ b/t/mbox_reader.t @@ -138,7 +138,11 @@ EOM PublicInbox::MboxReader->$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)"); } |