]> Sergey Matveev's repositories - public-inbox.git/blob - t/recipient.t
reject messages if ORIGINAL_RECIPIENT is not specified
[public-inbox.git] / t / recipient.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         local %ENV;
15         delete $ENV{ORIGINAL_RECIPIENT};
16
17         ok(PublicInbox->recipient_specified($f),
18                 "ORIGINAL_RECIPIENT unset is OK");
19
20         $ENV{ORIGINAL_RECIPIENT} = 'foo@example.com';
21         ok(!PublicInbox->recipient_specified($f),
22                 "wrong ORIGINAL_RECIPIENT rejected");
23
24         $ENV{ORIGINAL_RECIPIENT} = 'b@example.com';
25         ok(PublicInbox->recipient_specified($f),
26                 "ORIGINAL_RECIPIENT in To: is OK");
27
28         $ENV{ORIGINAL_RECIPIENT} = 'c@example.com';
29         ok(PublicInbox->recipient_specified($f),
30                 "ORIGINAL_RECIPIENT in Cc: is OK");
31 }
32
33 {
34         do_checks(Email::Simple->create(
35                 header => [
36                         From => 'a@example.com',
37                         To => 'b@example.com',
38                         Cc => 'c@example.com',
39                         'Content-Type' => 'text/plain',
40                         Subject => 'this is a subject',
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                 ],
55                 body => "hello world\n",
56         ));
57 }
58
59 done_testing();