1 # Copyright (C) 2013-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 require_mods('Plack::Util');
9 use_ok 'PublicInbox::View';
10 use_ok 'PublicInbox::Config';
12 # FIXME: make this test less fragile
14 env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
15 -inbox => Plack::Util::inline_object(
17 over => sub { undef },
18 search => sub { undef },
19 base_url => sub { 'http://example.com/' },
22 max_git_epoch => sub { undef },
23 description => sub { '' }),
24 www => Plack::Util::inline_object(style => sub { '' }),
26 $ctx->{-inbox}->{-primary_address} = 'test@example.com';
29 my ($ctx, $mime) = @_;
32 my $r = PublicInbox::View::msg_html($ctx, $mime);
34 while (defined(my $buf = $body->getline)) {
49 > Long and wordy reply goes here and it is split across multiple lines.
50 > We generate links to a separate full page where quoted-text is inline.
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
60 > See MAX_INLINE_QUOTED
61 > See MAX_INLINE_QUOTED
65 my $s = Email::Simple->create(
67 From => 'a@example.com',
68 To => 'b@example.com',
69 'Content-Type' => 'text/plain',
70 'Message-ID' => '<hello@example.com>',
71 Subject => 'this is a subject',
75 my $mime = Email::MIME->new($s);
76 my $html = msg_html($ctx, $mime);
79 like($html, qr!<a\nhref="raw"!s, "raw link present");
80 like($html, qr/hello world\b/, "body present");
81 like($html, qr/> keep this inline/, "short quoted text is inline");
88 attributes => { content_type => 'text/plain', },
92 attributes => { content_type => 'text/plain', },
96 my $mime = Email::MIME->create(
98 From => 'a@example.com',
100 'Message-ID' => '<blah@example.com>',
101 'In-Reply-To' => '<irp@example.com>',
106 my $html = msg_html($ctx, $mime);
107 like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
110 # multipart email with attached patch
114 attributes => { content_type => 'text/plain', },
115 body => 'hi, see attached patch',
119 content_type => 'text/plain',
120 filename => "foo&.patch",
122 body => "--- a/file\n+++ b/file\n" .
123 "@@ -49, 7 +49,34 @@\n",
126 my $mime = Email::MIME->create(
128 From => 'a@example.com',
129 Subject => '[PATCH] asdf',
130 'Message-ID' => '<patch@example.com>',
135 my $html = msg_html($ctx, $mime);
136 like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
137 "parts split with filename");
140 # multipart collapsed to single quoted-printable text/plain
145 content_type => 'text/plain',
146 encoding => 'quoted-printable',
151 my $mime = Email::MIME->create(
153 From => 'qp@example.com',
155 'Message-ID' => '<qp@example.com>',
160 my $orig = $mime->body_raw;
161 my $html = msg_html($ctx, $mime);
162 like($orig, qr/hi =3D bye=/, "our test used QP correctly");
163 like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
167 use PublicInbox::MID qw/id_compress/;
169 # n.b: this is probably invalid since we dropped CGI for PSGI:
170 like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
171 "percent always converted to sha1 to workaround buggy httpds");
173 is(id_compress('foobar-wtf'), 'foobar-wtf',
174 'regular ID not compressed');
178 my $cols = PublicInbox::View::COLS();
180 until (length(join(', ', @addr)) > ($cols * 2)) {
181 push @addr, '"l, f" <a@a>';
182 my $n = int(rand(20)) + 1;
183 push @addr, ('x'x$n).'@x';
185 my $orig = join(', ', @addr);
186 my $res = PublicInbox::View::fold_addresses($orig.'');
187 isnt($res, $orig, 'folded result');
188 unlike($res, qr/l,\n\tf/s, '"last, first" no broken');
189 my @nospc = ($res, $orig);
191 is($nospc[0], $nospc[1], 'no addresses lost in translation');
192 my $tws = PublicInbox::View::fold_addresses($orig.' ');
193 # (Email::Simple drops leading whitespace, but not trailing)
195 is($tws, $res, 'not thrown off by trailing whitespace');