]> Sergey Matveev's repositories - public-inbox.git/blob - t/filter_base.t
7919dd65098e0309662a2f7b7fec70bc9035376f
[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 PublicInbox::TestCommon;
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 $email = mime_load 't/filter_base-xhtml.eml', sub {
25         my $html_body = "<html><body>hi</body></html>";
26         my $parts = [
27                 Email::MIME->create(
28                         attributes => {
29                                 content_type => 'text/xhtml; charset=UTF-8',
30                                 encoding => 'base64',
31                         },
32                         body => $html_body,
33                 ),
34                 Email::MIME->create(
35                         attributes => {
36                                 content_type => 'text/plain',
37                                 encoding => 'quoted-printable',
38                         },
39                         body => 'hi = "bye"',
40                 )
41         ];
42         Email::MIME->create(
43                 header_str => [
44                   From => 'a@example.com',
45                   Subject => 'blah',
46                   'Content-Type' => 'multipart/alternative'
47                 ],
48                 parts => $parts,
49         )}; # mime_load sub
50         is($f->delivery($email), 100, "xhtml rejected");
51 }
52
53 {
54         my $f = PublicInbox::Filter::Base->new;
55         my $email = mime_load 't/filter_base-junk.eml', sub {
56         my $parts = [
57                 Email::MIME->create(
58                         attributes => {
59                                 content_type => 'application/vnd.ms-excel',
60                                 encoding => 'base64',
61                         },
62                         body => 'junk',
63                 ),
64                 Email::MIME->create(
65                         attributes => {
66                                 content_type => 'text/plain',
67                                 encoding => 'quoted-printable',
68                         },
69                         body => 'junk',
70                 )
71         ];
72         Email::MIME->create(
73                 header_str => [
74                   From => 'a@example.com',
75                   Subject => 'blah',
76                   'Content-Type' => 'multipart/mixed'
77                 ],
78                 parts => $parts,
79         )}; # mime_load sub
80         is($f->delivery($email), 100, 'proprietary format rejected on glob');
81 }
82
83 done_testing();