← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Sun Nov 5 02:36:06 2017
Reported on Sun Nov 5 02:56:22 2017

Filename/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/HTMLEval.pm
StatementsExecuted 36 statements in 3.22ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.30ms1.65msMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@26Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26
111212µs593µsMail::SpamAssassin::Plugin::HTMLEval::::newMail::SpamAssassin::Plugin::HTMLEval::new
11174µs83µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@20Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20
11143µs113µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@29Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29
11135µs114µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@23Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23
11131µs173µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@27Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27
11125µs39µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@22Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22
11120µs61µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@21Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21
11119µs19µsMail::SpamAssassin::Plugin::HTMLEval::::BEGIN@25Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::check_iframe_srcMail::SpamAssassin::Plugin::HTMLEval::check_iframe_src
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_charset_farawayMail::SpamAssassin::Plugin::HTMLEval::html_charset_faraway
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_evalMail::SpamAssassin::Plugin::HTMLEval::html_eval
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_image_onlyMail::SpamAssassin::Plugin::HTMLEval::html_image_only
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_image_ratioMail::SpamAssassin::Plugin::HTMLEval::html_image_ratio
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_rangeMail::SpamAssassin::Plugin::HTMLEval::html_range
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_tag_balanceMail::SpamAssassin::Plugin::HTMLEval::html_tag_balance
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_tag_existsMail::SpamAssassin::Plugin::HTMLEval::html_tag_exists
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_testMail::SpamAssassin::Plugin::HTMLEval::html_test
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_text_matchMail::SpamAssassin::Plugin::HTMLEval::html_text_match
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_text_not_matchMail::SpamAssassin::Plugin::HTMLEval::html_text_not_match
0000s0sMail::SpamAssassin::Plugin::HTMLEval::::html_title_subject_ratioMail::SpamAssassin::Plugin::HTMLEval::html_title_subject_ratio
Call graph for these subroutines as a Graphviz dot language file.
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
18package Mail::SpamAssassin::Plugin::HTMLEval;
19
20267µs292µ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
use strict;
# spent 83µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@20 # spent 9µs making 1 call to strict::import
21273µs2102µ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
use warnings;
# spent 61µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@21 # spent 41µs making 1 call to warnings::import
22280µs254µ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
use bytes;
# spent 39µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@22 # spent 14µs making 1 call to bytes::import
23273µs2193µ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
use re 'taint';
# spent 114µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@23 # spent 79µs making 1 call to re::import
24
25269µs119µ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
use Mail::SpamAssassin::Plugin;
# spent 19µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@25
262333µs11.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
use Mail::SpamAssassin::Locales;
# spent 1.65ms making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@26
27296µs2314µ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
use Mail::SpamAssassin::Util qw(untaint_var);
# spent 173µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@27 # spent 142µs making 1 call to Exporter::import
28
2922.27ms2182µ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
use vars qw(@ISA);
# spent 113µs making 1 call to Mail::SpamAssassin::Plugin::HTMLEval::BEGIN@29 # spent 70µs making 1 call to vars::import
30113µ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]
sub new {
3412µs my $class = shift;
3512µs my $mailsaobject = shift;
36
37 # some boilerplate...
3812µs $class = ref($class) || $class;
39118µs133µs my $self = $class->SUPER::new($mailsaobject);
# spent 33µs making 1 call to Mail::SpamAssassin::Plugin::new
4012µs bless ($self, $class);
41
42 # the important bit!
43120µs132µs $self->register_eval_rule("html_tag_balance");
# spent 32µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
44110µs128µs $self->register_eval_rule("html_image_only");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
4516µs127µs $self->register_eval_rule("html_image_ratio");
# spent 27µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
4616µs126µs $self->register_eval_rule("html_charset_faraway");
# spent 26µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
4716µs128µs $self->register_eval_rule("html_tag_exists");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
4816µs130µs $self->register_eval_rule("html_test");
# spent 30µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
4916µs128µs $self->register_eval_rule("html_eval");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
5016µs128µs $self->register_eval_rule("html_text_match");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
5116µs128µs $self->register_eval_rule("html_title_subject_ratio");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
5216µs128µs $self->register_eval_rule("html_text_not_match");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
5316µs139µs $self->register_eval_rule("html_range");
# spent 39µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
5416µs128µs $self->register_eval_rule("check_iframe_src");
# spent 28µs making 1 call to Mail::SpamAssassin::Plugin::register_eval_rule
55
56118µs return $self;
57}
58
59sub 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
71sub 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
80sub 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
90sub 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
111sub html_tag_exists {
112 my ($self, $pms, undef, $tag) = @_;
113 return exists $pms->{html}{inside}{$tag};
114}
115
116sub html_test {
117 my ($self, $pms, undef, $test) = @_;
118 return $pms->{html}{$test};
119}
120
121sub 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
137sub 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
147sub 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
164sub 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
174sub 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
196sub 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
20618µs1;