From 09acfa0ba87514dac4802ca88b3c95bb53d15c04 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Sep 2021 21:36:58 +0000 Subject: lei_to_mail+mbox_reader: fix handling of empty/bogus emails We may be handling invalid mboxes, so just return no objects in that case. While "lei q" on HTTP(S) externals expects a gzipped mboxrd, there's always a chance something else gzipped can be sent to us. There's also changes to lei_to_mail to better handle emails which lack a body and/or headers (e.g. t/solve/bare.patch) Link: https://public-inbox.org/meta/20210903151500.h72mzcpqixgtytjs@meerkat.local/ --- t/mbox_reader.t | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't') diff --git a/t/mbox_reader.t b/t/mbox_reader.t index da0ce7f1..e5f57d7b 100644 --- a/t/mbox_reader.t +++ b/t/mbox_reader.t @@ -71,6 +71,12 @@ my $check_fmt = sub { "Content-Length is correct $fmt $cur"); # clobber for ->as_string comparison below $eml->header_set('Content-Length'); + + # special case for t/solve/bare.patch, not sure if we + # should even handle it... + if ($cl[0] eq '0' && ${$eml->{hdr}} eq '') { + delete $eml->{bdy}; + } } else { is(scalar(@cl), 0, "Content-Length unset $fmt $cur"); } @@ -121,4 +127,21 @@ exit 1 is(scalar(grep(/Final/, @x)), 0, 'no incomplete bit'); } +{ + my $html = <hi,how are you +EOM + for my $m (qw(mboxrd mboxcl mboxcl2 mboxo)) { + my (@w, @x); + local $SIG{__WARN__} = sub { push @w, @_ }; + open my $fh, '<', \$html or xbail 'PerlIO::scalar'; + PublicInbox::MboxReader->$m($fh, sub { + push @x, $_[0]->as_string + }); + is_deeply(\@x, [], "messages in invalid $m"); + is_deeply([grep(!/^W: leftover/, @w)], [], + "no extra warnings besides leftover ($m)"); + } +} + done_testing; -- cgit v1.2.3-24-ge0c7