X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmime.t;h=471f0efa99533fa3a58697e482f5eb0fdc739bc3;hb=1ed1a566c7d300ab8afb604b2e7c939299318005;hp=cd3303d1457d8a8a3d12305d10c582572f4f27af;hpb=3fc59df0d633a17e0c5e43d633d12e8772c06ec3;p=public-inbox.git
diff --git a/t/mime.t b/t/mime.t
index cd3303d1..471f0efa 100644
--- a/t/mime.t
+++ b/t/mime.t
@@ -1,14 +1,23 @@
-# Copyright (C) 2017 all contributors
+#!perl -w
+# Copyright (C) 2017-2021 all contributors
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
# Artistic or GPL-1+
use strict;
-use warnings;
use Test::More;
-use_ok 'PublicInbox::MIME';
+use PublicInbox::TestCommon;
+use PublicInbox::MsgIter;
+my @classes = qw(PublicInbox::Eml);
+SKIP: {
+ require_mods('Email::MIME', 1);
+ push @classes, 'PublicInbox::MIME';
+};
+use_ok $_ for @classes;
+local $SIG{__WARN__} = sub {}; # needed for old Email::Simple (used by E::M)
-my $msg = PublicInbox::MIME->new(
-'From: Richard Hansen
+for my $cls (@classes) {
+ my $msg = $cls->new(<<'EOF');
+From: Richard Hansen
To: git@vger.kernel.org
Cc: Richard Hansen
Subject: [PATCH 0/2] minor diff orderfile documentation improvements
@@ -38,10 +47,11 @@ Content-Description: (truncated) S/MIME Cryptographic Signature
dkTlB69771K2eXK4LcHSH/2LqX+VYa3K44vrx1ruzjXdNWzIpKBy0weFNiwnJCGofvCysM2RCSI1
--94eb2c0bc864b76ba30545b2bca9--
-');
+EOF
-my @parts = $msg->parts;
-my $exp = 'Richard Hansen (2):
+ my @parts = $msg->subparts;
+ my $exp = <body, $exp, 'body matches expected');
+
+ my $raw = <<'EOF';
+Date: Wed, 18 Jan 2017 13:28:32 -0500
+From: Santiago Torres
+To: Junio C Hamano
+Cc: git@vger.kernel.org, peff@peff.net, sunshine@sunshineco.com,
+ walters@verbum.org, Lukas Puehringer
+Subject: Re: [PATCH v6 4/6] builtin/tag: add --format argument for tag -v
+Message-ID: <20170118182831.pkhqu2np3bh2puei@LykOS.localdomain>
+References: <20170117233723.23897-1-santiago@nyu.edu>
+ <20170117233723.23897-5-santiago@nyu.edu>
+
+
+MIME-Version: 1.0
+Content-Type: multipart/signed; micalg=pgp-sha256;
+ protocol="application/pgp-signature"; boundary="r24xguofrazenjwe"
+Content-Disposition: inline
+In-Reply-To:
+
+
+--r24xguofrazenjwe
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+Content-Transfer-Encoding: quoted-printable
+
+your tree directly?=20
+
+--r24xguofrazenjwe
+Content-Type: application/pgp-signature; name="signature.asc"
+
+-----BEGIN PGP SIGNATURE-----
+
+=7wIb
+-----END PGP SIGNATURE-----
+
+--r24xguofrazenjwe--
+
+EOF
+
+ $msg = $cls->new($raw);
+ my $nr = 0;
+ msg_iter($msg, sub {
+ my ($part, $level, @ex) = @{$_[0]};
+ is($level, 1, 'at expected level');
+ if (join('fail if $#ex > 0', @ex) eq '1') {
+ is($part->body_str, "your tree directly? \r\n",
+ 'body OK');
+ } elsif (join('fail if $#ex > 0', @ex) eq '2') {
+ is($part->body, "-----BEGIN PGP SIGNATURE-----\n\n" .
+ "=7wIb\n" .
+ "-----END PGP SIGNATURE-----\n",
+ 'sig "matches"');
+ } else {
+ fail "unexpected part\n";
+ }
+ $nr++;
+ });
-ok($msg->isa('Email::MIME'), 'compatible with Email::MIME');
-is($parts[0]->body, $exp, 'body matches expected');
+ is($nr, 2, 'got 2 parts');
+ is($msg->as_string, $raw,
+ 'stringified sufficiently close to original');
+}
done_testing();