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
32 > This is a long multi line quote so it should not be allowed to
33 > show up in its entirty in the Atom feed. drop me
42 > this is a short quote
46 print $pipe $simple->as_string or die "print failed: $!\n";
47 close $pipe or die "close pipe failed: $!\n";
52 my $feed = PublicInbox::Feed->generate({
57 my $p = XML::Feed->parse(\$feed);
58 is($p->format, "Atom", "parsed atom feed");
59 is(scalar $p->entries, 3, "parsed three entries");
61 unlike($feed, qr/drop me/, "long quoted text dropped");
62 like($feed, qr/inline me here/, "short quoted text kept");
63 like($feed, qr/keep me/, "unquoted text saved");
66 # add a new spam message
69 my $pid = open(my $pipe, "|-");
70 defined $pid or die "fork/pipe failed: $!\n";
72 exec("ssoma-mda", $git_dir);
75 $spam = Email::Simple->new(<<EOF);
76 From: SPAMMER <spammer\@example.com>
77 To: U <u\@example.com>
78 Message-Id: <this-is-spam\@example.com>
80 Date: Thu, 01 Jan 1970 00:00:00 +0000
83 print $pipe $spam->as_string or die "print failed: $!\n";
84 close $pipe or die "close pipe failed: $!\n";
89 my $spammy_feed = PublicInbox::Feed->generate({
94 my $p = XML::Feed->parse(\$spammy_feed);
95 is($p->format, "Atom", "parsed atom feed");
96 is(scalar $p->entries, 3, "parsed three entries");
98 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
103 my $pid = open(my $pipe, "|-");
104 defined $pid or die "fork/pipe failed: $!\n";
106 exec("ssoma-rm", $git_dir);
108 print $pipe $spam->as_string or die "print failed: $!\n";
109 close $pipe or die "close pipe failed: $!\n";
112 # spam no longer shows up
114 my $feed = PublicInbox::Feed->generate({
118 if ($have_xml_feed) {
119 my $p = XML::Feed->parse(\$feed);
120 is($p->format, "Atom", "parsed atom feed");
121 is(scalar $p->entries, 3, "parsed three entries");
123 unlike($feed, qr/SPAM/, "spam gone :>");