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 require './t/common.perl';
11 my @mods = qw(DBD::SQLite Search::Xapian IPC::Run);
12 foreach my $mod (@mods) {
14 plan skip_all => "$mod missing for mda_filter_rubylang.t" if $@;
17 use_ok 'PublicInbox::V2Writable';
18 my $tmpdir = tempdir('mda-XXXXXX', TMPDIR => 1, CLEANUP => 1);
19 my $pi_config = "$tmpdir/pi_config";
20 local $ENV{PI_CONFIG} = $pi_config;
21 local $ENV{PI_EMERGENCY} = "$tmpdir/emergency";
22 my $mda = 'blib/script/public-inbox-mda';
23 my @cfg = ('git', 'config', "--file=$pi_config");
24 is(system(@cfg, 'publicinboxmda.spamcheck', 'none'), 0);
26 for my $v (qw(V1 V2)) {
28 $SIG{__WARN__} = sub { push @warn, @_ };
29 my $cfgpfx = "publicinbox.$v";
30 my $mainrepo = "$tmpdir/$v";
31 my $addr = "test-$v\@example.com";
32 my @cmd = ('blib/script/public-inbox-init', "-$v", $v, $mainrepo,
33 "http://example.com/$v", $addr);
34 is(system(@cmd), 0, 'public-inbox init OK');
35 is(system('blib/script/public-inbox-index', $mainrepo), 0);
36 is(system(@cfg, "$cfgpfx.filter", 'PublicInbox::Filter::RubyLang'), 0);
37 is(system(@cfg, "$cfgpfx.altid",
38 'serial:alerts:file=msgmap.sqlite3'), 0);
41 local $ENV{ORIGINAL_RECIPIENT} = $addr;
43 From: user\@example.com
47 Message-Id: <a.$i\@b.com>
48 Date: Sat, 05 Jan 2019 04:19:17 +0000
52 ok(IPC::Run::run([$mda], \"$msg"), 'message delivered');
54 my $config = PublicInbox::Config->new;
55 my $ibx = $config->lookup_name($v);
57 # make sure all serials are searchable:
60 ($tot, $msgs) = $ibx->search->query("alerts:$i");
61 is($tot, 1, "got one result for alerts:$i");
62 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
64 is_deeply([], \@warn, 'no warnings');
66 # TODO: public-inbox-learn doesn't know about filters