Filename | /usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/WhiteListSubject.pm |
Statements | Executed 28 statements in 1.78ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 69µs | 422µs | new | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 64µs | 251µs | set_config | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 47µs | 47µs | BEGIN@46 | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 35µs | 131µs | BEGIN@52 | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 32µs | 106µs | BEGIN@50 | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 30µs | 36µs | BEGIN@49 | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 26µs | 34µs | BEGIN@47 | Mail::SpamAssassin::Plugin::WhiteListSubject::
1 | 1 | 1 | 21µs | 49µs | BEGIN@48 | Mail::SpamAssassin::Plugin::WhiteListSubject::
0 | 0 | 0 | 0s | 0s | __ANON__[:107] | Mail::SpamAssassin::Plugin::WhiteListSubject::
0 | 0 | 0 | 0s | 0s | __ANON__[:91] | Mail::SpamAssassin::Plugin::WhiteListSubject::
0 | 0 | 0 | 0s | 0s | _check_subject | Mail::SpamAssassin::Plugin::WhiteListSubject::
0 | 0 | 0 | 0s | 0s | check_subject_in_blacklist | Mail::SpamAssassin::Plugin::WhiteListSubject::
0 | 0 | 0 | 0s | 0s | check_subject_in_whitelist | Mail::SpamAssassin::Plugin::WhiteListSubject::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # <@LICENSE> | ||||
2 | # Licensed to the Apache Software Foundation (ASF) under one or more | ||||
3 | # contributor license agreements. See the NOTICE file distributed with | ||||
4 | # this work for additional information regarding copyright ownership. | ||||
5 | # The ASF licenses this file to you under the Apache License, Version 2.0 | ||||
6 | # (the "License"); you may not use this file except in compliance with | ||||
7 | # the License. You may obtain a copy of the License at: | ||||
8 | # | ||||
9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||
10 | # | ||||
11 | # Unless required by applicable law or agreed to in writing, software | ||||
12 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
14 | # See the License for the specific language governing permissions and | ||||
15 | # limitations under the License. | ||||
16 | # </@LICENSE> | ||||
17 | |||||
18 | =head1 NAME | ||||
19 | |||||
20 | Mail::SpamAssassin::Plugin::WhiteListSubject - whitelist by Subject header | ||||
21 | |||||
22 | =head1 SYNOPSIS | ||||
23 | |||||
24 | loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject | ||||
25 | |||||
26 | header SUBJECT_IN_WHITELIST eval:check_subject_in_whitelist() | ||||
27 | header SUBJECT_IN_BLACKLIST eval:check_subject_in_blacklist() | ||||
28 | |||||
29 | score SUBJECT_IN_WHITELIST -100 | ||||
30 | score SUBJECT_IN_BLACKLIST 100 | ||||
31 | |||||
32 | whitelist_subject [Bug *] | ||||
33 | blacklist_subject Make Money Fast | ||||
34 | |||||
35 | =head1 DESCRIPTION | ||||
36 | |||||
37 | This SpamAssassin plugin module provides eval tests for whitelisting and blacklisting | ||||
38 | particular strings in the Subject header. The value for whitelist_subject or | ||||
39 | blacklist_subject are strings which may contain file -glob -style patterns, | ||||
40 | similar to the other whitelist_* config options. | ||||
41 | |||||
42 | =cut | ||||
43 | |||||
44 | package Mail::SpamAssassin::Plugin::WhiteListSubject; | ||||
45 | |||||
46 | 2 | 80µs | 1 | 47µs | # spent 47µs within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@46 which was called:
# once (47µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 46 # spent 47µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@46 |
47 | 2 | 70µs | 2 | 43µs | # spent 34µs (26+8) within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@47 which was called:
# once (26µs+8µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 47 # spent 34µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@47
# spent 8µs making 1 call to strict::import |
48 | 2 | 61µs | 2 | 76µs | # spent 49µs (21+28) within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@48 which was called:
# once (21µs+28µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 48 # spent 49µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@48
# spent 28µs making 1 call to warnings::import |
49 | 2 | 58µs | 2 | 40µs | # spent 36µs (30+5) within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@49 which was called:
# once (30µs+5µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 49 # spent 36µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@49
# spent 5µs making 1 call to bytes::import |
50 | 2 | 77µs | 2 | 179µs | # spent 106µs (32+73) within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@50 which was called:
# once (32µs+73µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 50 # spent 106µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@50
# spent 73µs making 1 call to re::import |
51 | |||||
52 | 2 | 1.29ms | 2 | 227µs | # spent 131µs (35+96) within Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@52 which was called:
# once (35µs+96µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 52 # spent 131µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::BEGIN@52
# spent 96µs making 1 call to vars::import |
53 | 1 | 12µs | @ISA = qw(Mail::SpamAssassin::Plugin); | ||
54 | |||||
55 | # constructor: register the eval rule | ||||
56 | # spent 422µs (69+353) within Mail::SpamAssassin::Plugin::WhiteListSubject::new which was called:
# once (69µs+353µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 1 of (eval 75)[Mail/SpamAssassin/PluginHandler.pm:129] | ||||
57 | 1 | 2µs | my $class = shift; | ||
58 | 1 | 2µs | my $mailsaobject = shift; | ||
59 | |||||
60 | 1 | 2µs | $class = ref($class) || $class; | ||
61 | 1 | 20µs | 1 | 38µs | my $self = $class->SUPER::new($mailsaobject); # spent 38µs making 1 call to Mail::SpamAssassin::Plugin::new |
62 | 1 | 2µs | bless ($self, $class); | ||
63 | |||||
64 | 1 | 10µs | 1 | 38µs | $self->register_eval_rule ("check_subject_in_whitelist"); # spent 38µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
65 | 1 | 6µs | 1 | 26µs | $self->register_eval_rule ("check_subject_in_blacklist"); # spent 26µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
66 | |||||
67 | 1 | 15µs | 1 | 251µs | $self->set_config($mailsaobject->{conf}); # spent 251µs making 1 call to Mail::SpamAssassin::Plugin::WhiteListSubject::set_config |
68 | |||||
69 | 1 | 21µs | return $self; | ||
70 | } | ||||
71 | |||||
72 | # spent 251µs (64+188) within Mail::SpamAssassin::Plugin::WhiteListSubject::set_config which was called:
# once (64µs+188µs) by Mail::SpamAssassin::Plugin::WhiteListSubject::new at line 67 | ||||
73 | 1 | 2µs | my ($self, $conf) = @_; | ||
74 | |||||
75 | 1 | 2µs | my @cmds; | ||
76 | |||||
77 | push(@cmds, { | ||||
78 | setting => 'whitelist_subject', | ||||
79 | default => {}, | ||||
80 | type => $Mail::SpamAssassin::Conf::CONF_TYPE_ADDRLIST, | ||||
81 | code => sub { | ||||
82 | my ($self, $key, $value, $line) = @_; | ||||
83 | |||||
84 | $value = lc $value; | ||||
85 | my $re = $value; | ||||
86 | $re =~ s/[\000\\\(]/_/gs; # paranoia | ||||
87 | $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g; # escape any possible metachars | ||||
88 | $re =~ tr/?/./; # "?" -> "." | ||||
89 | $re =~ s/\*+/\.\*/g; # "*" -> "any string" | ||||
90 | $conf->{$key}->{$value} = ${re}; | ||||
91 | 1 | 18µs | }}); | ||
92 | |||||
93 | push(@cmds, { | ||||
94 | setting => 'blacklist_subject', | ||||
95 | default => {}, | ||||
96 | type => $Mail::SpamAssassin::Conf::CONF_TYPE_ADDRLIST, | ||||
97 | code => sub { | ||||
98 | my ($self, $key, $value, $line) = @_; | ||||
99 | |||||
100 | $value = lc $value; | ||||
101 | my $re = $value; | ||||
102 | $re =~ s/[\000\\\(]/_/gs; # paranoia | ||||
103 | $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g; # escape any possible metachars | ||||
104 | $re =~ tr/?/./; # "?" -> "." | ||||
105 | $re =~ s/\*+/\.\*/g; # "*" -> "any string" | ||||
106 | $conf->{$key}->{$value} = ${re}; | ||||
107 | 1 | 10µs | }}); | ||
108 | |||||
109 | 1 | 15µs | 1 | 188µs | $conf->{parser}->register_commands(\@cmds); # spent 188µs making 1 call to Mail::SpamAssassin::Conf::Parser::register_commands |
110 | } | ||||
111 | |||||
112 | sub check_subject_in_whitelist { | ||||
113 | my ($self, $permsgstatus) = @_; | ||||
114 | |||||
115 | my $subject = $permsgstatus->get('Subject'); | ||||
116 | |||||
117 | return 0 unless $subject ne ''; | ||||
118 | |||||
119 | return $self->_check_subject($permsgstatus->{conf}->{whitelist_subject}, $subject); | ||||
120 | } | ||||
121 | |||||
122 | sub check_subject_in_blacklist { | ||||
123 | my ($self, $permsgstatus) = @_; | ||||
124 | |||||
125 | my $subject = $permsgstatus->get('Subject'); | ||||
126 | |||||
127 | return 0 unless $subject ne ''; | ||||
128 | |||||
129 | return $self->_check_subject($permsgstatus->{conf}->{blacklist_subject}, $subject); | ||||
130 | } | ||||
131 | |||||
132 | sub _check_subject { | ||||
133 | my ($self, $list, $subject) = @_; | ||||
134 | |||||
135 | $subject = lc $subject; | ||||
136 | |||||
137 | return 1 if defined($list->{$subject}); | ||||
138 | |||||
139 | study $subject; # study is a no-op since perl 5.16.0, eliminating bugs | ||||
140 | foreach my $regexp (values %{$list}) { | ||||
141 | if ($subject =~ qr/$regexp/i) { | ||||
142 | return 1; | ||||
143 | } | ||||
144 | } | ||||
145 | |||||
146 | return 0; | ||||
147 | } | ||||
148 | |||||
149 | 1 | 8µs | 1; |