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 PublicInbox::Inbox;
12 use File::Temp qw/tempdir/;
13 my $have_xml_feed = eval { require XML::Feed; 1 };
14 require 't/common.perl';
17 stream_to_string(PublicInbox::Feed::generate($_[0]));
20 # ensure we are compatible with existing ssoma installations which
21 # do not use fast-import. We can probably remove this in 2018
24 return 0 if $ENV{FAST};
25 eval { require IPC::Run };
31 foreach my $p (split(':', $ENV{PATH})) {
39 ($x > 0 && (int(rand(10)) % 2) == 1);
42 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
43 my $git_dir = "$tmpdir/gittest";
44 my $ibx = PublicInbox::Inbox->new({
45 address => 'test@example',
48 url => 'http://example.com/test',
51 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
54 is(0, system(qw(git init -q --bare), $git_dir), "git init");
55 local $ENV{GIT_DIR} = $git_dir;
57 foreach my $i (1..6) {
58 my $mime = Email::MIME->new(<<EOF);
59 From: ME <me\@example.com>
60 To: U <u\@example.com>
61 Message-Id: <$i\@example.com>
63 Date: Thu, 01 Jan 1970 00:00:00 +0000
65 > This is a long multi line quote so it should not be allowed to
66 > show up in its entirty in the Atom feed. drop me
84 > this is a short quote
88 if (rand_use('ssoma-mda')) {
90 my $str = $mime->as_string;
91 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
92 die "mda failed: $?\n";
94 like($im->add($mime), qr/\A:\d+/, 'added');
104 my $feed = string_feed({
109 skip 'XML::Feed missing', 2 unless $have_xml_feed;
110 my $p = XML::Feed->parse(\$feed);
111 is($p->format, "Atom", "parsed atom feed");
112 is(scalar $p->entries, 3, "parsed three entries");
113 is($p->id, 'mailto:test@example',
114 "id is set to default");
117 like($feed, qr/drop me/, "long quoted text kept");
118 like($feed, qr/inline me here/, "short quoted text kept");
119 like($feed, qr/keep me/, "unquoted text saved");
122 # add a new spam message
125 $spam = Email::MIME->new(<<EOF);
126 From: SPAMMER <spammer\@example.com>
127 To: U <u\@example.com>
128 Message-Id: <this-is-spam\@example.com>
129 Subject: SPAM!!!!!!!!
130 Date: Thu, 01 Jan 1970 00:00:00 +0000
133 if (rand_use('ssoma-mda')) {
134 my $str = $spam->as_string;
135 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
136 die "mda failed: $?\n";
143 # check spam shows up
145 my $spammy_feed = string_feed({
150 skip 'XML::Feed missing', 2 unless $have_xml_feed;
151 my $p = XML::Feed->parse(\$spammy_feed);
152 is($p->format, "Atom", "parsed atom feed");
153 is(scalar $p->entries, 3, "parsed three entries");
155 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
159 if (rand_use('ssoma-rm')) {
160 my $spam_str = $spam->as_string;
161 IPC::Run::run(["ssoma-rm", $git_dir], \$spam_str) or
162 die "ssoma-rm failed: $?\n";
168 # spam no longer shows up
170 my $feed = string_feed({ -inbox => $ibx, max => 3 });
172 skip 'XML::Feed missing', 2 unless $have_xml_feed;
173 my $p = XML::Feed->parse(\$feed);
174 is($p->format, "Atom", "parsed atom feed");
175 is(scalar $p->entries, 3, "parsed three entries");
177 unlike($feed, qr/SPAM/, "spam gone :>");