]> Sergey Matveev's repositories - public-inbox.git/blob - t/watch_multiple_headers.t
No ext_urls
[public-inbox.git] / t / watch_multiple_headers.t
1 # Copyright (C) 2020-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 Test::More;
5 use PublicInbox::Config;
6 use PublicInbox::TestCommon;
7 require_git(2.6);
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::Watch';
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');
20
21 my $msg_to = <<EOF;
22 From: user\@a.com
23 To: $addr
24 Subject: address is in to
25 Message-Id: <to\@a.com>
26 Date: Sat, 18 Apr 2020 00:00:00 +0000
27
28 content1
29 EOF
30
31 my $msg_cc = <<EOF;
32 From: user1\@a.com
33 To: user2\@a.com
34 Cc: $addr
35 Subject: address is in cc
36 Message-Id: <cc\@a.com>
37 Date: Sat, 18 Apr 2020 00:01:00 +0000
38
39 content2
40 EOF
41
42 my $msg_none = <<EOF;
43 From: user1\@a.com
44 To: user2\@a.com
45 Cc: user3\@a.com
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
49
50 content3
51 EOF
52
53 PublicInbox::Emergency->new($maildir)->prepare(\$msg_to);
54 PublicInbox::Emergency->new($maildir)->prepare(\$msg_cc);
55 PublicInbox::Emergency->new($maildir)->prepare(\$msg_none);
56
57 my $raw = <<EOF;
58 $cfgpfx.address=$addr
59 $cfgpfx.inboxdir=$inboxdir
60 $cfgpfx.watch=maildir:$maildir
61 $cfgpfx.watchheader=To:$addr
62 $cfgpfx.watchheader=Cc:$addr
63 EOF
64 my $cfg = PublicInbox::Config->new(\$raw);
65 PublicInbox::Watch->new($cfg)->scan('full');
66 my $ibx = $cfg->lookup_name('test');
67 ok($ibx, 'found inbox by name');
68
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:');
75
76 done_testing;