1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
9 use PublicInbox::Import;
10 use PublicInbox::Config;
11 use File::Temp qw/tempdir/;
12 my $have_xml_feed = eval { require XML::Feed; 1 };
13 require 't/common.perl';
16 stream_to_string(PublicInbox::Feed::generate($_[0]));
19 # ensure we are compatible with existing ssoma installations which
20 # do not use fast-import. We can probably remove this in 2018
23 return 0 if $ENV{FAST};
24 eval { require IPC::Run };
30 foreach my $p (split(':', $ENV{PATH})) {
38 ($x > 0 && (int(rand(10)) % 2) == 1);
41 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
42 my $git_dir = "$tmpdir/gittest";
43 my $git = PublicInbox::Git->new($git_dir);
44 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
47 is(0, system(qw(git init -q --bare), $git_dir), "git init");
48 local $ENV{GIT_DIR} = $git_dir;
50 foreach my $i (1..6) {
51 my $mime = Email::MIME->new(<<EOF);
52 From: ME <me\@example.com>
53 To: U <u\@example.com>
54 Message-Id: <$i\@example.com>
56 Date: Thu, 01 Jan 1970 00:00:00 +0000
58 > This is a long multi line quote so it should not be allowed to
59 > show up in its entirty in the Atom feed. drop me
77 > this is a short quote
81 if (rand_use('ssoma-mda')) {
83 my $str = $mime->as_string;
84 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
85 die "mda failed: $?\n";
87 like($im->add($mime), qr/\A:\d+/, 'added');
97 my $feed = string_feed({
102 skip 'XML::Feed missing', 2 unless $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");
106 is($p->id, 'mailto:public-inbox@example.com',
107 "id is set to default");
110 like($feed, qr/drop me/, "long quoted text kept");
111 like($feed, qr/inline me here/, "short quoted text kept");
112 like($feed, qr/keep me/, "unquoted text saved");
115 # add a new spam message
118 $spam = Email::MIME->new(<<EOF);
119 From: SPAMMER <spammer\@example.com>
120 To: U <u\@example.com>
121 Message-Id: <this-is-spam\@example.com>
122 Subject: SPAM!!!!!!!!
123 Date: Thu, 01 Jan 1970 00:00:00 +0000
126 if (rand_use('ssoma-mda')) {
127 my $str = $spam->as_string;
128 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
129 die "mda failed: $?\n";
136 # check spam shows up
138 my $spammy_feed = string_feed({
143 skip 'XML::Feed missing', 2 unless $have_xml_feed;
144 my $p = XML::Feed->parse(\$spammy_feed);
145 is($p->format, "Atom", "parsed atom feed");
146 is(scalar $p->entries, 3, "parsed three entries");
148 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
152 if (rand_use('ssoma-rm')) {
153 my $spam_str = $spam->as_string;
154 IPC::Run::run(["ssoma-rm", $git_dir], \$spam_str) or
155 die "ssoma-rm failed: $?\n";
161 # spam no longer shows up
163 my $feed = string_feed({
168 skip 'XML::Feed missing', 2 unless $have_xml_feed;
169 my $p = XML::Feed->parse(\$feed);
170 is($p->format, "Atom", "parsed atom feed");
171 is(scalar $p->entries, 3, "parsed three entries");
173 unlike($feed, qr/SPAM/, "spam gone :>");
179 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
180 my $feed = string_feed({
185 'publicinbox.asdf.address' => $addr,
186 }, 'PublicInbox::Config'),
189 skip 'XML::Feed missing', 3 unless $have_xml_feed;
190 my $p = XML::Feed->parse(\$feed);
191 is($p->id, 'mailto:a@example.com',
192 "ID is set correctly");
193 is($p->format, "Atom", "parsed atom feed");
194 is(scalar $p->entries, 3, "parsed three entries");