← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Tue Nov 7 05:38:10 2017
Reported on Tue Nov 7 06:16:04 2017

Filename/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm
StatementsExecuted 9636 statements in 137ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111100ms133msMail::SpamAssassin::Plugin::ReplaceTags::::finish_parsing_endMail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end
26906113.8ms13.8msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:regcompMail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp (opcode)
1810616.79ms6.79msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substMail::SpamAssassin::Plugin::ReplaceTags::CORE:subst (opcode)
2019416.06ms6.06msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:matchMail::SpamAssassin::Plugin::ReplaceTags::CORE:match (opcode)
1690214.94ms4.94msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substcontMail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont (opcode)
64112.35ms2.71msMail::SpamAssassin::Plugin::ReplaceTags::::__ANON__[:266]Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[:266]
11171µs349µsMail::SpamAssassin::Plugin::ReplaceTags::::set_configMail::SpamAssassin::Plugin::ReplaceTags::set_config
11152µs430µsMail::SpamAssassin::Plugin::ReplaceTags::::newMail::SpamAssassin::Plugin::ReplaceTags::new
11150µs50µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@52Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52
11138µs113µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@59Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59
11130µs151µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@61Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61
11130µs71µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@57Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57
11125µs42µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@56Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56
11122µs31µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@58Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58
11121µs190µ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
52280µs150µs
# spent 50µs within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52 which was called: # once (50µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 52
use Mail::SpamAssassin;
53266µ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;
54257µs2358µs
# spent 190µs (21+168) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 which was called: # once (21µs+168µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 54
use Mail::SpamAssassin::Logger;
# spent 190µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 # spent 168µs making 1 call to Exporter::import
55
56263µs260µs
# spent 42µs (25+17) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 which was called: # once (25µs+17µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 56
use strict;
# spent 42µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 # spent 17µs making 1 call to strict::import
57266µs2112µs
# spent 71µs (30+41) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 which was called: # once (30µs+41µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 57
use warnings;
# spent 71µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 # spent 41µs making 1 call to warnings::import
58281µs240µs
# spent 31µs (22+9) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 which was called: # once (22µs+9µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 58
use bytes;
# spent 31µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 # spent 9µs making 1 call to bytes::import
59276µs2189µs
# spent 113µs (38+75) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 which was called: # once (38µs+75µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 59
use re 'taint';
# spent 113µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 # spent 76µs making 1 call to re::import
60
6121.95ms2272µs
# spent 151µs (30+121) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 which was called: # once (30µs+121µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 61
use vars qw(@ISA);
# spent 151µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 # spent 121µs making 1 call to vars::import
62113µs@ISA = qw(Mail::SpamAssassin::Plugin);
63
64
# spent 430µs (52+378) within Mail::SpamAssassin::Plugin::ReplaceTags::new which was called: # once (52µs+378µ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) = @_;
6612µs $class = ref($class) || $class;
67
68119µs130µs my $self = $class->SUPER::new($mailsa);
# spent 30µs making 1 call to Mail::SpamAssassin::Plugin::new
69
7012µs bless ($self, $class);
71
7217µs1349µs $self->set_config($mailsa->{conf});
73
74111µs return $self;
75}
76
77
# spent 133ms (100+32.9) within Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end which was called: # once (100ms+32.9ms) 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
8717µs for my $type (qw|body_tests rawbody_tests head_tests full_tests uri_tests|) {
8810110µs for my $priority (keys %{$conf->{$type}}) {
89122218.1ms while (my ($rule, $re) = each %{$conf->{$type}->{$priority}}) {
90 # skip if not listed by replace_rules
9112123.15ms next unless $conf->{rules_to_replace}{$rule};
92
9371433µs71738µs if (would_log('dbg', 'replacetags') > 1) {
# spent 738µs making 71 calls to Mail::SpamAssassin::Logger::would_log, avg 10µs/call
94 dbg("replacetags: replacing $rule: $re");
95 }
96
9771129µs my $passes = 0;
9871108µs my $doagain;
99
10071528µs do {
10184151µs my $pre_name;
102 my $post_name;
103 my $inter_name;
10484149µs $doagain = 0;
105
106 # get modifier tags
107841.74ms168910µs if ($re =~ s/${start}pre (.+?)${end}//) {
# spent 615µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 7µs/call # spent 295µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 4µs/call
108 $pre_name = $1;
109 }
110841.50ms168587µs if ($re =~ s/${start}post (.+?)${end}//) {
# spent 356µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 232µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1112979µs $post_name = $1;
112 }
113841.44ms168576µs if ($re =~ s/${start}inter (.+?)${end}//) {
# spent 342µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 234µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1142974µ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.81ms my @re = split(/(<[^<>]+>)/, $re);
120
12184141µ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 }
12784189µs if ($post_name) {
12829113µs my $post = $conf->{replace_post}->{$post_name};
12929114µs if ($post) {
1302810.6ms13583.90ms s{($start.+?$end)}{$1$post}g for @re;
# spent 1.56ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 3µs/call # spent 1.29ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call # spent 1.06ms making 434 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 2µs/call
131 }
132 }
13384186µs if ($inter_name) {
13429103µs my $inter = $conf->{replace_inter}->{$inter_name};
13529111µs if ($inter) {
1362810.2ms4681.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.24ms for (my $i = 0; $i < @re; $i++) {
140134827.2ms26967.89ms if ($re[$i] =~ m|$start(.+?)$end|g) {
# spent 4.30ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call # spent 3.60ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1416321.64ms my $tag_name = $1;
142 # if the tag exists, replace it with the corresponding phrase
1436322.24ms if ($tag_name) {
1446322.15ms my $replacement = $conf->{replace_tag}->{$tag_name};
1456322.36ms if ($replacement) {
14662831.2ms251214.3ms $re[$i] =~ s|$start$tag_name$end|$replacement|g;
# spent 8.12ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 13µs/call # spent 3.88ms making 1256 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 3µs/call # spent 2.27ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call
1476285.19ms5431.40ms $doagain = 1 if !$doagain && $replacement =~ /<[^>]+>/;
# spent 1.40ms making 543 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
148 }
149 }
150 }
151 }
152
153841.31ms $re = join('', @re);
154
155 # do the actual replacement
15684254µs $conf->{$type}->{$priority}->{$rule} = $re;
157
15884567µs84930µs if (would_log('dbg', 'replacetags') > 1) {
# spent 930µs making 84 calls to Mail::SpamAssassin::Logger::would_log, avg 11µs/call
159 dbg("replacetags: replaced $rule: $re");
160 }
161
16284695µs $passes++;
163 } while $doagain && $passes <= 5;
164 }
165 }
166 }
167
168 # free this up, if possible
16915µs if (!$conf->{allow_user_rules}) {
170113µs delete $conf->{rules_to_replace};
171 }
172
173120µs18µs dbg("replacetags: done replacing tags");
# spent 8µ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 349µs (71+277) within Mail::SpamAssassin::Plugin::ReplaceTags::set_config which was called: # once (71µs+277µs) by Mail::SpamAssassin::Plugin::ReplaceTags::new at line 72
sub set_config {
18212µs my ($self, $conf) = @_;
18311µ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
198114µ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
22416µ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 2.71ms (2.35+360µ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 42µs/call: # 64 times (2.35ms+360µs) by Mail::SpamAssassin::Conf::Parser::parse at line 438 of Mail/SpamAssassin/Conf/Parser.pm, avg 42µs/call
code => sub {
25664312µs my ($self, $key, $value, $line) = @_;
25764587µs64162µs unless (defined $value && $value !~ /^$/) {
# spent 162µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
258 return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
259 }
26064592µs64198µs unless ($value =~ /\S+/) {
# spent 198µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
261 return $Mail::SpamAssassin::Conf::INVALID_VALUE;
262 }
26364713µs foreach my $rule (split(' ', $value)) {
26471597µs $conf->{rules_to_replace}->{$rule} = 1;
265 }
266 }
267111µ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
28517µs push(@cmds, {
286 setting => 'replace_end',
287 is_priv => 1,
288 default => '>',
289 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
290 });
291
292117µs1277µs $conf->{parser}->register_commands(\@cmds);
293}
294
29518µs1;
296
297=back
298
299=cut
 
# spent 6.06ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match which was called 2019 times, avg 3µs/call: # 1348 times (4.30ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 543 times (1.40ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 147, avg 3µs/call # 64 times (198µ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 (162µ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.8ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp which was called 2690 times, avg 5µs/call: # 1348 times (3.60ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 628 times (8.12ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 13µs/call # 462 times (1.29ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call # 84 times (295µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 4µs/call # 84 times (234µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 113, avg 3µs/call # 84 times (232µ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.79ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst which was called 1810 times, avg 4µs/call: # 628 times (2.27ms+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.56ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call # 84 times (615µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 7µs/call # 84 times (356µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 110, avg 4µs/call # 84 times (342µ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.94ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont which was called 1690 times, avg 3µs/call: # 1256 times (3.88ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 3µs/call # 434 times (1.06ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 2µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont; # opcode