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