1 # Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <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',
52 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
55 is(0, system(qw(git init -q --bare), $git_dir), "git init");
56 local $ENV{GIT_DIR} = $git_dir;
58 foreach my $i (1..6) {
59 my $mime = Email::MIME->new(<<EOF);
60 From: ME <me\@example.com>
61 To: U <u\@example.com>
62 Message-Id: <$i\@example.com>
64 Date: Thu, 01 Jan 1970 00:00:00 +0000
66 > This is a long multi line quote so it should not be allowed to
67 > show up in its entirty in the Atom feed. drop me
85 > this is a short quote
89 if (rand_use('ssoma-mda')) {
91 my $str = $mime->as_string;
92 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
93 die "mda failed: $?\n";
95 like($im->add($mime), qr/\A:\d+/, 'added');
105 my $feed = string_feed({ -inbox => $ibx });
107 skip 'XML::Feed missing', 2 unless $have_xml_feed;
108 my $p = XML::Feed->parse(\$feed);
109 is($p->format, "Atom", "parsed atom feed");
110 is(scalar $p->entries, 3, "parsed three entries");
111 is($p->id, 'mailto:test@example',
112 "id is set to default");
115 like($feed, qr/drop me/, "long quoted text kept");
116 like($feed, qr/inline me here/, "short quoted text kept");
117 like($feed, qr/keep me/, "unquoted text saved");
120 # add a new spam message
123 $spam = Email::MIME->new(<<EOF);
124 From: SPAMMER <spammer\@example.com>
125 To: U <u\@example.com>
126 Message-Id: <this-is-spam\@example.com>
127 Subject: SPAM!!!!!!!!
128 Date: Thu, 01 Jan 1970 00:00:00 +0000
131 if (rand_use('ssoma-mda')) {
132 my $str = $spam->as_string;
133 IPC::Run::run(['ssoma-mda', $git_dir], \$str) or
134 die "mda failed: $?\n";
141 # check spam shows up
143 my $spammy_feed = string_feed({ -inbox => $ibx });
145 skip 'XML::Feed missing', 2 unless $have_xml_feed;
146 my $p = XML::Feed->parse(\$spammy_feed);
147 is($p->format, "Atom", "parsed atom feed");
148 is(scalar $p->entries, 3, "parsed three entries");
150 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
154 if (rand_use('ssoma-rm')) {
155 my $spam_str = $spam->as_string;
156 IPC::Run::run(["ssoma-rm", $git_dir], \$spam_str) or
157 die "ssoma-rm failed: $?\n";
163 # spam no longer shows up
165 my $feed = string_feed({ -inbox => $ibx });
167 skip 'XML::Feed missing', 2 unless $have_xml_feed;
168 my $p = XML::Feed->parse(\$feed);
169 is($p->format, "Atom", "parsed atom feed");
170 is(scalar $p->entries, 3, "parsed three entries");
172 unlike($feed, qr/SPAM/, "spam gone :>");