]> Sergey Matveev's repositories - public-inbox.git/blob - t/mda_filter_rubylang.t
No ext_urls
[public-inbox.git] / t / mda_filter_rubylang.t
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>
3 use strict;
4 use warnings;
5 use Test::More;
6 use PublicInbox::Eml;
7 use PublicInbox::Config;
8 use PublicInbox::TestCommon;
9 require_git(2.6);
10 require_mods(qw(DBD::SQLite Search::Xapian));
11 use_ok 'PublicInbox::V2Writable';
12 my ($tmpdir, $for_destroy) = tmpdir();
13 my $pi_config = "$tmpdir/pi_config";
14 local $ENV{PI_CONFIG} = $pi_config;
15 local $ENV{PI_EMERGENCY} = "$tmpdir/emergency";
16 my @cfg = ('git', 'config', "--file=$pi_config");
17 is(xsys(@cfg, 'publicinboxmda.spamcheck', 'none'), 0);
18
19 for my $v (qw(V1 V2)) {
20         my @warn;
21         local $SIG{__WARN__} = sub { push @warn, @_ };
22         my $cfgpfx = "publicinbox.$v";
23         my $inboxdir = "$tmpdir/$v";
24         my $addr = "test-$v\@example.com";
25         my $cmd = [ '-init', "-$v", $v, $inboxdir,
26                 "http://example.com/$v", $addr ];
27         ok(run_script($cmd), 'public-inbox-init');
28         ok(run_script([qw(-index -j0), $inboxdir]), 'public-inbox-index');
29         is(xsys(@cfg, "$cfgpfx.filter", 'PublicInbox::Filter::RubyLang'), 0);
30         is(xsys(@cfg, "$cfgpfx.altid",
31                 'serial:alerts:file=msgmap.sqlite3'), 0);
32
33         for my $i (1..2) {
34                 my $env = { ORIGINAL_RECIPIENT => $addr };
35                 my $opt = { 0 => \(<<EOF) };
36 From: user\@example.com
37 To: $addr
38 Subject: blah $i
39 X-Mail-Count: $i
40 Message-Id: <a.$i\@b.com>
41 Date: Sat, 05 Jan 2019 04:19:17 +0000
42
43 something
44 EOF
45                 ok(run_script(['-mda'], $env, $opt), 'message delivered');
46         }
47         my $cfg = PublicInbox::Config->new;
48         my $ibx = $cfg->lookup_name($v);
49
50         # make sure all serials are searchable:
51         for my $i (1..2) {
52                 my $mset = $ibx->search->mset("alerts:$i");
53                 is($mset->size, 1, "got one result for alerts:$i");
54                 my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
55                 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
56         }
57         is_deeply([], \@warn, 'no warnings');
58
59         # TODO: public-inbox-learn doesn't know about filters
60         # (but -watch does)
61 }
62
63 done_testing();