]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
doc: design_www: document solver endpoint
[public-inbox.git] / t / precheck.t
1 # Copyright (C) 2014-2020 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 warnings;
5 use Test::More;
6 use Email::Simple;
7 use PublicInbox::MDA;
8
9 sub do_checks {
10         my ($s) = @_;
11
12         my $recipient = 'foo@example.com';
13         ok(!PublicInbox::MDA->precheck($s, $recipient),
14                 "wrong ORIGINAL_RECIPIENT rejected");
15
16         $recipient = 'b@example.com';
17         ok(PublicInbox::MDA->precheck($s, $recipient),
18                 "ORIGINAL_RECIPIENT in To: is OK");
19
20         $recipient = 'c@example.com';
21         ok(PublicInbox::MDA->precheck($s, $recipient),
22                 "ORIGINAL_RECIPIENT in Cc: is OK");
23
24         $recipient = [ 'c@example.com', 'd@example.com' ];
25         ok(PublicInbox::MDA->precheck($s, $recipient),
26                 "alias list is OK");
27 }
28
29 {
30         my $s = Email::Simple->create(
31                 header => [
32                         From => 'abc@example.com',
33                         To => 'abc@example.com',
34                         Cc => 'c@example.com, another-list@example.com',
35                         'Content-Type' => 'text/plain',
36                         Subject => 'list is fine',
37                         'Message-ID' => '<MID@host>',
38                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
39                 ],
40                 body => "hello world\n",
41         );
42         my $addr = [ 'c@example.com', 'd@example.com' ];
43         ok(PublicInbox::MDA->precheck($s, $addr), 'Cc list is OK');
44 }
45
46 {
47         do_checks(Email::Simple->create(
48                 header => [
49                         From => 'a@example.com',
50                         To => 'b@example.com',
51                         Cc => 'c@example.com',
52                         'Content-Type' => 'text/plain',
53                         Subject => 'this is a subject',
54                         'Message-ID' => '<MID@host>',
55                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
56                 ],
57                 body => "hello world\n",
58         ));
59 }
60
61 {
62         do_checks(Email::Simple->create(
63                 header => [
64                         From => 'a@example.com',
65                         To => 'b+plus@example.com',
66                         Cc => 'John Doe <c@example.com>',
67                         'Content-Type' => 'text/plain',
68                         Subject => 'this is a subject',
69                         'Message-ID' => '<MID@host>',
70                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
71                 ],
72                 body => "hello world\n",
73         ));
74 }
75
76 {
77         my $recipient = 'b@example.com';
78         my $s = Email::Simple->create(
79                 header => [
80                         To => 'b@example.com',
81                         Cc => 'c@example.com',
82                         'Content-Type' => 'text/plain',
83                         Subject => 'this is a subject',
84                         'Message-ID' => '<MID@host>',
85                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
86                 ],
87                 body => "hello world\n",
88         );
89         ok(!PublicInbox::MDA->precheck($s, $recipient),
90                 "missing From: is rejected");
91 }
92
93 done_testing();