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
47 > this is a short quote
51 my $str = $simple->as_string;
52 run(['ssoma-mda', $git_dir], \$str) or
53 die "mda failed: $?\n";
61 my $feed = PublicInbox::Feed->generate({
66 skip 'XML::Feed missing', 2 unless $have_xml_feed;
67 my $p = XML::Feed->parse(\$feed);
68 is($p->format, "Atom", "parsed atom feed");
69 is(scalar $p->entries, 3, "parsed three entries");
70 is($p->id, 'mailto:public-inbox@example.com',
71 "id is set to default");
74 unlike($feed, qr/drop me/, "long quoted text dropped");
75 like($feed, qr!/f/\d%40example\.com\.html\b!,
76 "/f/ url generated for long quoted text");
77 like($feed, qr/inline me here/, "short quoted text kept");
78 like($feed, qr/keep me/, "unquoted text saved");
81 # add a new spam message
84 my $pid = open(my $pipe, "|-");
85 defined $pid or die "fork/pipe failed: $!\n";
87 exec("ssoma-mda", $git_dir);
90 $spam = Email::Simple->new(<<EOF);
91 From: SPAMMER <spammer\@example.com>
92 To: U <u\@example.com>
93 Message-Id: <this-is-spam\@example.com>
95 Date: Thu, 01 Jan 1970 00:00:00 +0000
98 print $pipe $spam->as_string or die "print failed: $!\n";
99 close $pipe or die "close pipe failed: $!\n";
102 # check spam shows up
104 my $spammy_feed = PublicInbox::Feed->generate({
109 skip 'XML::Feed missing', 2 unless $have_xml_feed;
110 my $p = XML::Feed->parse(\$spammy_feed);
111 is($p->format, "Atom", "parsed atom feed");
112 is(scalar $p->entries, 3, "parsed three entries");
114 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
119 my $spam_str = $spam->as_string;
120 run(["ssoma-rm", $git_dir], \$spam_str) or
121 die "ssoma-rm failed: $?\n";
124 # spam no longer shows up
126 my $feed = PublicInbox::Feed->generate({
131 skip 'XML::Feed missing', 2 unless $have_xml_feed;
132 my $p = XML::Feed->parse(\$feed);
133 is($p->format, "Atom", "parsed atom feed");
134 is(scalar $p->entries, 3, "parsed three entries");
136 unlike($feed, qr/SPAM/, "spam gone :>");
142 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
143 my $feed = PublicInbox::Feed->generate({
148 'publicinbox.asdf.address' => $addr,
149 }, 'PublicInbox::Config'),
152 skip 'XML::Feed missing', 3 unless $have_xml_feed;
153 my $p = XML::Feed->parse(\$feed);
154 is($p->id, 'mailto:a@example.com',
155 "ID is set correctly");
156 is($p->format, "Atom", "parsed atom feed");
157 is(scalar $p->entries, 3, "parsed three entries");