1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
8 use PublicInbox::Config;
9 use File::Temp qw/tempdir/;
10 my $have_xml_feed = eval { require XML::Feed; 1 };
12 my $tmpdir = tempdir(CLEANUP => 1);
13 my $git_dir = "$tmpdir/gittest";
16 is(0, system(qw(git init -q --bare), $git_dir), "git init");
17 local $ENV{GIT_DIR} = $git_dir;
19 foreach my $i (1..6) {
20 my $pid = open(my $pipe, "|-");
21 defined $pid or die "fork/pipe failed: $!\n";
23 exec("ssoma-mda", $git_dir);
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
43 > this is a short quote
47 print $pipe $simple->as_string or die "print failed: $!\n";
48 close $pipe or die "close pipe failed: $!\n";
56 my $feed = PublicInbox::Feed->generate({
61 skip 'XML::Feed missing', 2 unless $have_xml_feed;
62 my $p = XML::Feed->parse(\$feed);
63 is($p->format, "Atom", "parsed atom feed");
64 is(scalar $p->entries, 3, "parsed three entries");
65 is($p->id, 'public-inbox@example.com',
66 "id is set to default");
68 unlike($feed, qr/drop me/, "long quoted text dropped");
69 like($feed, qr/inline me here/, "short quoted text kept");
70 like($feed, qr/keep me/, "unquoted text saved");
73 # add a new spam message
76 my $pid = open(my $pipe, "|-");
77 defined $pid or die "fork/pipe failed: $!\n";
79 exec("ssoma-mda", $git_dir);
82 $spam = Email::Simple->new(<<EOF);
83 From: SPAMMER <spammer\@example.com>
84 To: U <u\@example.com>
85 Message-Id: <this-is-spam\@example.com>
87 Date: Thu, 01 Jan 1970 00:00:00 +0000
90 print $pipe $spam->as_string or die "print failed: $!\n";
91 close $pipe or die "close pipe failed: $!\n";
96 my $spammy_feed = PublicInbox::Feed->generate({
101 skip 'XML::Feed missing', 2 unless $have_xml_feed;
102 my $p = XML::Feed->parse(\$spammy_feed);
103 is($p->format, "Atom", "parsed atom feed");
104 is(scalar $p->entries, 3, "parsed three entries");
106 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
111 my $pid = open(my $pipe, "|-");
112 defined $pid or die "fork/pipe failed: $!\n";
114 exec("ssoma-rm", $git_dir);
116 print $pipe $spam->as_string or die "print failed: $!\n";
117 close $pipe or die "close pipe failed: $!\n";
120 # spam no longer shows up
122 my $feed = PublicInbox::Feed->generate({
127 skip 'XML::Feed missing', 2 unless $have_xml_feed;
128 my $p = XML::Feed->parse(\$feed);
129 is($p->format, "Atom", "parsed atom feed");
130 is(scalar $p->entries, 3, "parsed three entries");
132 unlike($feed, qr/SPAM/, "spam gone :>");
138 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
139 my $feed = PublicInbox::Feed->generate({
144 'publicinbox.asdf.address' => $addr,
145 }, 'PublicInbox::Config'),
148 skip 'XML::Feed missing', 3 unless $have_xml_feed;
149 my $p = XML::Feed->parse(\$feed);
150 is($p->id, 'a@example.com', "ID is set correctly");
151 is($p->format, "Atom", "parsed atom feed");
152 is(scalar $p->entries, 3, "parsed three entries");