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