lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / watch_multiple_headers.t
blob9585da2be13ced826e142bfbdfd6baa9d97d7759
1 # Copyright (C)  all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use v5.12;
4 use PublicInbox::TestCommon;
5 require_git(2.6);
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');
19 my $msg_to = <<EOF;
20 From: user\@a.com
21 To: $addr
22 Subject: address is in to
23 Message-Id: <to\@a.com>
24 Date: Sat, 18 Apr 2020 00:00:00 +0000
26 content1
27 EOF
29 my $msg_cc = <<EOF;
30 From: user1\@a.com
31 To: user2\@a.com
32 Cc: $addr
33 Subject: address is in cc
34 Message-Id: <cc\@a.com>
35 Date: Sat, 18 Apr 2020 00:01:00 +0000
37 content2
38 EOF
40 my $msg_none = <<EOF;
41 From: user1\@a.com
42 To: user2\@a.com
43 Cc: user3\@a.com
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
48 content3
49 EOF
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;
56 [publicinbox "test"]
57         address = $addr
58         inboxdir = $inboxdir
59         watch = maildir:$maildir
60         watchheader = To:$addr
61         watchheader = Cc:$addr
62 EOF
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:');
75 done_testing;