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;
10 use File::Temp qw/tempdir/;
11 my $have_xml_feed = eval { require XML::Feed; 1 };
13 my $tmpdir = tempdir(CLEANUP => 1);
14 my $git_dir = "$tmpdir/gittest";
17 is(0, system(qw(git init -q --bare), $git_dir), "git init");
18 local $ENV{GIT_DIR} = $git_dir;
20 foreach my $i (1..6) {
21 my $simple = Email::Simple->new(<<EOF);
22 From: ME <me\@example.com>
23 To: U <u\@example.com>
24 Message-Id: <$i\@example.com>
26 Date: Thu, 01 Jan 1970 00:00:00 +0000
28 > This is a long multi line quote so it should not be allowed to
29 > show up in its entirty in the Atom feed. drop me
38 > this is a short quote
42 my $str = $simple->as_string;
43 run(['ssoma-mda', $git_dir], \$str) or
44 die "mda failed: $?\n";
52 my $feed = PublicInbox::Feed->generate({
57 skip 'XML::Feed missing', 2 unless $have_xml_feed;
58 my $p = XML::Feed->parse(\$feed);
59 is($p->format, "Atom", "parsed atom feed");
60 is(scalar $p->entries, 3, "parsed three entries");
61 is($p->id, 'mailto:public-inbox@example.com',
62 "id is set to default");
65 unlike($feed, qr/drop me/, "long quoted text dropped");
66 like($feed, qr!/f/\d%40example\.com\.html\b!,
67 "/f/ url generated for long quoted text");
68 like($feed, qr/inline me here/, "short quoted text kept");
69 like($feed, qr/keep me/, "unquoted text saved");
72 # add a new spam message
75 my $pid = open(my $pipe, "|-");
76 defined $pid or die "fork/pipe failed: $!\n";
78 exec("ssoma-mda", $git_dir);
81 $spam = Email::Simple->new(<<EOF);
82 From: SPAMMER <spammer\@example.com>
83 To: U <u\@example.com>
84 Message-Id: <this-is-spam\@example.com>
86 Date: Thu, 01 Jan 1970 00:00:00 +0000
89 print $pipe $spam->as_string or die "print failed: $!\n";
90 close $pipe or die "close pipe failed: $!\n";
95 my $spammy_feed = PublicInbox::Feed->generate({
100 skip 'XML::Feed missing', 2 unless $have_xml_feed;
101 my $p = XML::Feed->parse(\$spammy_feed);
102 is($p->format, "Atom", "parsed atom feed");
103 is(scalar $p->entries, 3, "parsed three entries");
105 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
110 my $spam_str = $spam->as_string;
111 run(["ssoma-rm", $git_dir], \$spam_str) or
112 die "ssoma-rm failed: $?\n";
115 # spam no longer shows up
117 my $feed = PublicInbox::Feed->generate({
122 skip 'XML::Feed missing', 2 unless $have_xml_feed;
123 my $p = XML::Feed->parse(\$feed);
124 is($p->format, "Atom", "parsed atom feed");
125 is(scalar $p->entries, 3, "parsed three entries");
127 unlike($feed, qr/SPAM/, "spam gone :>");
133 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
134 my $feed = PublicInbox::Feed->generate({
139 'publicinbox.asdf.address' => $addr,
140 }, 'PublicInbox::Config'),
143 skip 'XML::Feed missing', 3 unless $have_xml_feed;
144 my $p = XML::Feed->parse(\$feed);
145 is($p->id, 'mailto:a@example.com',
146 "ID is set correctly");
147 is($p->format, "Atom", "parsed atom feed");
148 is(scalar $p->entries, 3, "parsed three entries");