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})) {
36 (($x > 0 && (int(rand(10)) % 2) == 1) || $x < 0);
39 my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
40 my $git_dir = "$tmpdir/gittest";
41 my $git = PublicInbox::Git->new($git_dir);
42 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
45 is(0, system(qw(git init -q --bare), $git_dir), "git init");
46 local $ENV{GIT_DIR} = $git_dir;
48 foreach my $i (1..6) {
49 my $mime = Email::MIME->new(<<EOF);
50 From: ME <me\@example.com>
51 To: U <u\@example.com>
52 Message-Id: <$i\@example.com>
54 Date: Thu, 01 Jan 1970 00:00:00 +0000
56 > This is a long multi line quote so it should not be allowed to
57 > show up in its entirty in the Atom feed. drop me
75 > this is a short quote
79 if (rand_use('ssoma-mda')) {
81 my $str = $mime->as_string;
82 run(['ssoma-mda', $git_dir], \$str) or
83 die "mda failed: $?\n";
85 like($im->add($mime), qr/\A:\d+/, 'added');
95 my $feed = string_feed({
100 skip 'XML::Feed missing', 2 unless $have_xml_feed;
101 my $p = XML::Feed->parse(\$feed);
102 is($p->format, "Atom", "parsed atom feed");
103 is(scalar $p->entries, 3, "parsed three entries");
104 is($p->id, 'mailto:public-inbox@example.com',
105 "id is set to default");
108 like($feed, qr/drop me/, "long quoted text kept");
109 like($feed, qr/inline me here/, "short quoted text kept");
110 like($feed, qr/keep me/, "unquoted text saved");
113 # add a new spam message
116 $spam = Email::MIME->new(<<EOF);
117 From: SPAMMER <spammer\@example.com>
118 To: U <u\@example.com>
119 Message-Id: <this-is-spam\@example.com>
120 Subject: SPAM!!!!!!!!
121 Date: Thu, 01 Jan 1970 00:00:00 +0000
124 if (rand_use('ssoma-mda')) {
125 my $pid = open(my $pipe, "|-");
126 defined $pid or die "fork/pipe failed: $!";
128 exec("ssoma-mda", $git_dir);
131 print $pipe $spam->as_string or die "print failed: $!";
132 close $pipe or die "close pipe failed: $!";
139 # check spam shows up
141 my $spammy_feed = string_feed({
146 skip 'XML::Feed missing', 2 unless $have_xml_feed;
147 my $p = XML::Feed->parse(\$spammy_feed);
148 is($p->format, "Atom", "parsed atom feed");
149 is(scalar $p->entries, 3, "parsed three entries");
151 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
155 if (rand_use('ssoma-rm')) {
156 my $spam_str = $spam->as_string;
157 run(["ssoma-rm", $git_dir], \$spam_str) or
158 die "ssoma-rm failed: $?\n";
164 # spam no longer shows up
166 my $feed = string_feed({
171 skip 'XML::Feed missing', 2 unless $have_xml_feed;
172 my $p = XML::Feed->parse(\$feed);
173 is($p->format, "Atom", "parsed atom feed");
174 is(scalar $p->entries, 3, "parsed three entries");
176 unlike($feed, qr/SPAM/, "spam gone :>");
182 foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) {
183 my $feed = string_feed({
188 'publicinbox.asdf.address' => $addr,
189 }, 'PublicInbox::Config'),
192 skip 'XML::Feed missing', 3 unless $have_xml_feed;
193 my $p = XML::Feed->parse(\$feed);
194 is($p->id, 'mailto:a@example.com',
195 "ID is set correctly");
196 is($p->format, "Atom", "parsed atom feed");
197 is(scalar $p->entries, 3, "parsed three entries");