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