]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
various documentation updates
[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@host>',
40                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
41                 ],
42                 body => "hello world\n",
43         ));
44 }
45
46 {
47         do_checks(Email::Simple->create(
48                 header => [
49                         From => 'a@example.com',
50                         To => 'b+plus@example.com',
51                         Cc => 'John Doe <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         my $recipient = 'b@example.com';
63         my $s = Email::Simple->create(
64                 header => [
65                         To => 'b@example.com',
66                         Cc => '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         my $f = Email::Filter->new(data => $s->as_string);
75         ok(!PublicInbox->precheck($f, $recipient), "missing From: is rejected");
76 }
77
78 done_testing();