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;
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};
29 foreach my $p (split(':', $ENV{PATH})) {
37 ($x > 0 && (int(rand(10)) % 2) == 1);
40 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
41 my $git_dir = "$tmpdir/gittest";
42 my $git = PublicInbox::Git->new($git_dir);
43 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
46 is(0, system(qw(git init -q --bare), $git_dir), "git init");
47 local $ENV{GIT_DIR} = $git_dir;
49 foreach my $i (1..6) {
50 my $mime = Email::MIME->new(<<EOF);
51 From: ME <me\@example.com>
52 To: U <u\@example.com>
53 Message-Id: <$i\@example.com>
55 Date: Thu, 01 Jan 1970 00:00:00 +0000
57 > This is a long multi line quote so it should not be allowed to
58 > show up in its entirty in the Atom feed. drop me
76 > this is a short quote
80 if (rand_use('ssoma-mda')) {
82 my $str = $mime->as_string;
83 run(['ssoma-mda', $git_dir], \$str) or
84 die "mda failed: $?\n";
86 like($im->add($mime), qr/\A:\d+/, 'added');
96 my $feed = string_feed({
101 skip 'XML::Feed missing', 2 unless $have_xml_feed;
102 my $p = XML::Feed->parse(\$feed);
103 is($p->format, "Atom", "parsed atom feed");
104 is(scalar $p->entries, 3, "parsed three entries");
105 is($p->id, 'mailto:public-inbox@example.com',
106 "id is set to default");
109 like($feed, qr/drop me/, "long quoted text kept");
110 like($feed, qr/inline me here/, "short quoted text kept");
111 like($feed, qr/keep me/, "unquoted text saved");
114 # add a new spam message
117 $spam = Email::MIME->new(<<EOF);
118 From: SPAMMER <spammer\@example.com>
119 To: U <u\@example.com>
120 Message-Id: <this-is-spam\@example.com>
121 Subject: SPAM!!!!!!!!
122 Date: Thu, 01 Jan 1970 00:00:00 +0000
125 if (rand_use('ssoma-mda')) {
126 my $pid = open(my $pipe, "|-");
127 defined $pid or die "fork/pipe failed: $!";
129 exec("ssoma-mda", $git_dir);
132 print $pipe $spam->as_string or die "print failed: $!";
133 close $pipe or die "close pipe failed: $!";
140 # check spam shows up
142 my $spammy_feed = string_feed({
147 skip 'XML::Feed missing', 2 unless $have_xml_feed;
148 my $p = XML::Feed->parse(\$spammy_feed);
149 is($p->format, "Atom", "parsed atom feed");
150 is(scalar $p->entries, 3, "parsed three entries");
152 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
156 if (rand_use('ssoma-rm')) {
157 my $spam_str = $spam->as_string;
158 run(["ssoma-rm", $git_dir], \$spam_str) or
159 die "ssoma-rm failed: $?\n";
165 # spam no longer shows up
167 my $feed = string_feed({
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 :>");
183 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
184 my $feed = string_feed({
189 'publicinbox.asdf.address' => $addr,
190 }, 'PublicInbox::Config'),
193 skip 'XML::Feed missing', 3 unless $have_xml_feed;
194 my $p = XML::Feed->parse(\$feed);
195 is($p->id, 'mailto:a@example.com',
196 "ID is set correctly");
197 is($p->format, "Atom", "parsed atom feed");
198 is(scalar $p->entries, 3, "parsed three entries");