← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Sun Nov 5 03:09:29 2017
Reported on Mon Nov 6 13:20:49 2017

Filename/usr/local/lib/perl5/site_perl/Mail/SpamAssassin/Plugin/ReplaceTags.pm
StatementsExecuted 9636 statements in 156ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111118ms152msMail::SpamAssassin::Plugin::ReplaceTags::::finish_parsing_endMail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end
26906115.0ms15.0msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:regcompMail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp (opcode)
1810616.86ms6.86msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substMail::SpamAssassin::Plugin::ReplaceTags::CORE:subst (opcode)
2019416.11ms6.11msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:matchMail::SpamAssassin::Plugin::ReplaceTags::CORE:match (opcode)
1690214.79ms4.79msMail::SpamAssassin::Plugin::ReplaceTags::::CORE:substcontMail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont (opcode)
64112.77ms3.15msMail::SpamAssassin::Plugin::ReplaceTags::::__ANON__[:266]Mail::SpamAssassin::Plugin::ReplaceTags::__ANON__[:266]
11149µs240µsMail::SpamAssassin::Plugin::ReplaceTags::::set_configMail::SpamAssassin::Plugin::ReplaceTags::set_config
11144µs303µsMail::SpamAssassin::Plugin::ReplaceTags::::newMail::SpamAssassin::Plugin::ReplaceTags::new
11139µs39µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@52Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52
11128µs58µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@57Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57
11122µs26µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@58Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58
11121µs155µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@54Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54
11120µs92µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@61Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61
11120µs29µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@56Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56
11119µs73µsMail::SpamAssassin::Plugin::ReplaceTags::::BEGIN@59Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59
11112µs12µ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
52263µs139µs
# spent 39µs within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@52 which was called: # once (39µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 52
use Mail::SpamAssassin;
53248µs112µs
# spent 12µs within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@53 which was called: # once (12µs+0s) by Mail::SpamAssassin::PluginHandler::load_plugin at line 53
use Mail::SpamAssassin::Plugin;
54253µs2289µs
# spent 155µs (21+134) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 which was called: # once (21µs+134µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 54
use Mail::SpamAssassin::Logger;
# spent 155µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@54 # spent 134µs making 1 call to Exporter::import
55
56251µs237µs
# spent 29µs (20+8) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 which was called: # once (20µs+8µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 56
use strict;
# spent 29µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@56 # spent 8µs making 1 call to strict::import
57264µs288µs
# spent 58µs (28+30) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 which was called: # once (28µs+30µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 57
use warnings;
# spent 58µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@57 # spent 30µs making 1 call to warnings::import
58255µs232µs
# spent 26µs (22+5) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 which was called: # once (22µs+5µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 58
use bytes;
# spent 26µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@58 # spent 5µs making 1 call to bytes::import
59265µs2126µs
# spent 73µs (19+54) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 which was called: # once (19µs+54µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 59
use re 'taint';
# spent 73µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@59 # spent 54µs making 1 call to re::import
60
6121.82ms2163µs
# spent 92µs (20+71) within Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 which was called: # once (20µs+71µs) by Mail::SpamAssassin::PluginHandler::load_plugin at line 61
use vars qw(@ISA);
# spent 92µs making 1 call to Mail::SpamAssassin::Plugin::ReplaceTags::BEGIN@61 # spent 71µs making 1 call to vars::import
62113µs@ISA = qw(Mail::SpamAssassin::Plugin);
63
64
# spent 303µs (44+260) within Mail::SpamAssassin::Plugin::ReplaceTags::new which was called: # once (44µs+260µ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
68110µs120µs my $self = $class->SUPER::new($mailsa);
# spent 20µs making 1 call to Mail::SpamAssassin::Plugin::new
69
7012µs bless ($self, $class);
71
7218µs1240µs $self->set_config($mailsa->{conf});
73
74114µs return $self;
75}
76
77
# spent 152ms (118+34.2) within Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end which was called: # once (118ms+34.2ms) by Mail::SpamAssassin::PluginHandler::callback at line 204 of Mail/SpamAssassin/PluginHandler.pm
sub finish_parsing_end {
7813µs my ($self, $opts) = @_;
79
8016µs16µs dbg("replacetags: replacing tags");
# spent 6µs making 1 call to Mail::SpamAssassin::Logger::dbg
81
8214µ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|) {
881070µs for my $priority (keys %{$conf->{$type}}) {
89122210.5ms while (my ($rule, $re) = each %{$conf->{$type}->{$priority}}) {
90 # skip if not listed by replace_rules
9112123.18ms next unless $conf->{rules_to_replace}{$rule};
92
9371452µs71768µs if (would_log('dbg', 'replacetags') > 1) {
# spent 768µs making 71 calls to Mail::SpamAssassin::Logger::would_log, avg 11µs/call
94 dbg("replacetags: replacing $rule: $re");
95 }
96
9771122µs my $passes = 0;
9871113µs my $doagain;
99
10071518µs do {
10184130µs my $pre_name;
102 my $post_name;
103 my $inter_name;
10484145µs $doagain = 0;
105
106 # get modifier tags
107841.52ms168607µs if ($re =~ s/${start}pre (.+?)${end}//) {
# spent 319µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 4µs/call # spent 287µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 3µs/call
108 $pre_name = $1;
109 }
110841.55ms168618µs if ($re =~ s/${start}post (.+?)${end}//) {
# spent 376µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 242µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1112984µs $post_name = $1;
112 }
113848.82ms168588µs if ($re =~ s/${start}inter (.+?)${end}//) {
# spent 346µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 242µs making 84 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1142977µ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.84ms my @re = split(/(<[^<>]+>)/, $re);
120
12184133µ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 }
12784206µs if ($post_name) {
12829107µs my $post = $conf->{replace_post}->{$post_name};
12929112µs if ($post) {
1302822.4ms13584.12ms s{($start.+?$end)}{$1$post}g for @re;
# spent 1.64ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call # spent 1.35ms making 462 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call # spent 1.13ms making 434 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 3µs/call
131 }
132 }
13384183µs if ($inter_name) {
13429120µs my $inter = $conf->{replace_inter}->{$inter_name};
13529115µs if ($inter) {
136284.81ms4681.70ms s{^$}{$inter} for @re;
# spent 1.70ms making 468 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call
137 }
138 }
139845.19ms for (my $i = 0; $i < @re; $i++) {
140134841.8ms26967.96ms if ($re[$i] =~ m|$start(.+?)$end|g) {
# spent 4.34ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call # spent 3.63ms making 1348 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 3µs/call
1416321.68ms my $tag_name = $1;
142 # if the tag exists, replace it with the corresponding phrase
1436322.23ms if ($tag_name) {
1446322.33ms my $replacement = $conf->{replace_tag}->{$tag_name};
1456322.26ms if ($replacement) {
14662828.8ms251215.4ms $re[$i] =~ s|$start$tag_name$end|$replacement|g;
# spent 9.26ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp, avg 15µs/call # spent 3.65ms making 1256 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont, avg 3µs/call # spent 2.51ms making 628 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst, avg 4µs/call
1476285.52ms5431.39ms $doagain = 1 if !$doagain && $replacement =~ /<[^>]+>/;
# spent 1.39ms making 543 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
148 }
149 }
150 }
151 }
152
153841.13ms $re = join('', @re);
154
155 # do the actual replacement
15684279µs $conf->{$type}->{$priority}->{$rule} = $re;
157
15884564µs841.04ms if (would_log('dbg', 'replacetags') > 1) {
# spent 1.04ms making 84 calls to Mail::SpamAssassin::Logger::would_log, avg 12µs/call
159 dbg("replacetags: replaced $rule: $re");
160 }
161
16284851µs $passes++;
163 } while $doagain && $passes <= 5;
164 }
165 }
166 }
167
168 # free this up, if possible
16915µs if (!$conf->{allow_user_rules}) {
170126µs delete $conf->{rules_to_replace};
171 }
172
173123µs112µs dbg("replacetags: done replacing tags");
# spent 12µ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 240µs (49+191) within Mail::SpamAssassin::Plugin::ReplaceTags::set_config which was called: # once (49µs+191µ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 3.15ms (2.77+377µ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 49µs/call: # 64 times (2.77ms+377µs) by Mail::SpamAssassin::Conf::Parser::parse at line 438 of Mail/SpamAssassin/Conf/Parser.pm, avg 49µs/call
code => sub {
25664299µs my ($self, $key, $value, $line) = @_;
25764836µs64170µs unless (defined $value && $value !~ /^$/) {
# spent 170µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
258 return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
259 }
26064801µs64206µs unless ($value =~ /\S+/) {
# spent 206µs making 64 calls to Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match, avg 3µs/call
261 return $Mail::SpamAssassin::Conf::INVALID_VALUE;
262 }
26364942µs foreach my $rule (split(' ', $value)) {
26471618µ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
27814µ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
292116µs1191µs $conf->{parser}->register_commands(\@cmds);
293}
294
29518µs1;
296
297=back
298
299=cut
 
# spent 6.11ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:match which was called 2019 times, avg 3µs/call: # 1348 times (4.34ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 543 times (1.39ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 147, avg 3µs/call # 64 times (206µ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 (170µ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 15.0ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:regcomp which was called 2690 times, avg 6µs/call: # 1348 times (3.63ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 140, avg 3µs/call # 628 times (9.26ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 15µs/call # 462 times (1.35ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call # 84 times (319µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 4µs/call # 84 times (242µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 113, avg 3µs/call # 84 times (242µ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.86ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst which was called 1810 times, avg 4µs/call: # 628 times (2.51ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 4µs/call # 468 times (1.70ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 136, avg 4µs/call # 462 times (1.64ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 4µs/call # 84 times (376µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 110, avg 4µs/call # 84 times (346µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 113, avg 4µs/call # 84 times (287µs+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 107, avg 3µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:subst; # opcode
# spent 4.79ms within Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont which was called 1690 times, avg 3µs/call: # 1256 times (3.65ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 146, avg 3µs/call # 434 times (1.13ms+0s) by Mail::SpamAssassin::Plugin::ReplaceTags::finish_parsing_end at line 130, avg 3µs/call
sub Mail::SpamAssassin::Plugin::ReplaceTags::CORE:substcont; # opcode