line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Lite::Processor::Regexp; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
83
|
|
4
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Mail::Lite::Constants; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
183
|
|
7
|
2
|
|
|
2
|
|
10
|
use Smart::Comments -ENV; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1665
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1527
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _get_regexpable_text { |
13
|
420
|
|
|
420
|
|
778
|
my $message = shift; |
14
|
|
|
|
|
|
|
|
15
|
420
|
|
|
|
|
714
|
my $text_type = shift; |
16
|
|
|
|
|
|
|
|
17
|
420
|
100
|
|
|
|
1200
|
if ( $text_type eq 'body' ) { |
18
|
230
|
|
|
|
|
975
|
return $message->body; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
190
|
50
|
|
|
|
1020
|
if ( $text_type ne 'header' ) { |
22
|
190
|
|
|
|
|
1274
|
return $message->header( $text_type ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
my $text = ''; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
while( my ($k, $v) = each %{ $message->headers } ) { |
|
0
|
|
|
|
|
0
|
|
28
|
0
|
|
|
|
|
0
|
$k =~ tr/-/_/; |
29
|
0
|
|
|
|
|
0
|
$text .= "$k:$v\n"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
return $text; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub process { |
36
|
230
|
|
|
230
|
0
|
422
|
my $args_ref = shift; |
37
|
|
|
|
|
|
|
|
38
|
230
|
|
|
|
|
416
|
my $message = $args_ref->{input }; |
39
|
230
|
|
|
|
|
336
|
my $processor_args = $args_ref->{processor }; |
40
|
|
|
|
|
|
|
|
41
|
230
|
|
|
|
|
482
|
my $extracted = {}; |
42
|
|
|
|
|
|
|
|
43
|
230
|
|
|
|
|
517
|
my $regexps = $processor_args->{regexps}; |
44
|
|
|
|
|
|
|
|
45
|
230
|
|
|
|
|
391
|
my $regexpables_texts; |
46
|
|
|
|
|
|
|
|
47
|
230
|
|
|
|
|
362
|
my @rules = keys %{ $regexps }; |
|
230
|
|
|
|
|
930
|
|
48
|
|
|
|
|
|
|
REGEXP_RULE: |
49
|
230
|
|
|
|
|
474
|
foreach my $rulename ( @rules ) { |
50
|
|
|
|
|
|
|
|
51
|
581
|
|
|
|
|
1265
|
my $rule = $regexps->{ $rulename }; |
52
|
|
|
|
|
|
|
|
53
|
581
|
|
|
|
|
3780
|
my ( $rule_var, $rule_on, $no_global ) = |
54
|
|
|
|
|
|
|
( $rulename =~ /^([^=]+)=~([^,]+)(?:\,(once))?$/g ); |
55
|
|
|
|
|
|
|
|
56
|
581
|
|
66
|
|
|
2869
|
my $text = |
57
|
|
|
|
|
|
|
$regexpables_texts->{ $rule_on } |
58
|
|
|
|
|
|
|
||= _get_regexpable_text( $message, $rule_on ); |
59
|
|
|
|
|
|
|
|
60
|
581
|
|
|
|
|
763
|
my @matched; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# parse_rfc822 alike behaviour |
63
|
581
|
100
|
|
|
|
1744
|
if ( $rule_var eq '$1' ) { |
64
|
54
|
|
|
|
|
829
|
while ( $text =~ m/$rule/g ) { |
65
|
|
|
|
|
|
|
# $1 is the key $2 is value |
66
|
458
|
|
|
|
|
1991
|
my ($k, $v) = ($1, $2); |
67
|
|
|
|
|
|
|
|
68
|
458
|
100
|
|
|
|
1008
|
if ( exists $extracted->{ $k } ) { |
69
|
7
|
50
|
|
|
|
29
|
if ( ref $extracted->{ $k } eq 'ARRAY' ) { |
70
|
0
|
|
|
|
|
0
|
push @{ $extracted->{ $k } }, $v; |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} else { |
72
|
7
|
|
|
|
|
83
|
$extracted->{ $k } = [ $extracted->{ $k }, $v ]; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} else { |
75
|
451
|
|
|
|
|
3881
|
$extracted->{ $1 } = $2; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
54
|
|
|
|
|
229
|
next REGEXP_RULE; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
527
|
50
|
|
|
|
1040
|
if ( ref $rule eq 'ARRAY' ) { |
82
|
|
|
|
|
|
|
REGEXPS_CHAIN: |
83
|
0
|
|
|
|
|
0
|
foreach my $regexp (@$rule) { |
84
|
0
|
|
|
|
|
0
|
@matched = ($text =~ m/$regexp/mg); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
last REGEXPS_CHAIN unless @matched; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$text = "@matched"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} else { |
91
|
527
|
100
|
|
|
|
798
|
if ( not $no_global ) { |
92
|
521
|
50
|
|
|
|
1151
|
$text or confess( $rule ); |
93
|
521
|
|
|
|
|
19176
|
@matched = ($text =~ m/$rule/mg); |
94
|
|
|
|
|
|
|
} else { |
95
|
6
|
|
|
|
|
58
|
@matched = ($text =~ m/$rule/m); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
527
|
100
|
|
|
|
1649
|
next REGEXP_RULE unless @matched; |
100
|
|
|
|
|
|
|
|
101
|
523
|
100
|
|
|
|
1030
|
if ( @matched > 1 ) { |
102
|
34
|
|
|
|
|
146
|
$extracted->{ $rule_var } = \@matched; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
489
|
|
|
|
|
2521
|
$extracted->{ $rule_var } = $matched[0]; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
230
|
|
|
|
|
510
|
${ $args_ref->{ output } } = [ $extracted ]; |
|
230
|
|
|
|
|
468
|
|
110
|
|
|
|
|
|
|
|
111
|
230
|
|
|
|
|
729
|
return OK; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |