]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / precheck.t
1 # Copyright (C) 2014-2021 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 PublicInbox::Eml;
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 = PublicInbox::Eml->new(<<'EOF');
31 From: abc@example.com
32 To: abc@example.com
33 Cc: c@example.com, another-list@example.com
34 Content-Type: text/plain
35 Subject: list is fine
36 Message-ID: <MID@host>
37 Date: Wed, 09 Apr 2014 01:28:34 +0000
38
39 hello world
40 EOF
41         my $addr = [ 'c@example.com', 'd@example.com' ];
42         ok(PublicInbox::MDA->precheck($s, $addr), 'Cc list is OK');
43 }
44
45 {
46         do_checks(PublicInbox::Eml->new(<<'EOF'));
47 From: a@example.com
48 To: b@example.com
49 Cc: c@example.com
50 Content-Type: text/plain
51 Subject: this is a subject
52 Message-ID: <MID@host>
53 Date: Wed, 09 Apr 2014 01:28:34 +0000
54
55 hello world
56 EOF
57 }
58
59 {
60         do_checks(PublicInbox::Eml->new(<<'EOF'));
61 From: a@example.com
62 To: b+plus@example.com
63 Cc: John Doe <c@example.com>
64 Content-Type: text/plain
65 Subject: this is a subject
66 Message-ID: <MID@host>
67 Date: Wed, 09 Apr 2014 01:28:34 +0000
68
69 hello world
70 EOF
71 }
72
73 {
74         my $recipient = 'b@example.com';
75         my $s = PublicInbox::Eml->new(<<'EOF');
76 To: b@example.com
77 Cc: c@example.com
78 Content-Type: text/plain
79 Subject: this is a subject
80 Message-ID: <MID@host>
81 Date: Wed, 09 Apr 2014 01:28:34 +0000
82
83 hello world
84 EOF
85         ok(!PublicInbox::MDA->precheck($s, $recipient),
86                 "missing From: is rejected");
87 }
88
89 done_testing();