1 # Copyright (C) 2013-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
8 use_ok 'PublicInbox::View';
10 # FIXME: make this test less fragile
12 env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
13 -inbox => Plack::Util::inline_object(
15 search => sub { undef },
16 base_url => sub { 'http://example.com/' },
19 max_git_part => sub { undef },
20 description => sub { '' }),
22 $ctx->{-inbox}->{-primary_address} = 'test@example.com';
28 my $r = PublicInbox::View::msg_html($ctx, $mime);
30 while (defined(my $buf = $body->getline)) {
45 > Long and wordy reply goes here and it is split across multiple lines.
46 > We generate links to a separate full page where quoted-text is inline.
50 > See MAX_INLINE_QUOTED
51 > See MAX_INLINE_QUOTED
52 > See MAX_INLINE_QUOTED
53 > See MAX_INLINE_QUOTED
54 > See MAX_INLINE_QUOTED
55 > See MAX_INLINE_QUOTED
56 > See MAX_INLINE_QUOTED
57 > See MAX_INLINE_QUOTED
61 my $s = Email::Simple->create(
63 From => 'a@example.com',
64 To => 'b@example.com',
65 'Content-Type' => 'text/plain',
66 'Message-ID' => '<hello@example.com>',
67 Subject => 'this is a subject',
71 my $mime = Email::MIME->new($s);
72 my $html = msg_html($mime);
75 like($html, qr!<a\nhref="raw"!s, "raw link present");
76 like($html, qr/hello world\b/, "body present");
77 like($html, qr/> keep this inline/, "short quoted text is inline");
84 attributes => { content_type => 'text/plain', },
88 attributes => { content_type => 'text/plain', },
92 my $mime = Email::MIME->create(
94 From => 'a@example.com',
96 'Message-ID' => '<blah@example.com>',
97 'In-Reply-To' => '<irp@example.com>',
102 my $html = msg_html($mime);
103 like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
106 # multipart email with attached patch
110 attributes => { content_type => 'text/plain', },
111 body => 'hi, see attached patch',
115 content_type => 'text/plain',
116 filename => "foo&.patch",
118 body => "--- a/file\n+++ b/file\n" .
119 "@@ -49, 7 +49,34 @@\n",
122 my $mime = Email::MIME->create(
124 From => 'a@example.com',
125 Subject => '[PATCH] asdf',
126 'Message-ID' => '<patch@example.com>',
131 my $html = msg_html($mime);
132 like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
133 "parts split with filename");
136 # multipart collapsed to single quoted-printable text/plain
141 content_type => 'text/plain',
142 encoding => 'quoted-printable',
147 my $mime = Email::MIME->create(
149 From => 'qp@example.com',
151 'Message-ID' => '<qp@example.com>',
156 my $orig = $mime->body_raw;
157 my $html = msg_html($mime);
158 like($orig, qr/hi =3D bye=/, "our test used QP correctly");
159 like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
163 use PublicInbox::MID qw/id_compress/;
165 # n.b: this is probably invalid since we dropped CGI for PSGI:
166 like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
167 "percent always converted to sha1 to workaround buggy httpds");
169 is(id_compress('foobar-wtf'), 'foobar-wtf',
170 'regular ID not compressed');