1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw/tempdir/;
8 use PublicInbox::Config;
9 my @mods = qw(DBD::SQLite Search::Xapian IPC::Run);
10 foreach my $mod (@mods) {
12 plan skip_all => "$mod missing for mda_filter_rubylang.t" if $@;
15 use_ok 'PublicInbox::V2Writable';
16 my $tmpdir = tempdir('mda-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 my $pi_config = "$tmpdir/pi_config";
18 local $ENV{PI_CONFIG} = $pi_config;
19 local $ENV{PI_EMERGENCY} = "$tmpdir/emergency";
20 my $mda = 'blib/script/public-inbox-mda';
21 my @cfg = ('git', 'config', "--file=$pi_config");
22 is(system(@cfg, 'publicinboxmda.spamcheck', 'none'), 0);
24 for my $v (qw(V1 V2)) {
26 $SIG{__WARN__} = sub { push @warn, @_ };
27 my $cfgpfx = "publicinbox.$v";
28 my $mainrepo = "$tmpdir/$v";
29 my $addr = "test-$v\@example.com";
30 my @cmd = ('blib/script/public-inbox-init', "-$v", $v, $mainrepo,
31 "http://example.com/$v", $addr);
32 is(system(@cmd), 0, 'public-inbox init OK');
33 is(system('blib/script/public-inbox-index', $mainrepo), 0);
34 is(system(@cfg, "$cfgpfx.filter", 'PublicInbox::Filter::RubyLang'), 0);
35 is(system(@cfg, "$cfgpfx.altid",
36 'serial:alerts:file=msgmap.sqlite3'), 0);
39 local $ENV{ORIGINAL_RECIPIENT} = $addr;
41 From: user\@example.com
45 Message-Id: <a.$i\@b.com>
46 Date: Sat, 05 Jan 2019 04:19:17 +0000
50 ok(IPC::Run::run([$mda], \"$msg"), 'message delivered');
52 my $config = PublicInbox::Config->new;
53 my $ibx = $config->lookup_name($v);
55 # make sure all serials are searchable:
58 ($tot, $msgs) = $ibx->search->query("alerts:$i");
59 is($tot, 1, "got one result for alerts:$i");
60 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
62 is_deeply([], \@warn, 'no warnings');
64 # TODO: public-inbox-learn doesn't know about filters