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 unlike($feed, qr/drop me/, "long quoted text dropped");
80 like($feed, qr!/\d%40example\.com/f/#q!,
81 "/f/ url generated for long quoted text");
82 like($feed, qr/inline me here/, "short quoted text kept");
83 like($feed, qr/keep me/, "unquoted text saved");
86 # add a new spam message
89 my $pid = open(my $pipe, "|-");
90 defined $pid or die "fork/pipe failed: $!\n";
92 exec("ssoma-mda", $git_dir);
95 $spam = Email::Simple->new(<<EOF);
96 From: SPAMMER <spammer\@example.com>
97 To: U <u\@example.com>
98 Message-Id: <this-is-spam\@example.com>
100 Date: Thu, 01 Jan 1970 00:00:00 +0000
103 print $pipe $spam->as_string or die "print failed: $!\n";
104 close $pipe or die "close pipe failed: $!\n";
107 # check spam shows up
109 my $spammy_feed = string_feed({
114 skip 'XML::Feed missing', 2 unless $have_xml_feed;
115 my $p = XML::Feed->parse(\$spammy_feed);
116 is($p->format, "Atom", "parsed atom feed");
117 is(scalar $p->entries, 3, "parsed three entries");
119 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
124 my $spam_str = $spam->as_string;
125 run(["ssoma-rm", $git_dir], \$spam_str) or
126 die "ssoma-rm failed: $?\n";
129 # spam no longer shows up
131 my $feed = string_feed({
136 skip 'XML::Feed missing', 2 unless $have_xml_feed;
137 my $p = XML::Feed->parse(\$feed);
138 is($p->format, "Atom", "parsed atom feed");
139 is(scalar $p->entries, 3, "parsed three entries");
141 unlike($feed, qr/SPAM/, "spam gone :>");
147 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
148 my $feed = string_feed({
153 'publicinbox.asdf.address' => $addr,
154 }, 'PublicInbox::Config'),
157 skip 'XML::Feed missing', 3 unless $have_xml_feed;
158 my $p = XML::Feed->parse(\$feed);
159 is($p->id, 'mailto:a@example.com',
160 "ID is set correctly");
161 is($p->format, "Atom", "parsed atom feed");
162 is(scalar $p->entries, 3, "parsed three entries");