1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
8 use PublicInbox::Config;
10 use File::Temp qw/tempdir/;
11 my $have_xml_feed = eval { require XML::Feed; 1 };
12 require 't/common.perl';
15 stream_to_string(PublicInbox::Feed::generate($_[0]));
18 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
19 my $git_dir = "$tmpdir/gittest";
22 is(0, system(qw(git init -q --bare), $git_dir), "git init");
23 local $ENV{GIT_DIR} = $git_dir;
25 foreach my $i (1..6) {
26 my $simple = Email::Simple->new(<<EOF);
27 From: ME <me\@example.com>
28 To: U <u\@example.com>
29 Message-Id: <$i\@example.com>
31 Date: Thu, 01 Jan 1970 00:00:00 +0000
33 > This is a long multi line quote so it should not be allowed to
34 > show up in its entirty in the Atom feed. drop me
52 > this is a short quote
56 my $str = $simple->as_string;
57 run(['ssoma-mda', $git_dir], \$str) or
58 die "mda failed: $?\n";
66 my $feed = string_feed({
71 skip 'XML::Feed missing', 2 unless $have_xml_feed;
72 my $p = XML::Feed->parse(\$feed);
73 is($p->format, "Atom", "parsed atom feed");
74 is(scalar $p->entries, 3, "parsed three entries");
75 is($p->id, 'mailto:public-inbox@example.com',
76 "id is set to default");
79 like($feed, qr/drop me/, "long quoted text kept");
80 like($feed, qr/inline me here/, "short quoted text kept");
81 like($feed, qr/keep me/, "unquoted text saved");
84 # add a new spam message
87 my $pid = open(my $pipe, "|-");
88 defined $pid or die "fork/pipe failed: $!\n";
90 exec("ssoma-mda", $git_dir);
93 $spam = Email::Simple->new(<<EOF);
94 From: SPAMMER <spammer\@example.com>
95 To: U <u\@example.com>
96 Message-Id: <this-is-spam\@example.com>
98 Date: Thu, 01 Jan 1970 00:00:00 +0000
101 print $pipe $spam->as_string or die "print failed: $!\n";
102 close $pipe or die "close pipe failed: $!\n";
105 # check spam shows up
107 my $spammy_feed = string_feed({
112 skip 'XML::Feed missing', 2 unless $have_xml_feed;
113 my $p = XML::Feed->parse(\$spammy_feed);
114 is($p->format, "Atom", "parsed atom feed");
115 is(scalar $p->entries, 3, "parsed three entries");
117 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
122 my $spam_str = $spam->as_string;
123 run(["ssoma-rm", $git_dir], \$spam_str) or
124 die "ssoma-rm failed: $?\n";
127 # spam no longer shows up
129 my $feed = string_feed({
134 skip 'XML::Feed missing', 2 unless $have_xml_feed;
135 my $p = XML::Feed->parse(\$feed);
136 is($p->format, "Atom", "parsed atom feed");
137 is(scalar $p->entries, 3, "parsed three entries");
139 unlike($feed, qr/SPAM/, "spam gone :>");
145 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
146 my $feed = string_feed({
151 'publicinbox.asdf.address' => $addr,
152 }, 'PublicInbox::Config'),
155 skip 'XML::Feed missing', 3 unless $have_xml_feed;
156 my $p = XML::Feed->parse(\$feed);
157 is($p->id, 'mailto:a@example.com',
158 "ID is set correctly");
159 is($p->format, "Atom", "parsed atom feed");
160 is(scalar $p->entries, 3, "parsed three entries");