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 use File::Temp qw/tempdir/;
13 my $have_xml_feed = eval { require XML::Feed; 1 };
14 require './t/common.perl';
17 my $res = PublicInbox::Feed::generate($_[0]);
20 while (defined(my $chunk = $body->getline)) {
27 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
28 my $git_dir = "$tmpdir/gittest";
29 my $ibx = PublicInbox::Inbox->new({
30 address => 'test@example',
33 url => 'http://example.com/test',
37 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
40 is(0, system(qw(git init -q --bare), $git_dir), "git init");
41 local $ENV{GIT_DIR} = $git_dir;
43 foreach my $i (1..6) {
44 my $mime = Email::MIME->new(<<EOF);
45 From: ME <me\@example.com>
46 To: U <u\@example.com>
47 Message-Id: <$i\@example.com>
49 Date: Thu, 01 Jan 1970 00:00:00 +0000
51 > This is a long multi line quote so it should not be allowed to
52 > show up in its entirty in the Atom feed. drop me
70 > this is a short quote
74 like($im->add($mime), qr/\A:\d+/, 'added');
83 my $feed = string_feed({ -inbox => $ibx });
85 skip 'XML::Feed missing', 2 unless $have_xml_feed;
86 my $p = XML::Feed->parse(\$feed);
87 is($p->format, "Atom", "parsed atom feed");
88 is(scalar $p->entries, 3, "parsed three entries");
89 is($p->id, 'mailto:test@example',
90 "id is set to default");
93 like($feed, qr/drop me/, "long quoted text kept");
94 like($feed, qr/inline me here/, "short quoted text kept");
95 like($feed, qr/keep me/, "unquoted text saved");
98 # add a new spam message
101 $spam = Email::MIME->new(<<EOF);
102 From: SPAMMER <spammer\@example.com>
103 To: U <u\@example.com>
104 Message-Id: <this-is-spam\@example.com>
105 Subject: SPAM!!!!!!!!
106 Date: Thu, 01 Jan 1970 00:00:00 +0000
113 # check spam shows up
115 my $spammy_feed = string_feed({ -inbox => $ibx });
117 skip 'XML::Feed missing', 2 unless $have_xml_feed;
118 my $p = XML::Feed->parse(\$spammy_feed);
119 is($p->format, "Atom", "parsed atom feed");
120 is(scalar $p->entries, 3, "parsed three entries");
122 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
129 # spam no longer shows up
131 my $feed = string_feed({ -inbox => $ibx });
133 skip 'XML::Feed missing', 2 unless $have_xml_feed;
134 my $p = XML::Feed->parse(\$feed);
135 is($p->format, "Atom", "parsed atom feed");
136 is(scalar $p->entries, 3, "parsed three entries");
138 unlike($feed, qr/SPAM/, "spam gone :>");