← 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:21 2017

Filename/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm
StatementsExecuted 9636 statements in 140ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11198.7ms131msMail::SpamAssassin::Plugin::ReplaceTags::::finish_parsing_endMail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end
26906113.6ms13.6msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:regcompMail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp (opcode)
64117.66ms8.03msMail::SpamAssassin::Plugin::ReplaceTags::::__ANON__[:266]Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[:266]
1810616.60ms6.60msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substMail::SpamAssassin::Plugin::ReplaceTags::CORE:subst (opcode)
2019415.98ms5.98msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:matchMail::SpamAssassin::Plugin::ReplaceTags::CORE:match (opcode)
1690214.89ms4.89msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substcontMail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont (opcode)
11156µs358µsMail::SpamAssassin::Plugin::ReplaceTags::::set_configMail::SpamAssassin::Plugin::ReplaceTags::set_config
11156µs432µsMail::SpamAssassin::Plugin::ReplaceTags::::newMail::SpamAssassin::Plugin::ReplaceTags::new
11144µs44µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@52Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52
11137µs123µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@59Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59
11135µs46µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@56Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56
11134µs39µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@58Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58
11134µs126µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@61Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61
11129µs84µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@57Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57
11127µs224µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@54Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54
11116µs16µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@53Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@53
0000s0sMail::SpamAssassin::Plugin::ReplaceTags::::user_conf_parsing_endMail::SpamAssassin::Plugin::ReplaceTags::user_conf_parsing_end
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
18=head1 NAME
19
20Mail::SpamAssassin::Plugin::ReplaceTags - tags for SpamAssassin rules
21
22The plugin allows rules to contain regular expression tags to be used in
23regular expression rules. The tags make it much easier to maintain
24complicated rules.
25
26Warning: This plugin relies on data structures specific to this version of
27SpamAssasin; it is not guaranteed to work with other versions of SpamAssassin.
28
29=head1 SYNOPSIS
30
31 loadplugin Mail::SpamAssassin::Plugin::ReplaceTags
32
33 replace_start <
34 replace_end >
35
36 replace_tag A [a@]
37 replace_tag G [gk]
38 replace_tag I [il|!1y\?\xcc\xcd\xce\xcf\xec\xed\xee\xef]
39 replace_tag R [r3]
40 replace_tag V (?:[vu]|\\\/)
41 replace_tag SP [\s~_-]
42
43 body VIAGRA_OBFU /(?!viagra)<V>+<SP>*<I>+<SP>*<A>+<SP>*<G>+<SP>*<R>+<SP>*<A>+/i
44 describe VIAGRA_OBFU Attempt to obfuscate "viagra"
45
46 replace_rules VIAGRA_OBFU
47
48=cut
49
50package Mail::SpamAssassin::Plugin::ReplaceTags;
51
52284µs144µs
# spent 44µs within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52 which was called: # once (44µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 52
use Mail::SpamAssassin;
53271µs116µs
# spent 16µs within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@53 which was called: # once (16µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 53
use Mail::SpamAssassin::Plugin;
54272µs2420µs
# spent 224µs (27+197) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 which was called: # once (27µs+197µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 54
use Mail::SpamAssassin::Logger;
# spent 224µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 # spent 197µs making 1 call to Exporter::import
55
56261µs257µs
# spent 46µs (35+11) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 which was called: # once (35µs+11µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 56
use strict;
# spent 46µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 # spent 11µs making 1 call to strict::import
57266µs2139µs
# spent 84µs (29+55) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 which was called: # once (29µs+55µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 57
use warnings;
# spent 84µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 # spent 55µs making 1 call to warnings::import
58292µs244µs
# spent 39µs (34+5) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 which was called: # once (34µs+5µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 58
use bytes;
# spent 39µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 # spent 5µs making 1 call to bytes::import
592104µs2209µs
# spent 123µs (37+86) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 which was called: # once (37µs+86µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 59
use re 'taint';
# spent 123µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 # spent 86µs making 1 call to re::import
60
6122.02ms2218µs
# spent 126µs (34+92) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 which was called: # once (34µs+92µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 61
use vars qw(@ISA);
# spent 126µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 # spent 92µs making 1 call to vars::import
62115µs@ISA = qw(Mail::SpamAssassin::Plugin);
63
64
# spent 432µs (56+376) within Mail::SpamAssassin::Plugin::ReplaceTags::new which was called: # once (56µs+376µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 1 of (eval 79)[Mail/SpamAssassin/PluginHandler.pm:129]
sub new {
6512µs my ($class, $mailsa) = @_;
6615µs $class = ref($class) || $class;
67
68117µs119µs my $self = $class->SUPER::new($mailsa);
# spent 19µs making 1 call to Mail::SpamAssassin::Plugin::new
69
7012µs bless ($self, $class);
71
7218µs1358µs $self->set_config($mailsa->{conf});
73
74116µs return $self;
75}
76
77
# spent 131ms (98.7+32.4) within Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end which was called: # once (98.7ms+32.4ms) by Mail::SpamAssassin::PluginHandler::callback at line 204 of Mail/SpamAssassin/PluginHandler.pm
sub finish_parsing_end {
7812µs my ($self, $opts) = @_;
79
8017µs16µs dbg("replacetags: replacing tags");
# spent 6µs making 1 call to Mail::SpamAssassin::Logger::dbg
81
8213µs my $conf = $opts->{conf};
8314µs my $start = $conf->{replace_start};
8413µs my $end = $conf->{replace_end};
85
86 # this is the version-specific code
8715µs for my $type (qw|body_tests rawbody_tests head_tests full_tests uri_tests|) {
881081µs for my $priority (keys %{$conf->{$type}}) {
89122217.7ms while (my ($rule, $re) = each %{$conf->{$type}->{$priority}}) {
90 # skip if not listed by replace_rules
9112123.04ms next unless $conf->{rules_to_replace}{$rule};
92
9371425µs71731µs if (would_log('dbg', 'replacetags') > 1) {
# spent 731µs making 71 calls to Mail::SpamAssassin::Logger::would_log, avg 10µs/call
94 dbg("replacetags: replacing $rule: $re");
95 }
96
9771114µs my $passes = 0;
9871113µs my $doagain;
99
10071519µs do {
10184137µs my $pre_name;
102 my $post_name;
103 my $inter_name;
10484130µs $doagain = 0;
105
106 # get modifier tags
107841.60ms168820µs if ($re =~ s/${start}pre (.+?)${end}//) {
# spent 503µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 6µs/call # spent 317µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 4µs/call
108 $pre_name = $1;
109 }
110841.40ms168569µs if ($re =~ s/${start}post (.+?)${end}//) {
# spent 340µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 229µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1112978µs $post_name = $1;
112 }
113841.39ms168574µs if ($re =~ s/${start}inter (.+?)${end}//) {
# spent 335µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 239µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1142972µs $inter_name = $1;
115 }
116
117 # this will produce an array of tags to be replaced
118 # for two adjacent tags, an element of "" will be between the two
119841.72ms my @re = split(/(<[^<>]+>)/, $re);
120
12184134µs if ($pre_name) {
122 my $pre = $conf->{replace_pre}->{$pre_name};
123 if ($pre) {
124 s{($start.+?$end)}{$pre$1} for @re;
125 }
126 }
12784173µs if ($post_name) {
12829106µs my $post = $conf->{replace_post}->{$post_name};
12929122µs if ($post) {
1302816.3ms13583.88ms s{($start.+?$end)}{$1$post}g for @re;
# spent 1.51ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 3µs/call # spent 1.28ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call # spent 1.09ms making 434 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 3µs/call
131 }
132 }
13384183µs if ($inter_name) {
13429107µs my $inter = $conf->{replace_inter}->{$inter_name};
13529115µs if ($inter) {
136284.88ms4681.65ms s{^$}{$inter} for @re;
# spent 1.65ms making 468 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call
137 }
138 }
139845.14ms for (my $i = 0; $i < @re; $i++) {
140134826.8ms26967.81ms if ($re[$i] =~ m|$start(.+?)$end|g) {
# spent 4.24ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call # spent 3.57ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1416321.61ms my $tag_name = $1;
142 # if the tag exists, replace it with the corresponding phrase
1436322.23ms if ($tag_name) {
1446322.12ms my $replacement = $conf->{replace_tag}->{$tag_name};
1456322.24ms if ($replacement) {
14662830.5ms251214.1ms $re[$i] =~ s|$start$tag_name$end|$replacement|g;
# spent 8.00ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 13µs/call # spent 3.80ms making 1256 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 3µs/call # spent 2.26ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call
1476284.98ms5431.37ms $doagain = 1 if !$doagain && $replacement =~ /<[^>]+>/;
# spent 1.37ms making 543 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
148 }
149 }
150 }
151 }
152
153841.26ms $re = join('', @re);
154
155 # do the actual replacement
15684242µs $conf->{$type}->{$priority}->{$rule} = $re;
157
15884510µs84880µs if (would_log('dbg', 'replacetags') > 1) {
# spent 880µs making 84 calls to Mail::SpamAssassin::Logger::would_log, avg 10µs/call
159 dbg("replacetags: replaced $rule: $re");
160 }
161
16284716µs $passes++;
163 } while $doagain && $passes <= 5;
164 }
165 }
166 }
167
168 # free this up, if possible
16914µs if (!$conf->{allow_user_rules}) {
170112µs delete $conf->{rules_to_replace};
171 }
172
173116µs17µs dbg("replacetags: done replacing tags");
# spent 7µs making 1 call to Mail::SpamAssassin::Logger::dbg
174}
175
176sub user_conf_parsing_end {
177 my ($self, $opts) = @_;
178 return $self->finish_parsing_end($opts);
179}
180
181
# spent 358µs (56+302) within Mail::SpamAssassin::Plugin::ReplaceTags::set_config which was called: # once (56µs+302µs) by Mail::SpamAssassin::Plugin::ReplaceTags::new at line 72
sub set_config {
18212µs my ($self, $conf) = @_;
18312µs my @cmds;
184
185=head1 RULE DEFINITIONS AND PRIVILEGED SETTINGS
186
187=over 4
188
189=item replace_tag tagname expression
190
191Assign a valid regular expression to tagname.
192
193Note: It is not recommended to put quantifiers inside the tag, it's better to
194put them inside the rule itself for greater flexibility.
195
196=cut
197
19815µs push(@cmds, {
199 setting => 'replace_tag',
200 is_priv => 1,
201 type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
202 });
203
204=item replace_pre tagname expression
205
206Assign a valid regular expression to tagname. The expression will be
207placed before each tag that is replaced.
208
209=cut
210
21113µs push(@cmds, {
212 setting => 'replace_pre',
213 is_priv => 1,
214 type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
215 });
216
217=item replace_inter tagname expression
218
219Assign a valid regular expression to tagname. The expression will be
220placed between each two immediately adjacent tags that are replaced.
221
222=cut
223
22413µs push(@cmds, {
225 setting => 'replace_inter',
226 is_priv => 1,
227 type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
228 });
229
230=item replace_post tagname expression
231
232Assign a valid regular expression to tagname. The expression will be
233placed after each tag that is replaced.
234
235=cut
236
23713µs push(@cmds, {
238 setting => 'replace_post',
239 is_priv => 1,
240 type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
241 });
242
243=item replace_rules list_of_tests
244
245Specify a list of symbolic test names (separated by whitespace) of tests which
246should be modified using replacement tags. Only simple regular expression
247body, header, uri, full, rawbody tests are supported.
248
249=cut
250
251 push(@cmds, {
252 setting => 'replace_rules',
253 is_priv => 1,
254 type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
255
# spent 8.03ms (7.66+375µs) within Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm:266] which was called 64 times, avg 126µs/call: # 64 times (7.66ms+375µs) by Mail::SpamAssassin::Conf::Parser::parse at line 438 of Mail/SpamAssassin/Conf/Parser.pm, avg 126µs/call
code => sub {
25664312µs my ($self, $key, $value, $line) = @_;
25764579µs64179µs unless (defined $value && $value !~ /^$/) {
# spent 179µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
258 return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
259 }
260645.85ms64196µs unless ($value =~ /\S+/) {
# spent 196µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
261 return $Mail::SpamAssassin::Conf::INVALID_VALUE;
262 }
26364664µs foreach my $rule (split(' ', $value)) {
26471677µs $conf->{rules_to_replace}->{$rule} = 1;
265 }
266 }
26718µs });
268
269=item replace_start string
270
271=item replace_end string
272
273String(s) which indicate the start and end of a tag inside a rule. Only tags
274enclosed by the start and end strings are found and replaced.
275
276=cut
277
27818µs push(@cmds, {
279 setting => 'replace_start',
280 is_priv => 1,
281 default => '<',
282 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
283 });
284
28514µs push(@cmds, {
286 setting => 'replace_end',
287 is_priv => 1,
288 default => '>',
289 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
290 });
291
292118µs1302µs $conf->{parser}->register_commands(\@cmds);
293}
294
29518µs1;
296
297=back
298
299=cut
 
# spent 5.98ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match which was called 2019 times, avg 3µs/call: # 1348 times (4.24ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 543 times (1.37ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 147, avg 3µs/call # 64 times (196µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm:266] at line 260, avg 3µs/call # 64 times (179µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm:266] at line 257, avg 3µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match; # opcode
# spent 13.6ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp which was called 2690 times, avg 5µs/call: # 1348 times (3.57ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 628 times (8.00ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 13µs/call # 462 times (1.28ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call # 84 times (317µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 4µs/call # 84 times (239µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 113, avg 3µs/call # 84 times (229µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 110, avg 3µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp; # opcode
# spent 6.60ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst which was called 1810 times, avg 4µs/call: # 628 times (2.26ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 4µs/call # 468 times (1.65ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 136, avg 4µs/call # 462 times (1.51ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call # 84 times (503µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 6µs/call # 84 times (340µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 110, avg 4µs/call # 84 times (335µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 113, avg 4µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst; # opcode
# spent 4.89ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont which was called 1690 times, avg 3µs/call: # 1256 times (3.80ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 3µs/call # 434 times (1.09ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont; # opcode