]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
update copyright headers and email addresses
[public-inbox.git] / t / precheck.t
1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
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::MDA;
9
10 sub do_checks {
11         my ($s) = @_;
12
13         my $f = Email::Filter->new(data => $s->as_string);
14
15         my $recipient = 'foo@example.com';
16         ok(!PublicInbox::MDA->precheck($f, $recipient),
17                 "wrong ORIGINAL_RECIPIENT rejected");
18
19         $recipient = 'b@example.com';
20         ok(PublicInbox::MDA->precheck($f, $recipient),
21                 "ORIGINAL_RECIPIENT in To: is OK");
22
23         $recipient = 'c@example.com';
24         ok(PublicInbox::MDA->precheck($f, $recipient),
25                 "ORIGINAL_RECIPIENT in Cc: is OK");
26
27         $recipient = [ 'c@example.com', 'd@example.com' ];
28         ok(PublicInbox::MDA->precheck($f, $recipient),
29                 "alias list is OK");
30 }
31
32 {
33         do_checks(Email::Simple->create(
34                 header => [
35                         From => 'a@example.com',
36                         To => 'b@example.com',
37                         Cc => 'c@example.com',
38                         'Content-Type' => 'text/plain',
39                         Subject => 'this is a subject',
40                         'Message-ID' => '<MID@host>',
41                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
42                 ],
43                 body => "hello world\n",
44         ));
45 }
46
47 {
48         do_checks(Email::Simple->create(
49                 header => [
50                         From => 'a@example.com',
51                         To => 'b+plus@example.com',
52                         Cc => 'John Doe <c@example.com>',
53                         'Content-Type' => 'text/plain',
54                         Subject => 'this is a subject',
55                         'Message-ID' => '<MID@host>',
56                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
57                 ],
58                 body => "hello world\n",
59         ));
60 }
61
62 {
63         my $recipient = 'b@example.com';
64         my $s = Email::Simple->create(
65                 header => [
66                         To => 'b@example.com',
67                         Cc => 'c@example.com',
68                         'Content-Type' => 'text/plain',
69                         Subject => 'this is a subject',
70                         'Message-ID' => '<MID@host>',
71                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
72                 ],
73                 body => "hello world\n",
74         );
75         my $f = Email::Filter->new(data => $s->as_string);
76         ok(!PublicInbox::MDA->precheck($f, $recipient),
77                 "missing From: is rejected");
78 }
79
80 done_testing();