1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::Config;
8 require './t/common.perl';
10 my @mods = qw(DBD::SQLite Search::Xapian);
11 foreach my $mod (@mods) {
13 plan skip_all => "$mod missing for mda_filter_rubylang.t" if $@;
16 use_ok 'PublicInbox::V2Writable';
17 my ($tmpdir, $for_destroy) = tmpdir();
18 my $pi_config = "$tmpdir/pi_config";
19 local $ENV{PI_CONFIG} = $pi_config;
20 local $ENV{PI_EMERGENCY} = "$tmpdir/emergency";
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 $inboxdir = "$tmpdir/$v";
29 my $addr = "test-$v\@example.com";
30 my $cmd = [ '-init', "-$v", $v, $inboxdir,
31 "http://example.com/$v", $addr ];
32 ok(run_script($cmd), 'public-inbox-init');
33 ok(run_script(['-index', $inboxdir]), 'public-inbox-index');
34 is(system(@cfg, "$cfgpfx.filter", 'PublicInbox::Filter::RubyLang'), 0);
35 is(system(@cfg, "$cfgpfx.altid",
36 'serial:alerts:file=msgmap.sqlite3'), 0);
39 my $env = { ORIGINAL_RECIPIENT => $addr };
40 my $opt = { 0 => \(<<EOF) };
41 From: user\@example.com
45 Message-Id: <a.$i\@b.com>
46 Date: Sat, 05 Jan 2019 04:19:17 +0000
50 ok(run_script(['-mda'], $env, $opt), '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