]> Sergey Matveev's repositories - public-inbox.git/blob - t/filter_base.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / filter_base.t
1 # Copyright (C) 2016-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::MIME;
7 use_ok 'PublicInbox::Filter::Base';
8
9 {
10         my $f = PublicInbox::Filter::Base->new;
11         ok($f, 'created stock object');
12         ok(defined $f->{reject_suffix}, 'rejected suffix redefined');
13         is(ref($f->{reject_suffix}), 'Regexp', 'reject_suffix should be a RE');
14 }
15
16 {
17         my $f = PublicInbox::Filter::Base->new(reject_suffix => undef);
18         ok($f, 'created base object q/o reject_suffix');
19         ok(!defined $f->{reject_suffix}, 'reject_suffix not defined');
20 }
21
22 {
23         my $f = PublicInbox::Filter::Base->new;
24         my $html_body = "<html><body>hi</body></html>";
25         my $parts = [
26                 Email::MIME->create(
27                         attributes => {
28                                 content_type => 'text/xhtml; charset=UTF-8',
29                                 encoding => 'base64',
30                         },
31                         body => $html_body,
32                 ),
33                 Email::MIME->create(
34                         attributes => {
35                                 content_type => 'text/plain',
36                                 encoding => 'quoted-printable',
37                         },
38                         body => 'hi = "bye"',
39                 )
40         ];
41         my $email = Email::MIME->create(
42                 header_str => [
43                   From => 'a@example.com',
44                   Subject => 'blah',
45                   'Content-Type' => 'multipart/alternative'
46                 ],
47                 parts => $parts,
48         );
49         is($f->delivery($email), 100, "xhtml rejected");
50 }
51
52 {
53         my $f = PublicInbox::Filter::Base->new;
54         my $parts = [
55                 Email::MIME->create(
56                         attributes => {
57                                 content_type => 'application/vnd.ms-excel',
58                                 encoding => 'base64',
59                         },
60                         body => 'junk',
61                 ),
62                 Email::MIME->create(
63                         attributes => {
64                                 content_type => 'text/plain',
65                                 encoding => 'quoted-printable',
66                         },
67                         body => 'junk',
68                 )
69         ];
70         my $email = Email::MIME->create(
71                 header_str => [
72                   From => 'a@example.com',
73                   Subject => 'blah',
74                   'Content-Type' => 'multipart/mixed'
75                 ],
76                 parts => $parts,
77         );
78         is($f->delivery($email), 100, 'proprietary format rejected on glob');
79 }
80
81 done_testing();