1 # Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
8 use PublicInbox::Import;
9 use PublicInbox::Inbox;
10 my $have_xml_treepp = eval { require XML::TreePP; 1 };
11 use PublicInbox::TestCommon;
14 my $res = PublicInbox::Feed::generate($_[0]);
17 while (defined(my $chunk = $body->getline)) {
24 my ($tmpdir, $for_destroy) = tmpdir();
25 my $git_dir = "$tmpdir/gittest";
26 my $ibx = PublicInbox::Inbox->new({
27 address => 'test@example',
30 url => [ 'http://example.com/test' ],
34 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
38 foreach my $i (1..6) {
39 my $mime = PublicInbox::Eml->new(<<EOF);
40 From: ME <me\@example.com>
41 To: U <u\@example.com>
42 Message-Id: <$i\@example.com>
44 Date: Thu, 01 Jan 1970 00:00:00 +0000
46 > This is a long multi line quote so it should not be allowed to
47 > show up in its entirty in the Atom feed. drop me
65 > this is a short quote
69 like($im->add($mime), qr/\A:\d+/, 'added');
78 my $feed = string_feed({ -inbox => $ibx });
80 skip 'XML::TreePP missing', 3 unless $have_xml_treepp;
81 my $t = XML::TreePP->new->parse($feed);
82 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
83 'looks like an an Atom feed');
84 is(scalar @{$t->{feed}->{entry}}, 3,
85 'parsed three entries');
86 is($t->{feed}->{id}, 'mailto:test@example',
87 'id is set to default');
90 like($feed, qr/drop me/, "long quoted text kept");
91 like($feed, qr/inline me here/, "short quoted text kept");
92 like($feed, qr/keep me/, "unquoted text saved");
95 # add a new spam message
98 $spam = PublicInbox::Eml->new(<<EOF);
99 From: SPAMMER <spammer\@example.com>
100 To: U <u\@example.com>
101 Message-Id: <this-is-spam\@example.com>
102 Subject: SPAM!!!!!!!!
103 Date: Thu, 01 Jan 1970 00:00:00 +0000
110 # check spam shows up
112 my $spammy_feed = string_feed({ -inbox => $ibx });
114 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
115 my $t = XML::TreePP->new->parse($spammy_feed);
116 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
117 'looks like an an Atom feed');
118 is(scalar @{$t->{feed}->{entry}}, 3,
119 'parsed three entries');
121 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
128 # spam no longer shows up
130 my $feed = string_feed({ -inbox => $ibx });
132 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
133 my $t = XML::TreePP->new->parse($feed);
134 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
135 'looks like an an Atom feed');
136 is(scalar @{$t->{feed}->{entry}}, 3,
137 'parsed three entries');
139 unlike($feed, qr/SPAM/, "spam gone :>");