1 # Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
8 use PublicInbox::Import;
9 use PublicInbox::Inbox;
10 my $have_xml_feed = eval { require XML::Feed; 1 };
11 use PublicInbox::TestCommon;
14 my $res = PublicInbox::Feed::generate($_[0]);
17 while (defined(my $chunk = $body->getline)) {
24 my ($tmpdir, $for_destroy) = tmpdir();
25 my $git_dir = "$tmpdir/gittest";
26 my $ibx = PublicInbox::Inbox->new({
27 address => 'test@example',
30 url => [ 'http://example.com/test' ],
34 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
37 is(0, system(qw(git init -q --bare), $git_dir), "git init");
38 local $ENV{GIT_DIR} = $git_dir;
40 foreach my $i (1..6) {
41 my $mime = Email::MIME->new(<<EOF);
42 From: ME <me\@example.com>
43 To: U <u\@example.com>
44 Message-Id: <$i\@example.com>
46 Date: Thu, 01 Jan 1970 00:00:00 +0000
48 > This is a long multi line quote so it should not be allowed to
49 > show up in its entirty in the Atom feed. drop me
67 > this is a short quote
71 like($im->add($mime), qr/\A:\d+/, 'added');
80 my $feed = string_feed({ -inbox => $ibx });
82 skip 'XML::Feed missing', 2 unless $have_xml_feed;
83 my $p = XML::Feed->parse(\$feed);
84 is($p->format, "Atom", "parsed atom feed");
85 is(scalar $p->entries, 3, "parsed three entries");
86 is($p->id, 'mailto:test@example',
87 "id is set to default");
90 like($feed, qr/drop me/, "long quoted text kept");
91 like($feed, qr/inline me here/, "short quoted text kept");
92 like($feed, qr/keep me/, "unquoted text saved");
95 # add a new spam message
98 $spam = Email::MIME->new(<<EOF);
99 From: SPAMMER <spammer\@example.com>
100 To: U <u\@example.com>
101 Message-Id: <this-is-spam\@example.com>
102 Subject: SPAM!!!!!!!!
103 Date: Thu, 01 Jan 1970 00:00:00 +0000
110 # check spam shows up
112 my $spammy_feed = string_feed({ -inbox => $ibx });
114 skip 'XML::Feed missing', 2 unless $have_xml_feed;
115 my $p = XML::Feed->parse(\$spammy_feed);
116 is($p->format, "Atom", "parsed atom feed");
117 is(scalar $p->entries, 3, "parsed three entries");
119 like($spammy_feed, qr/SPAM/s, "spam showed up :<");
126 # spam no longer shows up
128 my $feed = string_feed({ -inbox => $ibx });
130 skip 'XML::Feed missing', 2 unless $have_xml_feed;
131 my $p = XML::Feed->parse(\$feed);
132 is($p->format, "Atom", "parsed atom feed");
133 is(scalar $p->entries, 3, "parsed three entries");
135 unlike($feed, qr/SPAM/, "spam gone :>");