Filename | /usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/HTMLEval.pm |
Statements | Executed 36 statements in 2.80ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.19ms | 1.48ms | BEGIN@26 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 161µs | 436µs | new | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 44µs | 54µs | BEGIN@20 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 25µs | 140µs | BEGIN@27 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 21µs | 48µs | BEGIN@21 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 21µs | 77µs | BEGIN@23 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 20µs | 29µs | BEGIN@22 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 20µs | 76µs | BEGIN@29 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 13µs | 13µs | BEGIN@25 | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | check_iframe_src | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_charset_faraway | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_eval | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_image_only | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_image_ratio | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_range | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_tag_balance | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_tag_exists | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_test | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_text_match | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_text_not_match | Mail::SpamAssassin::Plugin::HTMLEval::
0 | 0 | 0 | 0s | 0s | html_title_subject_ratio | Mail::SpamAssassin::Plugin::HTMLEval::
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 | package Mail::SpamAssassin::Plugin::HTMLEval; | ||||
19 | |||||
20 | 2 | 60µs | 2 | 64µs | # spent 54µs (44+10) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20 which was called:
# once (44µs+10µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 20 # spent 54µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20
# spent 10µs making 1 call to strict::import |
21 | 2 | 59µs | 2 | 75µs | # spent 48µs (21+27) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21 which was called:
# once (21µs+27µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 21 # spent 48µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21
# spent 27µs making 1 call to warnings::import |
22 | 2 | 58µs | 2 | 38µs | # spent 29µs (20+9) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22 which was called:
# once (20µs+9µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 22 # spent 29µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22
# spent 9µs making 1 call to bytes::import |
23 | 2 | 59µs | 2 | 133µs | # spent 77µs (21+56) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23 which was called:
# once (21µs+56µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 23 # spent 77µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23
# spent 56µs making 1 call to re::import |
24 | |||||
25 | 2 | 58µs | 1 | 13µs | # spent 13µs within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25 which was called:
# once (13µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 25 # spent 13µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25 |
26 | 2 | 320µs | 1 | 1.48ms | # spent 1.48ms (1.19+288µs) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26 which was called:
# once (1.19ms+288µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 26 # spent 1.48ms making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26 |
27 | 2 | 63µs | 2 | 255µs | # spent 140µs (25+115) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27 which was called:
# once (25µs+115µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 27 # spent 140µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27
# spent 115µs making 1 call to Exporter::import |
28 | |||||
29 | 2 | 2.00ms | 2 | 133µs | # spent 76µs (20+56) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29 which was called:
# once (20µs+56µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 29 # spent 76µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29
# spent 56µs making 1 call to vars::import |
30 | 1 | 14µs | @ISA = qw(Mail::SpamAssassin::Plugin); | ||
31 | |||||
32 | # constructor: register the eval rule | ||||
33 | # spent 436µs (161+275) within Mail::SpamAssassin::Plugin::HTMLEval::new which was called:
# once (161µs+275µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 1 of (eval 95)[Mail/SpamAssassin/PluginHandler.pm:129] | ||||
34 | 1 | 2µs | my $class = shift; | ||
35 | 1 | 2µs | my $mailsaobject = shift; | ||
36 | |||||
37 | # some boilerplate... | ||||
38 | 1 | 2µs | $class = ref($class) || $class; | ||
39 | 1 | 14µs | 1 | 20µs | my $self = $class->SUPER::new($mailsaobject); # spent 20µs making 1 call to Mail::SpamAssassin::Plugin::new |
40 | 1 | 2µs | bless ($self, $class); | ||
41 | |||||
42 | # the important bit! | ||||
43 | 1 | 10µs | 1 | 32µs | $self->register_eval_rule("html_tag_balance"); # spent 32µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
44 | 1 | 6µs | 1 | 20µs | $self->register_eval_rule("html_image_only"); # spent 20µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
45 | 1 | 6µs | 1 | 18µs | $self->register_eval_rule("html_image_ratio"); # spent 18µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
46 | 1 | 6µs | 1 | 19µs | $self->register_eval_rule("html_charset_faraway"); # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
47 | 1 | 6µs | 1 | 19µs | $self->register_eval_rule("html_tag_exists"); # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
48 | 1 | 6µs | 1 | 18µs | $self->register_eval_rule("html_test"); # spent 18µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
49 | 1 | 7µs | 1 | 18µs | $self->register_eval_rule("html_eval"); # spent 18µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
50 | 1 | 6µs | 1 | 18µs | $self->register_eval_rule("html_text_match"); # spent 18µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
51 | 1 | 6µs | 1 | 19µs | $self->register_eval_rule("html_title_subject_ratio"); # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
52 | 1 | 6µs | 1 | 19µs | $self->register_eval_rule("html_text_not_match"); # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
53 | 1 | 6µs | 1 | 37µs | $self->register_eval_rule("html_range"); # spent 37µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
54 | 1 | 6µs | 1 | 19µs | $self->register_eval_rule("check_iframe_src"); # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
55 | |||||
56 | 1 | 10µs | return $self; | ||
57 | } | ||||
58 | |||||
59 | sub html_tag_balance { | ||||
60 | my ($self, $pms, undef, $rawtag, $rawexpr) = @_; | ||||
61 | $rawtag =~ /^([a-zA-Z0-9]+)$/; my $tag = $1; | ||||
62 | $rawexpr =~ /^([\<\>\=\!\-\+ 0-9]+)$/; my $expr = $1; | ||||
63 | |||||
64 | return 0 unless exists $pms->{html}{inside}{$tag}; | ||||
65 | |||||
66 | $pms->{html}{inside}{$tag} =~ /^([\<\>\=\!\-\+ 0-9]+)$/; | ||||
67 | my $val = $1; | ||||
68 | return eval "\$val $expr"; | ||||
69 | } | ||||
70 | |||||
71 | sub html_image_only { | ||||
72 | my ($self, $pms, undef, $min, $max) = @_; | ||||
73 | |||||
74 | return (exists $pms->{html}{inside}{img} && | ||||
75 | exists $pms->{html}{length} && | ||||
76 | $pms->{html}{length} > $min && | ||||
77 | $pms->{html}{length} <= $max); | ||||
78 | } | ||||
79 | |||||
80 | sub html_image_ratio { | ||||
81 | my ($self, $pms, undef, $min, $max) = @_; | ||||
82 | |||||
83 | return 0 unless (exists $pms->{html}{non_space_len} && | ||||
84 | exists $pms->{html}{image_area} && | ||||
85 | $pms->{html}{image_area} > 0); | ||||
86 | my $ratio = $pms->{html}{non_space_len} / $pms->{html}{image_area}; | ||||
87 | return ($ratio > $min && $ratio <= $max); | ||||
88 | } | ||||
89 | |||||
90 | sub html_charset_faraway { | ||||
91 | my ($self, $pms) = @_; | ||||
92 | |||||
93 | return 0 unless exists $pms->{html}{charsets}; | ||||
94 | |||||
95 | my @locales = Mail::SpamAssassin::Util::get_my_locales($pms->{conf}->{ok_locales}); | ||||
96 | return 0 if grep { $_ eq "all" } @locales; | ||||
97 | |||||
98 | my $okay = 0; | ||||
99 | my $bad = 0; | ||||
100 | for my $c (split(' ', $pms->{html}{charsets})) { | ||||
101 | if (Mail::SpamAssassin::Locales::is_charset_ok_for_locales($c, @locales)) { | ||||
102 | $okay++; | ||||
103 | } | ||||
104 | else { | ||||
105 | $bad++; | ||||
106 | } | ||||
107 | } | ||||
108 | return ($bad && ($bad >= $okay)); | ||||
109 | } | ||||
110 | |||||
111 | sub html_tag_exists { | ||||
112 | my ($self, $pms, undef, $tag) = @_; | ||||
113 | return exists $pms->{html}{inside}{$tag}; | ||||
114 | } | ||||
115 | |||||
116 | sub html_test { | ||||
117 | my ($self, $pms, undef, $test) = @_; | ||||
118 | return $pms->{html}{$test}; | ||||
119 | } | ||||
120 | |||||
121 | sub html_eval { | ||||
122 | my ($self, $pms, undef, $test, $rawexpr) = @_; | ||||
123 | my $expr; | ||||
124 | if ($rawexpr =~ /^[\<\>\=\!\-\+ 0-9]+$/) { | ||||
125 | $expr = untaint_var($rawexpr); | ||||
126 | } | ||||
127 | # workaround bug 3320: wierd perl bug where additional, very explicit | ||||
128 | # untainting into a new var is required. | ||||
129 | my $tainted = $pms->{html}{$test}; | ||||
130 | return unless defined($tainted); | ||||
131 | my $val = $tainted; | ||||
132 | |||||
133 | # just use the value in $val, don't copy it needlessly | ||||
134 | return eval "\$val $expr"; | ||||
135 | } | ||||
136 | |||||
137 | sub html_text_match { | ||||
138 | my ($self, $pms, undef, $text, $regexp) = @_; | ||||
139 | for my $string (@{ $pms->{html}{$text} }) { | ||||
140 | if (defined $string && $string =~ /${regexp}/) { | ||||
141 | return 1; | ||||
142 | } | ||||
143 | } | ||||
144 | return 0; | ||||
145 | } | ||||
146 | |||||
147 | sub html_title_subject_ratio { | ||||
148 | my ($self, $pms, undef, $ratio) = @_; | ||||
149 | |||||
150 | my $subject = $pms->get('Subject'); | ||||
151 | if ($subject eq '') { | ||||
152 | return 0; | ||||
153 | } | ||||
154 | my $max = 0; | ||||
155 | for my $string (@{ $pms->{html}{title} }) { | ||||
156 | if ($string) { | ||||
157 | my $ratio = length($string) / length($subject); | ||||
158 | $max = $ratio if $ratio > $max; | ||||
159 | } | ||||
160 | } | ||||
161 | return $max > $ratio; | ||||
162 | } | ||||
163 | |||||
164 | sub html_text_not_match { | ||||
165 | my ($self, $pms, undef, $text, $regexp) = @_; | ||||
166 | for my $string (@{ $pms->{html}{$text} }) { | ||||
167 | if (defined $string && $string !~ /${regexp}/) { | ||||
168 | return 1; | ||||
169 | } | ||||
170 | } | ||||
171 | return 0; | ||||
172 | } | ||||
173 | |||||
174 | sub html_range { | ||||
175 | my ($self, $pms, undef, $test, $min, $max) = @_; | ||||
176 | |||||
177 | return 0 unless exists $pms->{html}{$test}; | ||||
178 | |||||
179 | $test = $pms->{html}{$test}; | ||||
180 | |||||
181 | # not all perls understand what "inf" means, so we need to do | ||||
182 | # non-numeric tests! urg! | ||||
183 | if (!defined $max || $max eq "inf") { | ||||
184 | return ($test eq "inf") ? 1 : ($test > $min); | ||||
185 | } | ||||
186 | elsif ($test eq "inf") { | ||||
187 | # $max < inf, so $test == inf means $test > $max | ||||
188 | return 0; | ||||
189 | } | ||||
190 | else { | ||||
191 | # if we get here everything should be a number | ||||
192 | return ($test > $min && $test <= $max); | ||||
193 | } | ||||
194 | } | ||||
195 | |||||
196 | sub check_iframe_src { | ||||
197 | my ($self, $pms) = @_; | ||||
198 | |||||
199 | foreach my $v ( values %{$pms->{html}->{uri_detail}} ) { | ||||
200 | return 1 if $v->{types}->{iframe}; | ||||
201 | } | ||||
202 | |||||
203 | return 0; | ||||
204 | } | ||||
205 | |||||
206 | 1 | 9µs | 1; |