]> Sergey Matveev's repositories - public-inbox.git/blob - t/mime.t
No ext_urls
[public-inbox.git] / t / mime.t
1 #!perl -w
2 # Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
3 # This library is free software; you can redistribute it and/or modify
4 # it under the same terms as Perl itself.
5 # Artistic or GPL-1+ <https://www.gnu.org/licenses/gpl-1.0.txt>
6 use strict;
7 use Test::More;
8 use PublicInbox::TestCommon;
9 use PublicInbox::MsgIter;
10 my @classes = qw(PublicInbox::Eml);
11 SKIP: {
12         require_mods('Email::MIME', 1);
13         push @classes, 'PublicInbox::MIME';
14 };
15 use_ok $_ for @classes;
16 local $SIG{__WARN__} = sub {}; # needed for old Email::Simple (used by E::M)
17
18 for my $cls (@classes) {
19         my $msg = $cls->new(<<'EOF');
20 From:   Richard Hansen <hansenr@google.com>
21 To:     git@vger.kernel.org
22 Cc:     Richard Hansen <hansenr@google.com>
23 Subject: [PATCH 0/2] minor diff orderfile documentation improvements
24 Date:   Mon,  9 Jan 2017 19:40:29 -0500
25 Message-Id: <20170110004031.57985-1-hansenr@google.com>
26 X-Mailer: git-send-email 2.11.0.390.gc69c2f50cf-goog
27 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256;
28         boundary="94eb2c0bc864b76ba30545b2bca9"
29
30 --94eb2c0bc864b76ba30545b2bca9
31
32 Richard Hansen (2):
33   diff: document behavior of relative diff.orderFile
34   diff: document the pattern format for diff.orderFile
35
36  Documentation/diff-config.txt  | 5 ++++-
37  Documentation/diff-options.txt | 3 ++-
38  2 files changed, 6 insertions(+), 2 deletions(-)
39
40
41 --94eb2c0bc864b76ba30545b2bca9
42 Content-Type: application/pkcs7-signature; name="smime.p7s"
43 Content-Transfer-Encoding: base64
44 Content-Disposition: attachment; filename="smime.p7s"
45 Content-Description: (truncated) S/MIME Cryptographic Signature
46
47 dkTlB69771K2eXK4LcHSH/2LqX+VYa3K44vrx1ruzjXdNWzIpKBy0weFNiwnJCGofvCysM2RCSI1
48 --94eb2c0bc864b76ba30545b2bca9--
49
50 EOF
51
52         my @parts = $msg->subparts;
53         my $exp = <<EOF;
54 Richard Hansen (2):
55   diff: document behavior of relative diff.orderFile
56   diff: document the pattern format for diff.orderFile
57
58  Documentation/diff-config.txt  | 5 ++++-
59  Documentation/diff-options.txt | 3 ++-
60  2 files changed, 6 insertions(+), 2 deletions(-)
61
62 EOF
63
64         is($parts[0]->body, $exp, 'body matches expected');
65
66         my $raw = <<'EOF';
67 Date:   Wed, 18 Jan 2017 13:28:32 -0500
68 From:   Santiago Torres <santiago@nyu.edu>
69 To:     Junio C Hamano <gitster@pobox.com>
70 Cc:     git@vger.kernel.org, peff@peff.net, sunshine@sunshineco.com,
71         walters@verbum.org, Lukas Puehringer <luk.puehringer@gmail.com>
72 Subject: Re: [PATCH v6 4/6] builtin/tag: add --format argument for tag -v
73 Message-ID: <20170118182831.pkhqu2np3bh2puei@LykOS.localdomain>
74 References: <20170117233723.23897-1-santiago@nyu.edu>
75  <20170117233723.23897-5-santiago@nyu.edu>
76  <xmqqmvepb4oj.fsf@gitster.mtv.corp.google.com>
77  <xmqqh94wb4y0.fsf@gitster.mtv.corp.google.com>
78 MIME-Version: 1.0
79 Content-Type: multipart/signed; micalg=pgp-sha256;
80         protocol="application/pgp-signature"; boundary="r24xguofrazenjwe"
81 Content-Disposition: inline
82 In-Reply-To: <xmqqh94wb4y0.fsf@gitster.mtv.corp.google.com>
83
84
85 --r24xguofrazenjwe
86 Content-Type: text/plain; charset=us-ascii
87 Content-Disposition: inline
88 Content-Transfer-Encoding: quoted-printable
89
90 your tree directly?=20
91
92 --r24xguofrazenjwe
93 Content-Type: application/pgp-signature; name="signature.asc"
94
95 -----BEGIN PGP SIGNATURE-----
96
97 =7wIb
98 -----END PGP SIGNATURE-----
99
100 --r24xguofrazenjwe--
101
102 EOF
103
104         $msg = $cls->new($raw);
105         my $nr = 0;
106         msg_iter($msg, sub {
107                 my ($part, $level, @ex) = @{$_[0]};
108                 is($level, 1, 'at expected level');
109                 if (join('fail if $#ex > 0', @ex) eq '1') {
110                         is($part->body_str, "your tree directly? \r\n",
111                         'body OK');
112                 } elsif (join('fail if $#ex > 0', @ex) eq '2') {
113                         is($part->body, "-----BEGIN PGP SIGNATURE-----\n\n" .
114                                         "=7wIb\n" .
115                                         "-----END PGP SIGNATURE-----\n",
116                                 'sig "matches"');
117                 } else {
118                         fail "unexpected part\n";
119                 }
120                 $nr++;
121         });
122
123         is($nr, 2, 'got 2 parts');
124         is($msg->as_string, $raw,
125                 'stringified sufficiently close to original');
126 }
127
128 done_testing();