1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
8 use PublicInbox::Config;
9 my @mods = qw(Filesys::Notify::Simple DBD::SQLite Search::Xapian);
10 foreach my $mod (@mods) {
12 plan skip_all => "$mod missing for watch_filter_rubylang_v2.t" if $@;
15 use_ok 'PublicInbox::WatchMaildir';
16 use_ok 'PublicInbox::Emergency';
17 my ($tmpdir, $for_destroy) = tmpdir();
18 local $ENV{PI_CONFIG} = "$tmpdir/pi_config";
22 if (require_git(2.6, 1)) {
23 use_ok 'PublicInbox::V2Writable';
26 skip 'git 2.6+ needed for V2', 40;
32 $SIG{__WARN__} = sub { push @warn, @_ };
33 my $cfgpfx = "publicinbox.$v";
34 my $inboxdir = "$tmpdir/$v";
35 my $maildir = "$tmpdir/md-$v";
36 my $spamdir = "$tmpdir/spam-$v";
37 my $addr = "test-$v\@example.com";
38 my @cmd = ('-init', "-$v", $v, $inboxdir,
39 "http://example.com/$v", $addr);
40 ok(run_script(\@cmd), 'public-inbox init OK');
42 ok(run_script(['-index', $inboxdir]), 'v1 indexed');
44 PublicInbox::Emergency->new($spamdir);
48 From: user\@example.com
52 Message-Id: <a.$i\@b.com>
53 Date: Sat, 05 Jan 2019 04:19:17 +0000
57 PublicInbox::Emergency->new($maildir)->prepare(\$msg);
61 From: spammer\@example.com
65 Message-Id: <a.99\@b.com>
66 Date: Sat, 05 Jan 2019 04:19:17 +0000
70 PublicInbox::Emergency->new($maildir)->prepare(\"$spam");
74 $cfgpfx.inboxdir=$inboxdir
75 $cfgpfx.watch=maildir:$maildir
76 $cfgpfx.filter=PublicInbox::Filter::RubyLang
77 $cfgpfx.altid=serial:alerts:file=msgmap.sqlite3
78 publicinboxwatch.watchspam=maildir:$spamdir
80 my $config = PublicInbox::Config->new(\$orig);
81 my $ibx = $config->lookup_name($v);
82 ok($ibx, 'found inbox by name');
84 my $w = PublicInbox::WatchMaildir->new($config);
89 # make sure all serials are searchable:
92 ($tot, $msgs) = $ibx->search->query("alerts:$i");
93 is($tot, 1, "got one result for alerts:$i");
94 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
96 ($tot, undef) = $ibx->search->query('b:spam');
97 is($tot, 1, 'got spam message');
99 my $nr = unlink <$maildir/new/*>;
102 PublicInbox::Emergency->new($spamdir)->prepare(\$spam);
103 my @new = glob("$spamdir/new/*");
104 my @p = split(m!/+!, $new[0]);
105 ok(link($new[0], "$spamdir/cur/".$p[-1].":2,S"));
106 is(unlink($new[0]), 1);
110 $config = PublicInbox::Config->new(\$orig);
111 $ibx = $config->lookup_name($v);
112 ($tot, undef) = $ibx->search->reopen->query('b:spam');
113 is($tot, 0, 'spam removed');
115 is_deeply([], \@warn, 'no warnings');