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');
37 is(0, system(qw(git init -q --bare), $git_dir), "git init");
38 local $ENV{GIT_DIR} = $git_dir;
40 foreach my $i (1..6) {
41 my $mime = Email::MIME->new(<<EOF);
42 From: ME <me\@example.com>
43 To: U <u\@example.com>
44 Message-Id: <$i\@example.com>
46 Date: Thu, 01 Jan 1970 00:00:00 +0000
48 > This is a long multi line quote so it should not be allowed to
49 > show up in its entirty in the Atom feed. drop me
67 > this is a short quote
71 like($im->add($mime), qr/\A:\d+/, 'added');
80 my $feed = string_feed({ -inbox => $ibx });
82 skip 'XML::TreePP missing', 3 unless $have_xml_treepp;
83 my $t = XML::TreePP->new->parse($feed);
84 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
85 'looks like an an Atom feed');
86 is(scalar @{$t->{feed}->{entry}}, 3,
87 'parsed three entries');
88 is($t->{feed}->{id}, 'mailto:test@example',
89 'id is set to default');
92 like($feed, qr/drop me/, "long quoted text kept");
93 like($feed, qr/inline me here/, "short quoted text kept");
94 like($feed, qr/keep me/, "unquoted text saved");
97 # add a new spam message
100 $spam = Email::MIME->new(<<EOF);
101 From: SPAMMER <spammer\@example.com>
102 To: U <u\@example.com>
103 Message-Id: <this-is-spam\@example.com>
104 Subject: SPAM!!!!!!!!
105 Date: Thu, 01 Jan 1970 00:00:00 +0000
112 # check spam shows up
114 my $spammy_feed = string_feed({ -inbox => $ibx });
116 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
117 my $t = XML::TreePP->new->parse($spammy_feed);
118 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
119 'looks like an an Atom feed');
120 is(scalar @{$t->{feed}->{entry}}, 3,
121 'parsed three entries');
123 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
130 # spam no longer shows up
132 my $feed = string_feed({ -inbox => $ibx });
134 skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
135 my $t = XML::TreePP->new->parse($feed);
136 like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
137 'looks like an an Atom feed');
138 is(scalar @{$t->{feed}->{entry}}, 3,
139 'parsed three entries');
141 unlike($feed, qr/SPAM/, "spam gone :>");