2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
9 use PublicInbox::Inbox;
10 my $have_xml_treepp = eval { require XML::TreePP; 1 };
11 my ($tmpdir, $for_destroy) = tmpdir();
13 my $git_dir = "$tmpdir/gittest";
14 my $ibx = create_inbox 'v1', tmpdir => $git_dir, sub {
16 foreach my $i (1..6) {
17 $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
18 From: ME <me\@example.com>
19 To: U <u\@example.com>
20 Message-Id: <$i\@example.com>
22 Date: Thu, 01 Jan 1970 00:00:00 +0000
29 > this is a short quote
36 $ibx->{url} = [ 'http://example.com/test' ];
40 env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
42 my $string_feed = sub {
43 my $res = PublicInbox::Feed::generate($ctx);
46 while (defined(my $chunk = $body->getline)) {
53 my $im = $ibx->importer(0);
59 my $feed = $string_feed->();
61 skip 'XML::TreePP missing', 3 unless $have_xml_treepp;
62 my $t = XML::TreePP->new->parse($feed);
63 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
64 'looks like an an Atom feed');
65 is(scalar @{$t->{feed}->{entry}}, 3,
66 'parsed three entries');
67 is($t->{feed}->{id}, 'mailto:v1@example.com',
68 'id is set to default');
71 like($feed, qr/drop me/, "long quoted text kept");
72 like($feed, qr/inline me here/, "short quoted text kept");
73 like($feed, qr/keep me/, "unquoted text saved");
76 # add a new spam message
79 $spam = PublicInbox::Eml->new(<<EOF);
80 From: SPAMMER <spammer\@example.com>
81 To: U <u\@example.com>
82 Message-Id: <this-is-spam\@example.com>
84 Date: Thu, 01 Jan 1970 00:00:00 +0000
93 my $spammy_feed = $string_feed->();
95 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
96 my $t = XML::TreePP->new->parse($spammy_feed);
97 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
98 'looks like an an Atom feed');
99 is(scalar @{$t->{feed}->{entry}}, 3,
100 'parsed three entries');
102 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
109 # spam no longer shows up
111 my $feed = $string_feed->();
113 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
114 my $t = XML::TreePP->new->parse($feed);
115 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
116 'looks like an an Atom feed');
117 is(scalar @{$t->{feed}->{entry}}, 3,
118 'parsed three entries');
120 unlike($feed, qr/SPAM/, "spam gone :>");