]> Sergey Matveev's repositories - public-inbox.git/blob - t/view.t
view: inline message reply into message view
[public-inbox.git] / t / view.t
1 # Copyright (C) 2013-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::MIME;
7 use PublicInbox::View;
8
9 sub msg_html ($) {
10         my ($mime) = @_;
11
12         PublicInbox::View::msg_html(undef, $mime);
13 }
14
15 # plain text
16 {
17         my $body = <<EOF;
18 So and so wrote:
19 > keep this inline
20
21 OK
22
23 > Long and wordy reply goes here and it is split across multiple lines.
24 > We generate links to a separate full page where quoted-text is inline.
25 > This is
26 >
27 > Currently 12 lines
28 > See MAX_INLINE_QUOTED
29 > See MAX_INLINE_QUOTED
30 > See MAX_INLINE_QUOTED
31 > See MAX_INLINE_QUOTED
32 > See MAX_INLINE_QUOTED
33 > See MAX_INLINE_QUOTED
34 > See MAX_INLINE_QUOTED
35 > See MAX_INLINE_QUOTED
36
37 hello world
38 EOF
39         my $s = Email::Simple->create(
40                 header => [
41                         From => 'a@example.com',
42                         To => 'b@example.com',
43                         'Content-Type' => 'text/plain',
44                         'Message-ID' => '<hello@example.com>',
45                         Subject => 'this is a subject',
46                 ],
47                 body => $body,
48         )->as_string;
49         my $mime = Email::MIME->new($s);
50         my $html = msg_html($mime);
51
52         # ghetto tests
53         like($html, qr!<a\nhref="raw"!s, "raw link present");
54         like($html, qr/hello world\b/, "body present");
55         like($html, qr/&gt; keep this inline/, "short quoted text is inline");
56 }
57
58 # multipart crap
59 {
60         my $parts = [
61                 Email::MIME->create(
62                         attributes => { content_type => 'text/plain', },
63                         body => 'hi',
64                 ),
65                 Email::MIME->create(
66                         attributes => { content_type => 'text/plain', },
67                         body => 'bye',
68                 )
69         ];
70         my $mime = Email::MIME->create(
71                 header_str => [
72                         From => 'a@example.com',
73                         Subject => 'blargh',
74                         'Message-ID' => '<blah@example.com>',
75                         'In-Reply-To' => '<irp@example.com>',
76                         ],
77                 parts => $parts,
78         );
79
80         my $html = msg_html($mime);
81         like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
82 }
83
84 # multipart email with attached patch
85 {
86         my $parts = [
87                 Email::MIME->create(
88                         attributes => { content_type => 'text/plain', },
89                         body => 'hi, see attached patch',
90                 ),
91                 Email::MIME->create(
92                         attributes => {
93                                 content_type => 'text/plain',
94                                 filename => "foo.patch",
95                         },
96                         body => "--- a/file\n+++ b/file\n" .
97                                 "@@ -49, 7 +49,34 @@\n",
98                 ),
99         ];
100         my $mime = Email::MIME->create(
101                 header_str => [
102                         From => 'a@example.com',
103                         Subject => '[PATCH] asdf',
104                         'Message-ID' => '<patch@example.com>',
105                         ],
106                 parts => $parts,
107         );
108
109         my $html = msg_html($mime);
110         like($html, qr!.*Attachment #2: foo\.patch --!,
111                 "parts split with filename");
112 }
113
114 # multipart collapsed to single quoted-printable text/plain
115 {
116         my $parts = [
117                 Email::MIME->create(
118                         attributes => {
119                                 content_type => 'text/plain',
120                                 encoding => 'quoted-printable',
121                         },
122                         body => 'hi = bye',
123                 )
124         ];
125         my $mime = Email::MIME->create(
126                 header_str => [
127                         From => 'qp@example.com',
128                         Subject => 'QP',
129                         'Message-ID' => '<qp@example.com>',
130                         ],
131                 parts => $parts,
132         );
133
134         my $orig = $mime->body_raw;
135         my $html = msg_html($mime);
136         like($orig, qr/hi =3D bye=/, "our test used QP correctly");
137         like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
138 }
139
140 {
141         use PublicInbox::MID qw/id_compress/;
142
143         # n.b: this is probably invalid since we dropped CGI for PSGI:
144         like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
145                 "percent always converted to sha1 to workaround buggy httpds");
146
147         is(id_compress('foobar-wtf'), 'foobar-wtf',
148                 'regular ID not compressed');
149 }
150
151 done_testing();