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 stream_to_string(PublicInbox::Feed::generate($_[0]));
20 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
21 my $git_dir = "$tmpdir/gittest";
22 my $ibx = PublicInbox::Inbox->new({
23 address => 'test@example',
26 url => 'http://example.com/test',
30 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
33 is(0, system(qw(git init -q --bare), $git_dir), "git init");
34 local $ENV{GIT_DIR} = $git_dir;
36 foreach my $i (1..6) {
37 my $mime = Email::MIME->new(<<EOF);
38 From: ME <me\@example.com>
39 To: U <u\@example.com>
40 Message-Id: <$i\@example.com>
42 Date: Thu, 01 Jan 1970 00:00:00 +0000
44 > This is a long multi line quote so it should not be allowed to
45 > show up in its entirty in the Atom feed. drop me
63 > this is a short quote
67 like($im->add($mime), qr/\A:\d+/, 'added');
76 my $feed = string_feed({ -inbox => $ibx });
78 skip 'XML::Feed missing', 2 unless $have_xml_feed;
79 my $p = XML::Feed->parse(\$feed);
80 is($p->format, "Atom", "parsed atom feed");
81 is(scalar $p->entries, 3, "parsed three entries");
82 is($p->id, 'mailto:test@example',
83 "id is set to default");
86 like($feed, qr/drop me/, "long quoted text kept");
87 like($feed, qr/inline me here/, "short quoted text kept");
88 like($feed, qr/keep me/, "unquoted text saved");
91 # add a new spam message
94 $spam = Email::MIME->new(<<EOF);
95 From: SPAMMER <spammer\@example.com>
96 To: U <u\@example.com>
97 Message-Id: <this-is-spam\@example.com>
99 Date: Thu, 01 Jan 1970 00:00:00 +0000
106 # check spam shows up
108 my $spammy_feed = string_feed({ -inbox => $ibx });
110 skip 'XML::Feed missing', 2 unless $have_xml_feed;
111 my $p = XML::Feed->parse(\$spammy_feed);
112 is($p->format, "Atom", "parsed atom feed");
113 is(scalar $p->entries, 3, "parsed three entries");
115 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
122 # spam no longer shows up
124 my $feed = string_feed({ -inbox => $ibx });
126 skip 'XML::Feed missing', 2 unless $have_xml_feed;
127 my $p = XML::Feed->parse(\$feed);
128 is($p->format, "Atom", "parsed atom feed");
129 is(scalar $p->entries, 3, "parsed three entries");
131 unlike($feed, qr/SPAM/, "spam gone :>");