Filename | /usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/HTMLEval.pm |
Statements | Executed 36 statements in 3.22ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.30ms | 1.65ms | BEGIN@26 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 212µs | 593µs | new | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 74µs | 83µs | BEGIN@20 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 43µs | 113µs | BEGIN@29 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 35µs | 114µs | BEGIN@23 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 31µs | 173µs | BEGIN@27 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 25µs | 39µs | BEGIN@22 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 20µs | 61µs | BEGIN@21 | Mail::SpamAssassin::Plugin::HTMLEval::
1 | 1 | 1 | 19µs | 19µ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 | 67µs | 2 | 92µs | # spent 83µs (74+9) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20 which was called:
# once (74µs+9µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 20 # spent 83µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20
# spent 9µs making 1 call to strict::import |
21 | 2 | 73µs | 2 | 102µs | # spent 61µs (20+41) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21 which was called:
# once (20µs+41µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 21 # spent 61µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21
# spent 41µs making 1 call to warnings::import |
22 | 2 | 80µs | 2 | 54µs | # spent 39µs (25+14) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22 which was called:
# once (25µs+14µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 22 # spent 39µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22
# spent 14µs making 1 call to bytes::import |
23 | 2 | 73µs | 2 | 193µs | # spent 114µs (35+79) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23 which was called:
# once (35µs+79µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 23 # spent 114µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23
# spent 79µs making 1 call to re::import |
24 | |||||
25 | 2 | 69µs | 1 | 19µs | # spent 19µs within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25 which was called:
# once (19µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 25 # spent 19µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25 |
26 | 2 | 333µs | 1 | 1.65ms | # spent 1.65ms (1.30+346µs) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26 which was called:
# once (1.30ms+346µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 26 # spent 1.65ms making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26 |
27 | 2 | 96µs | 2 | 314µs | # spent 173µs (31+142) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27 which was called:
# once (31µs+142µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 27 # spent 173µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27
# spent 142µs making 1 call to Exporter::import |
28 | |||||
29 | 2 | 2.27ms | 2 | 182µs | # spent 113µs (43+70) within Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29 which was called:
# once (43µs+70µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 29 # spent 113µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29
# spent 70µs making 1 call to vars::import |
30 | 1 | 13µs | @ISA = qw(Mail::SpamAssassin::Plugin); | ||
31 | |||||
32 | # constructor: register the eval rule | ||||
33 | # spent 593µs (212+381) within Mail::SpamAssassin::Plugin::HTMLEval::new which was called:
# once (212µs+381µ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 | 18µs | 1 | 33µs | my $self = $class->SUPER::new($mailsaobject); # spent 33µs making 1 call to Mail::SpamAssassin::Plugin::new |
40 | 1 | 2µs | bless ($self, $class); | ||
41 | |||||
42 | # the important bit! | ||||
43 | 1 | 20µ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 | 10µs | 1 | 28µs | $self->register_eval_rule("html_image_only"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
45 | 1 | 6µs | 1 | 27µs | $self->register_eval_rule("html_image_ratio"); # spent 27µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
46 | 1 | 6µs | 1 | 26µs | $self->register_eval_rule("html_charset_faraway"); # spent 26µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
47 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("html_tag_exists"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
48 | 1 | 6µs | 1 | 30µs | $self->register_eval_rule("html_test"); # spent 30µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
49 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("html_eval"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
50 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("html_text_match"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
51 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("html_title_subject_ratio"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
52 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("html_text_not_match"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
53 | 1 | 6µs | 1 | 39µs | $self->register_eval_rule("html_range"); # spent 39µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
54 | 1 | 6µs | 1 | 28µs | $self->register_eval_rule("check_iframe_src"); # spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule |
55 | |||||
56 | 1 | 18µ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 | 8µs | 1; |