1 # Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
9 use PublicInbox::Import;
10 use PublicInbox::Config;
11 use PublicInbox::Inbox;
12 my $have_xml_feed = eval { require XML::Feed; 1 };
13 use PublicInbox::TestCommon;
16 my $res = PublicInbox::Feed::generate($_[0]);
19 while (defined(my $chunk = $body->getline)) {
26 my ($tmpdir, $for_destroy) = tmpdir();
27 my $git_dir = "$tmpdir/gittest";
28 my $ibx = PublicInbox::Inbox->new({
29 address => 'test@example',
32 url => 'http://example.com/test',
36 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
39 is(0, system(qw(git init -q --bare), $git_dir), "git init");
40 local $ENV{GIT_DIR} = $git_dir;
42 foreach my $i (1..6) {
43 my $mime = Email::MIME->new(<<EOF);
44 From: ME <me\@example.com>
45 To: U <u\@example.com>
46 Message-Id: <$i\@example.com>
48 Date: Thu, 01 Jan 1970 00:00:00 +0000
50 > This is a long multi line quote so it should not be allowed to
51 > show up in its entirty in the Atom feed. drop me
69 > this is a short quote
73 like($im->add($mime), qr/\A:\d+/, 'added');
82 my $feed = string_feed({ -inbox => $ibx });
84 skip 'XML::Feed missing', 2 unless $have_xml_feed;
85 my $p = XML::Feed->parse(\$feed);
86 is($p->format, "Atom", "parsed atom feed");
87 is(scalar $p->entries, 3, "parsed three entries");
88 is($p->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::Feed missing', 2 unless $have_xml_feed;
117 my $p = XML::Feed->parse(\$spammy_feed);
118 is($p->format, "Atom", "parsed atom feed");
119 is(scalar $p->entries, 3, "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::Feed missing', 2 unless $have_xml_feed;
133 my $p = XML::Feed->parse(\$feed);
134 is($p->format, "Atom", "parsed atom feed");
135 is(scalar $p->entries, 3, "parsed three entries");
137 unlike($feed, qr/SPAM/, "spam gone :>");