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';
9 use_ok 'PublicInbox::Config';
11 # FIXME: make this test less fragile
13 env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
14 -inbox => Plack::Util::inline_object(
16 search => sub { undef },
17 base_url => sub { 'http://example.com/' },
20 max_git_part => sub { undef },
21 description => sub { '' }),
22 www => Plack::Util::inline_object(style => sub { '' }),
24 $ctx->{-inbox}->{-primary_address} = 'test@example.com';
30 my $r = PublicInbox::View::msg_html($ctx, $mime);
32 while (defined(my $buf = $body->getline)) {
47 > Long and wordy reply goes here and it is split across multiple lines.
48 > We generate links to a separate full page where quoted-text is inline.
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
58 > See MAX_INLINE_QUOTED
59 > See MAX_INLINE_QUOTED
63 my $s = Email::Simple->create(
65 From => 'a@example.com',
66 To => 'b@example.com',
67 'Content-Type' => 'text/plain',
68 'Message-ID' => '<hello@example.com>',
69 Subject => 'this is a subject',
73 my $mime = Email::MIME->new($s);
74 my $html = msg_html($mime);
77 like($html, qr!<a\nhref="raw"!s, "raw link present");
78 like($html, qr/hello world\b/, "body present");
79 like($html, qr/> keep this inline/, "short quoted text is inline");
86 attributes => { content_type => 'text/plain', },
90 attributes => { content_type => 'text/plain', },
94 my $mime = Email::MIME->create(
96 From => 'a@example.com',
98 'Message-ID' => '<blah@example.com>',
99 'In-Reply-To' => '<irp@example.com>',
104 my $html = msg_html($mime);
105 like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
108 # multipart email with attached patch
112 attributes => { content_type => 'text/plain', },
113 body => 'hi, see attached patch',
117 content_type => 'text/plain',
118 filename => "foo&.patch",
120 body => "--- a/file\n+++ b/file\n" .
121 "@@ -49, 7 +49,34 @@\n",
124 my $mime = Email::MIME->create(
126 From => 'a@example.com',
127 Subject => '[PATCH] asdf',
128 'Message-ID' => '<patch@example.com>',
133 my $html = msg_html($mime);
134 like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
135 "parts split with filename");
138 # multipart collapsed to single quoted-printable text/plain
143 content_type => 'text/plain',
144 encoding => 'quoted-printable',
149 my $mime = Email::MIME->create(
151 From => 'qp@example.com',
153 'Message-ID' => '<qp@example.com>',
158 my $orig = $mime->body_raw;
159 my $html = msg_html($mime);
160 like($orig, qr/hi =3D bye=/, "our test used QP correctly");
161 like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
165 use PublicInbox::MID qw/id_compress/;
167 # n.b: this is probably invalid since we dropped CGI for PSGI:
168 like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
169 "percent always converted to sha1 to workaround buggy httpds");
171 is(id_compress('foobar-wtf'), 'foobar-wtf',
172 'regular ID not compressed');
176 my $cols = PublicInbox::View::COLS();
178 until (length(join(', ', @addr)) > ($cols * 2)) {
179 push @addr, '"l, f" <a@a>';
180 my $n = int(rand(20)) + 1;
181 push @addr, ('x'x$n).'@x';
183 my $orig = join(', ', @addr);
184 my $res = PublicInbox::View::fold_addresses($orig.'');
185 isnt($res, $orig, 'folded result');
186 unlike($res, qr/l,\n\tf/s, '"last, first" no broken');
187 my @nospc = ($res, $orig);
189 is($nospc[0], $nospc[1], 'no addresses lost in translation');
190 my $tws = PublicInbox::View::fold_addresses($orig.' ');
191 # (Email::Simple drops leading whitespace, but not trailing)
193 is($tws, $res, 'not thrown off by trailing whitespace');