about summary refs log tree commit homepage
path: root/t/mbox_reader.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-04 21:36:58 +0000
committerEric Wong <e@80x24.org>2021-09-04 23:33:06 +0000
commit09acfa0ba87514dac4802ca88b3c95bb53d15c04 (patch)
tree60c117b099564f06b54db089d698abbdc4aa6c41 /t/mbox_reader.t
parent42420897bd81bf5664d5a93c5069dda4cb0459f1 (diff)
downloadpublic-inbox-09acfa0ba87514dac4802ca88b3c95bb53d15c04.tar.gz
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/
Diffstat (limited to 't/mbox_reader.t')
-rw-r--r--t/mbox_reader.t23
1 files changed, 23 insertions, 0 deletions
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 = <<EOM;
+<html><head><title>hi,</title></head><body>how are you</body></html>
+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;