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>
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 over => sub { undef },
17 search => sub { undef },
18 base_url => sub { 'http://example.com/' },
21 max_git_epoch => sub { undef },
22 description => sub { '' }),
23 www => Plack::Util::inline_object(style => sub { '' }),
25 $ctx->{-inbox}->{-primary_address} = 'test@example.com';
28 my ($ctx, $mime) = @_;
31 my $r = PublicInbox::View::msg_html($ctx, $mime);
33 while (defined(my $buf = $body->getline)) {
48 > Long and wordy reply goes here and it is split across multiple lines.
49 > We generate links to a separate full page where quoted-text is inline.
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
60 > See MAX_INLINE_QUOTED
64 my $s = Email::Simple->create(
66 From => 'a@example.com',
67 To => 'b@example.com',
68 'Content-Type' => 'text/plain',
69 'Message-ID' => '<hello@example.com>',
70 Subject => 'this is a subject',
74 my $mime = Email::MIME->new($s);
75 my $html = msg_html($ctx, $mime);
78 like($html, qr!<a\nhref="raw"!s, "raw link present");
79 like($html, qr/hello world\b/, "body present");
80 like($html, qr/> keep this inline/, "short quoted text is inline");
87 attributes => { content_type => 'text/plain', },
91 attributes => { content_type => 'text/plain', },
95 my $mime = Email::MIME->create(
97 From => 'a@example.com',
99 'Message-ID' => '<blah@example.com>',
100 'In-Reply-To' => '<irp@example.com>',
105 my $html = msg_html($ctx, $mime);
106 like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
109 # multipart email with attached patch
113 attributes => { content_type => 'text/plain', },
114 body => 'hi, see attached patch',
118 content_type => 'text/plain',
119 filename => "foo&.patch",
121 body => "--- a/file\n+++ b/file\n" .
122 "@@ -49, 7 +49,34 @@\n",
125 my $mime = Email::MIME->create(
127 From => 'a@example.com',
128 Subject => '[PATCH] asdf',
129 'Message-ID' => '<patch@example.com>',
134 my $html = msg_html($ctx, $mime);
135 like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
136 "parts split with filename");
139 # multipart collapsed to single quoted-printable text/plain
144 content_type => 'text/plain',
145 encoding => 'quoted-printable',
150 my $mime = Email::MIME->create(
152 From => 'qp@example.com',
154 'Message-ID' => '<qp@example.com>',
159 my $orig = $mime->body_raw;
160 my $html = msg_html($ctx, $mime);
161 like($orig, qr/hi =3D bye=/, "our test used QP correctly");
162 like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
166 use PublicInbox::MID qw/id_compress/;
168 # n.b: this is probably invalid since we dropped CGI for PSGI:
169 like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
170 "percent always converted to sha1 to workaround buggy httpds");
172 is(id_compress('foobar-wtf'), 'foobar-wtf',
173 'regular ID not compressed');
177 my $cols = PublicInbox::View::COLS();
179 until (length(join(', ', @addr)) > ($cols * 2)) {
180 push @addr, '"l, f" <a@a>';
181 my $n = int(rand(20)) + 1;
182 push @addr, ('x'x$n).'@x';
184 my $orig = join(', ', @addr);
185 my $res = PublicInbox::View::fold_addresses($orig.'');
186 isnt($res, $orig, 'folded result');
187 unlike($res, qr/l,\n\tf/s, '"last, first" no broken');
188 my @nospc = ($res, $orig);
190 is($nospc[0], $nospc[1], 'no addresses lost in translation');
191 my $tws = PublicInbox::View::fold_addresses($orig.' ');
192 # (Email::Simple drops leading whitespace, but not trailing)
194 is($tws, $res, 'not thrown off by trailing whitespace');