]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
precheck uses recipient argument
[public-inbox.git] / t / precheck.t
1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::Simple;
7 use Email::Filter;
8 use PublicInbox;
9
10 sub do_checks {
11         my ($s) = @_;
12
13         my $f = Email::Filter->new(data => $s->as_string);
14
15         ok(PublicInbox->precheck($f, undef),
16                 "RECIPIENT unset is OK");
17
18         my $recipient = 'foo@example.com';
19         ok(!PublicInbox->precheck($f, $recipient),
20                 "wrong RECIPIENT rejected");
21
22         $recipient = 'b@example.com';
23         ok(PublicInbox->precheck($f, $recipient),
24                 "RECIPIENT in To: is OK");
25
26         $recipient = 'c@example.com';
27         ok(PublicInbox->precheck($f, $recipient),
28                 "RECIPIENT in Cc: is OK");
29 }
30
31 {
32         do_checks(Email::Simple->create(
33                 header => [
34                         From => 'a@example.com',
35                         To => 'b@example.com',
36                         Cc => 'c@example.com',
37                         'Content-Type' => 'text/plain',
38                         Subject => 'this is a subject',
39                         'Message-ID' => '<MID>',
40                 ],
41                 body => "hello world\n",
42         ));
43 }
44
45 {
46         do_checks(Email::Simple->create(
47                 header => [
48                         From => 'a@example.com',
49                         To => 'b+plus@example.com',
50                         Cc => 'John Doe <c@example.com>',
51                         'Content-Type' => 'text/plain',
52                         Subject => 'this is a subject',
53                         'Message-ID' => '<MID>',
54                 ],
55                 body => "hello world\n",
56         ));
57 }
58
59 {
60         my $recipient = 'b@example.com';
61         my $s = Email::Simple->create(
62                 header => [
63                         To => 'b@example.com',
64                         Cc => 'c@example.com',
65                         'Content-Type' => 'text/plain',
66                         Subject => 'this is a subject',
67                         'Message-ID' => '<MID>',
68                 ],
69                 body => "hello world\n",
70         );
71         my $f = Email::Filter->new(data => $s->as_string);
72         ok(!PublicInbox->precheck($f, $recipient), "missing From: is rejected");
73 }
74
75 done_testing();