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 File::Temp qw/tempdir/;
9 my $have_xml_feed = eval { require XML::Feed; 1 };
11 my $tmpdir = tempdir(CLEANUP => 1);
12 my $git_dir = "$tmpdir/gittest";
15 is(0, system(qw(git init -q --bare), $git_dir), "git init");
16 local $ENV{GIT_DIR} = $git_dir;
18 foreach my $i (1..6) {
19 my $pid = open(my $pipe, "|-");
20 defined $pid or die "fork/pipe failed: $!\n";
22 exec("ssoma-mda", $git_dir);
25 my $simple = Email::Simple->new(<<EOF);
26 From: ME <me\@example.com>
27 To: U <u\@example.com>
28 Message-Id: <$i\@example.com>
30 Date: Thu, 01 Jan 1970 00:00:00 +0000
40 print $pipe $simple->as_string or die "print failed: $!\n";
41 close $pipe or die "close pipe failed: $!\n";
46 my $feed = PublicInbox::Feed->generate($git_dir, 3);
48 my $p = XML::Feed->parse(\$feed);
49 is($p->format, "Atom", "parsed atom feed");
50 is(scalar $p->entries, 3, "parsed three entries");
52 unlike($feed, qr/drop me/, "quoted text dropped");
53 like($feed, qr/keep me/, "unquoted text saved");
56 # add a new spam message
59 my $pid = open(my $pipe, "|-");
60 defined $pid or die "fork/pipe failed: $!\n";
62 exec("ssoma-mda", $git_dir);
65 $spam = Email::Simple->new(<<EOF);
66 From: SPAMMER <spammer\@example.com>
67 To: U <u\@example.com>
68 Message-Id: <this-is-spam\@example.com>
70 Date: Thu, 01 Jan 1970 00:00:00 +0000
73 print $pipe $spam->as_string or die "print failed: $!\n";
74 close $pipe or die "close pipe failed: $!\n";
79 my $spammy_feed = PublicInbox::Feed->generate($git_dir, 3);
81 my $p = XML::Feed->parse(\$spammy_feed);
82 is($p->format, "Atom", "parsed atom feed");
83 is(scalar $p->entries, 3, "parsed three entries");
85 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
90 my $pid = open(my $pipe, "|-");
91 defined $pid or die "fork/pipe failed: $!\n";
93 exec("ssoma-rm", $git_dir);
95 print $pipe $spam->as_string or die "print failed: $!\n";
96 close $pipe or die "close pipe failed: $!\n";
99 # spam no longer shows up
101 my $feed = PublicInbox::Feed->generate($git_dir, 3);
102 if ($have_xml_feed) {
103 my $p = XML::Feed->parse(\$feed);
104 is($p->format, "Atom", "parsed atom feed");
105 is(scalar $p->entries, 3, "parsed three entries");
107 unlike($feed, qr/SPAM/, "spam gone :>");