1 # Copyright (C) 2019-2021 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 require_mods(qw(DBD::SQLite Search::Xapian));
10 use_ok 'PublicInbox::Watch';
11 use_ok 'PublicInbox::Emergency';
12 my ($tmpdir, $for_destroy) = tmpdir();
13 local $ENV{PI_CONFIG} = "$tmpdir/pi_config";
17 if (require_git(2.6, 1)) {
18 use_ok 'PublicInbox::V2Writable';
21 skip 'git 2.6+ needed for V2', 40;
27 local $SIG{__WARN__} = sub { push @warn, @_ };
28 my $cfgpfx = "publicinbox.$v";
29 my $inboxdir = "$tmpdir/$v";
30 my $maildir = "$tmpdir/md-$v";
31 my $spamdir = "$tmpdir/spam-$v";
32 my $addr = "test-$v\@example.com";
33 my @cmd = ('-init', '-Lfull', "-$v", $v, $inboxdir,
34 "http://example.com/$v", $addr);
35 ok(run_script(\@cmd), 'public-inbox init');
36 PublicInbox::Emergency->new($spamdir);
40 From: user\@example.com
44 Message-Id: <a.$i\@b.com>
45 Date: Sat, 05 Jan 2019 04:19:17 +0000
49 PublicInbox::Emergency->new($maildir)->prepare(\$msg);
53 From: spammer\@example.com
57 Message-Id: <a.99\@b.com>
58 Date: Sat, 05 Jan 2019 04:19:17 +0000
62 PublicInbox::Emergency->new($maildir)->prepare(\"$spam");
66 $cfgpfx.inboxdir=$inboxdir
67 $cfgpfx.watch=maildir:$maildir
68 $cfgpfx.filter=PublicInbox::Filter::RubyLang
69 $cfgpfx.altid=serial:alerts:file=msgmap.sqlite3
70 publicinboxwatch.watchspam=maildir:$spamdir
72 my $cfg = PublicInbox::Config->new(\$orig);
73 my $ibx = $cfg->lookup_name($v);
74 $ibx->{-no_fsync} = 1;
75 ok($ibx, 'found inbox by name');
77 my $w = PublicInbox::Watch->new($cfg);
82 # make sure all serials are searchable:
84 my $mset = $ibx->search->mset("alerts:$i");
85 is($mset->size, 1, "got one result for alerts:$i");
86 my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
87 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
89 is($ibx->search->mset('b:spam')->size, 1, 'got spam message');
91 my $nr = unlink <$maildir/new/*>;
94 PublicInbox::Emergency->new($spamdir)->prepare(\$spam);
95 my @new = glob("$spamdir/new/*");
96 my @p = split(m!/+!, $new[0]);
97 ok(link($new[0], "$spamdir/cur/".$p[-1].":2,S"));
98 is(unlink($new[0]), 1);
102 $cfg = PublicInbox::Config->new(\$orig);
103 $ibx = $cfg->lookup_name($v);
104 $ibx->{-no_fsync} = 1;
105 is($ibx->search->reopen->mset('b:spam')->size, 0, 'spam removed');
107 is_deeply([], \@warn, 'no warnings');