]> Sergey Matveev's repositories - public-inbox.git/blob - t/view.t
view: inline shorter quotes
[public-inbox.git] / t / view.t
1 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
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 5 lines
22 > See MAX_INLINE_QUOTED
23
24 hello world
25 EOF
26         my $s = Email::Simple->create(
27                 header => [
28                         From => 'a@example.com',
29                         To => 'b@example.com',
30                         'Content-Type' => 'text/plain',
31                         'Message-ID' => '<hello@example.com>',
32                         Subject => 'this is a subject',
33                 ],
34                 body => $body,
35         );
36         $s = Email::MIME->new($s->as_string);
37         my $html = PublicInbox::View->as_html($s);
38
39         # ghetto
40         like($html, qr/<a href="hello%40/s, "MID link present");
41         like($html, qr/hello world\b/, "body present");
42         like($html, qr/&gt; keep this inline/, "short quoted text is inline");
43         like($html, qr/<a name=[^>]+>&gt; Long and wordy/,
44                 "long quoted text is anchored");
45
46         # short page
47         my $pfx = "http://example.com/test/f";
48         my $short = PublicInbox::View->as_html($s, $pfx);
49         like($short, qr/\n&gt; keep this inline/,
50                 "short quoted text is inline");
51         like($short, qr/<a href="\Q$pfx\E#[^>]+>Long and wordy/,
52                 "long quoted text is made into a link");
53         ok(length($short) < length($html), "short page is shorter");
54 }
55
56 # multipart crap
57 {
58         my $parts = [
59                 Email::MIME->create(
60                         attributes => { content_type => 'text/plain', },
61                         body => 'hi',
62                 ),
63                 Email::MIME->create(
64                         attributes => { content_type => 'text/plain', },
65                         body => 'bye',
66                 )
67         ];
68         my $mime = Email::MIME->create(
69                 header_str => [
70                         From => 'a@example.com',
71                         Subject => 'blargh',
72                         'Message-ID' => '<blah@example.com>',
73                         'In-Reply-To' => '<irp@example.com>',
74                         ],
75                 parts => $parts,
76         );
77
78         my $html = PublicInbox::View->as_html($mime);
79         like($html, qr/hi\n-+ part #2 -+\nbye\n/, "multipart split");
80 }
81
82 # multipart email with attached patch
83 {
84         my $parts = [
85                 Email::MIME->create(
86                         attributes => { content_type => 'text/plain', },
87                         body => 'hi, see attached patch',
88                 ),
89                 Email::MIME->create(
90                         attributes => {
91                                 content_type => 'text/plain',
92                                 filename => "foo.patch",
93                         },
94                         body => "--- a/file\n+++ b/file\n" .
95                                 "@@ -49, 7 +49,34 @@\n",
96                 ),
97         ];
98         my $mime = Email::MIME->create(
99                 header_str => [
100                         From => 'a@example.com',
101                         Subject => '[PATCH] asdf',
102                         'Message-ID' => '<patch@example.com>',
103                         ],
104                 parts => $parts,
105         );
106
107         my $html = PublicInbox::View->as_html($mime);
108         like($html, qr!see attached patch\n-+ foo\.patch -+\n--- a/file\n!,
109                 "parts split with filename");
110 }
111
112 done_testing();