]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/eml.t
public-inbox 1.6.1 - minor bugfix release
[public-inbox.git] / t / eml.t
diff --git a/t/eml.t b/t/eml.t
index b7f58ac706965b289b03e1d627a4acb7dc6f3113..4d1c1216f7c9a611ab0b4b3ebaa0b55aacf90f2f 100644 (file)
--- a/t/eml.t
+++ b/t/eml.t
@@ -8,10 +8,19 @@ 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;
 
+sub mime_load ($) {
+       my ($path) = @_;
+       open(my $fh, '<', $path) or die "open $path: $!";
+       PublicInbox::MIME->new(\(do { local $/; <$fh> }));
+}
+
 {
        my $eml = PublicInbox::Eml->new(\(my $str = "a: b\n\nhi\n"));
        is($str, "hi\n", '->new modified body like Email::Simple');
@@ -74,7 +83,7 @@ for my $cls (@classes) {
        $eml->header_str_set('Subject', "\x{100}");
        like($eml->header_raw('Subject'), qr/utf-8\?B\?/i,
                'MIME-B encoded UTF-8 Subject');
-       is_deeply([$eml->header_str('Subject')], [ "\x{100}" ],
+       is_deeply([$eml->header('Subject')], [ "\x{100}" ],
                'got wide character back');
 }
 
@@ -163,7 +172,7 @@ EOF
        is(scalar(@tmp), 1, 'got one part even w/o boundary');
        is($tmp[0]->[0]->[0]->body, "hello world\n", 'body preserved');
        is($tmp[0]->[0]->[1], 0, '$depth is zero');
-       is($tmp[0]->[0]->[2], 0, '@idx is zero');
+       is($tmp[0]->[0]->[2], 1, '@idx is one');
 }
 
 # I guess the following only worked in PI::M because of a happy accident
@@ -254,6 +263,9 @@ EOF
 }
 
 for my $cls (@classes) {
+SKIP: {
+       skip 'newer Email::MIME behavior inconsistent', 1 if
+               $cls eq 'PublicInbox::MIME';
        my $s = <<EOF; # buggy git-send-email versions, again?
 Content-Type: text/plain; =?ISO-8859-1?Q?=20charset=3D=1BOF?=
 Content-Transfer-Encoding: 8bit
@@ -263,7 +275,8 @@ Object-Id: ab0440d8cd6d843bee9a27709a459ce3b2bdb94d (lore/kvm)
 EOF
        my $eml = $cls->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') {
@@ -377,8 +390,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) {
@@ -389,7 +406,8 @@ Content-Disposition: attachment; filename="=?utf-8?q?vtpm-makefile.patch?="
 EOF
        is($cls->new($s)->filename, 'vtpm-makefile.patch', 'filename decoded');
        $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');
@@ -407,10 +425,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;