1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::Config;
6 use PublicInbox::TestCommon;
8 require_mods(qw(Search::Xapian DBD::SQLite));
9 my ($tmpdir, $for_destroy) = tmpdir();
10 my $inboxdir = "$tmpdir/v2";
11 my $maildir = "$tmpdir/md";
12 use_ok 'PublicInbox::WatchMaildir';
13 use_ok 'PublicInbox::Emergency';
14 my $cfgpfx = "publicinbox.test";
15 my $addr = 'test-public@example.com';
16 my @cmd = ('-init', '-V2', 'test', $inboxdir,
17 'http://example.com/list', $addr);
18 local $ENV{PI_CONFIG} = "$tmpdir/pi_config";
19 ok(run_script(\@cmd), 'public-inbox init OK');
24 Subject: address is in to
25 Message-Id: <to\@a.com>
26 Date: Sat, 18 Apr 2020 00:00:00 +0000
35 Subject: address is in cc
36 Message-Id: <cc\@a.com>
37 Date: Sat, 18 Apr 2020 00:01:00 +0000
46 Subject: address is not in to or cc
47 Message-Id: <none\@a.com>
48 Date: Sat, 18 Apr 2020 00:02:00 +0000
53 PublicInbox::Emergency->new($maildir)->prepare(\$msg_to);
54 PublicInbox::Emergency->new($maildir)->prepare(\$msg_cc);
55 PublicInbox::Emergency->new($maildir)->prepare(\$msg_none);
59 $cfgpfx.inboxdir=$inboxdir
60 $cfgpfx.watch=maildir:$maildir
61 $cfgpfx.watchheader=To:$addr
62 $cfgpfx.watchheader=Cc:$addr
64 my $config = PublicInbox::Config->new(\$cfg);
65 PublicInbox::WatchMaildir->new($config)->scan('full');
66 my $ibx = $config->lookup_name('test');
67 ok($ibx, 'found inbox by name');
69 my $num = $ibx->mm->num_for('to@a.com');
70 ok(defined $num, 'Matched for address in To:');
71 $num = $ibx->mm->num_for('cc@a.com');
72 ok(defined $num, 'Matched for address in Cc:');
73 $num = $ibx->mm->num_for('none@a.com');
74 is($num, undef, 'No match without address in To: or Cc:');