X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Feml.t;h=2e6a441f51dc71b85bbb37fcff318f6f2bb88e47;hb=refs%2Fheads%2Fmaster;hp=8d131b1418eb7c510b55297ef2cbeed4632fd038;hpb=686951722e2709b548384b19ad300f5c2642d368;p=public-inbox.git diff --git a/t/eml.t b/t/eml.t index 8d131b14..2e6a441f 100644 --- a/t/eml.t +++ b/t/eml.t @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ use strict; use Test::More; @@ -8,6 +8,9 @@ use PublicInbox::MsgIter qw(msg_part_text); my @classes = qw(PublicInbox::Eml); SKIP: { require_mods('Email::MIME', 1); + # TODO: Email::MIME behavior is not consistent in newer versions + # we need to evaluate and possibly adjust our behavior to decide + # between DWIM-ness with historical mail... push @classes, 'PublicInbox::MIME'; }; use_ok $_ for @classes; @@ -23,6 +26,8 @@ sub mime_load ($) { is($str, "hi\n", '->new modified body like Email::Simple'); is($eml->body, "hi\n", '->body works'); is($eml->as_string, "a: b\n\nhi\n", '->as_string'); + my $empty = PublicInbox::Eml->new("\n\n"); + is($empty->as_string, "\n\n", 'empty message'); } for my $cls (@classes) { @@ -211,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 = <new(\$s); my ($str, $err) = msg_part_text($eml, $eml->content_type); - is($str, "\x{100}\n", "got wide character by assuming utf-8"); + is($str, "\x{100}\n", "got wide character by assuming utf-8 ($cls)"); +} # SKIP } if ('we differ from Email::MIME with final "\n" on missing epilogue') { @@ -383,8 +403,12 @@ SKIP: { $msg->parts_set([$old[-1]]); is(scalar $msg->subparts, 1, 'only last remains'); } - is($eml->as_string, $mime->as_string, - 'as_string matches after parts_set'); + + # some versions of Email::MIME or Email::MIME::* will drop + # unnecessary ", while PublicInbox::Eml will preserve the original + my $exp = $mime->as_string; + $exp =~ s/; boundary=b\b/; boundary="b"/; + is($eml->as_string, $exp, 'as_string matches after parts_set'); } for my $cls (@classes) { @@ -393,12 +417,14 @@ Content-Type: text/x-patch; name="=?utf-8?q?vtpm-fakefile.patch?=" Content-Disposition: attachment; filename="=?utf-8?q?vtpm-makefile.patch?=" EOF - is($cls->new($s)->filename, 'vtpm-makefile.patch', 'filename decoded'); + is($cls->new($s)->filename, 'vtpm-makefile.patch', + "filename decoded ($cls)") if $cls ne 'PublicInbox::MIME'; $s =~ s/^Content-Disposition:.*$//sm; - is($cls->new($s)->filename, 'vtpm-fakefile.patch', 'filename fallback'); + is($cls->new($s)->filename, 'vtpm-fakefile.patch', + "filename fallback ($cls)") if $cls ne 'PublicInbox::MIME'; is($cls->new($s)->content_type, 'text/x-patch; name="vtpm-fakefile.patch"', - 'matches Email::MIME output, "correct" or not'); + qq[matches Email::MIME output, "correct" or not ($cls)]); $s = <<'EOF'; Content-Type: multipart/foo; boundary=b @@ -413,10 +439,14 @@ Content-Type: text/x-patch; name="=?utf-8?q?vtpm-fakefile.patch?=" b --b-- EOF - my @tmp; - $cls->new($s)->each_part(sub { push @tmp, $_[0]->[0]->filename }); - is_deeply(['vtpm-makefile.patch', 'vtpm-fakefile.patch'], \@tmp, - 'got filename for both attachments'); + SKIP: { + skip 'newer Email::MIME is inconsistent here', 1 + if $cls eq 'PublicInbox::MIME'; + my @x; + $cls->new($s)->each_part(sub { push @x, $_[0]->[0]->filename }); + is_deeply(['vtpm-makefile.patch', 'vtpm-fakefile.patch'], \@x, + "got filename for both attachments ($cls)"); + } } done_testing;