blib/lib/POE/Filter/Transparent/SMTP.pm

filter: Statementstmt 90.9% 90 / 99 Branchbran 71.8% 23 / 32 Conditioncond 33.3% 8 / 24 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 75.4% 141 / 187 CC 26 SCAR 21.2
CC
26
Cov
78%
new
16.7
put
8.5
get_one
5.2
CRAP 8.3
↑ Summary
1 # Copyright (c) 2008-2009 George Nistorica
2 # All rights reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the same terms as Perl itself. See the LICENSE
5 # file that comes with this distribution for more details.
6  
7 # ($rcs) = (' $Id: SMTP.pm,v 1.11 2009/01/28 12:45:15 george Exp $ ' =~ /(\d+(\.\d+)+)/);
8  
9 package POE::Filter::Transparent::SMTP;
10 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use POE::Filter::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 our $VERSION = q{0.2};
18 5 my $EOL = qq{\015\012};
19  
20 7 ▶sub new {
Subroutine new: called CC=12 SCAR=28.1
Pod documented
21 7 my $class = shift;
22 7 my @options = @_;
23 7 my %options = @options;
24  
25 7 my ( $filter, $self, %filter_line_opts );
26 7 ▶ if ( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 7 7
27 0 croak q{->new() is a class method!};
28 }
29  
30 7 foreach (qw/InputLiteral OutputLiteral/) {
31 14 ▶ if ( exists $options{$_} and defined $options{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{$_} and defined $options{$_}) 12 2 14
Condition66%2/3
exists $options{$_} and defined $options{$_}
!ll&&!rl&&r
2012
MC/DC50%1/2
exists $options{$_} and defined $options{$_}
exists $options{$_} defined $options{$_}
Truth table66%2/3
A and B
A= exists $options{$_}B= defined $options{$_}
ABresult
0X0
100
111
32 12 $filter_line_opts{$_} = $options{$_};
33 }
34 }
35  
36 # we need this when outputing data prefixed by dot
37 7 ▶ if ( not exists $filter_line_opts{'OutputLiteral'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $filter_line_opts{'OutputLiteral'}) { } 1 6 7
38 1 $self->{'OutputLiteral'} = $EOL;
39 }
40 else {
41 6 $self->{'OutputLiteral'} = $filter_line_opts{'OutputLiteral'};
42 }
43  
44 7 ▶ if ( exists $options{'Warn'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{'Warn'} and defined $options{'Warn'} and $options{'Warn'}) { } 0 7 7
Condition33%2/6
exists $options{"Warn"} and defined $options{"Warn"} and $options{"Warn"}
!ll&&!rl&&r
700
exists $options{"Warn"} and defined $options{"Warn"}
!ll&&!rl&&r
700
MC/DC0%0/3
exists $options{"Warn"} and defined $options{"Warn"} and $options{"Warn"}
exists $options{"Warn"} defined $options{"Warn"} $options{"Warn"}
Truth table25%1/4
A and B and C
A= exists $options{"Warn"}B= defined $options{"Warn"}C= $options{"Warn"}
ABCresult
0XX0
10X0
1100
1111
45 and defined $options{'Warn'}
46 and $options{'Warn'} )
47 {
48 0 $self->{'Warn'} = 1;
49 }
50 else {
51 7 $self->{'Warn'} = 0;
52 }
53  
54 # check for EscapeSingleInputDot
55 # defaults to no
56 # useful for escaping Single Dot on a line in message bodies (not
57 # entire SMTP transaction logs, that include the message body as
58 # well)
59  
60 7 ▶ if ( exists $options{'EscapeSingleInputDot'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{'EscapeSingleInputDot'} and defined $options{'EscapeSingleInputDot'} and $options{'EscapeSingleInputDot'}) { } 0 7 7
Condition33%2/6
exists $options{"EscapeSingleInputDot"} and defined $options{"EscapeSingleInputDot"} and $options{"EscapeSingleInputDot"}
!ll&&!rl&&r
700
exists $options{"EscapeSingleInputDot"} and defined $options{"EscapeSingleInputDot"}
!ll&&!rl&&r
700
MC/DC0%0/3
exists $options{"EscapeSingleInputDot"} and defined $options{"EscapeSingleInputDot"} and $options{"EscapeSingleInputDot"}
exists $options{"EscapeSingleInputDot"} defined $options{"EscapeSingleInputDot"} $options{"EscapeSingleInputDot"}
Truth table25%1/4
A and B and C
A= exists $options{"EscapeSingleInputDot"}B= defined $options{"EscapeSingleInputDot"}C= $options{"EscapeSingleInputDot"}
ABCresult
0XX0
10X0
1100
1111
61 and defined $options{'EscapeSingleInputDot'}
62 and $options{'EscapeSingleInputDot'} )
63 {
64 0 $self->{'EscapeSingleInputDot'} = 1;
65 }
66 else {
67 7 $self->{'EscapeSingleInputDot'} = 0;
68 }
69  
70 # create the POE::Filter::Line filter to store inside our little so
71 # called object
72 7 $filter = POE::Filter::Line->new(%filter_line_opts);
73 7 $self->{'filter_line'} = $filter;
74 7 bless $self, $class;
75 7 return $self;
76 }
77  
78 1 ▶sub clone {
Subroutine clone: called CC=2 SCAR=7.1
Pod documented
79 1 my $self = shift;
80 1 my $filter;
81 1 ▶ if ( not ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 1 1
82 0 croak q{->clone() is not a package method!};
83 }
84 1 my $new_obj = $self;
85 1 $filter = $new_obj->{'filter_line'};
86 1 $filter = $filter->clone;
87 1 $new_obj->{'filter_line'} = $filter;
88 1 return $new_obj;
89 }
90  
91 13 ▶sub get_one_start {
Subroutine get_one_start: called CC=2 SCAR=7.1
Pod documented
92 13 my $self = shift;
93 13 my $arg = shift;
94 13 ▶ if ( ref $arg ne q{ARRAY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg ne "ARRAY") 0 13 13
95 0 croak q{->get_one_start() accepts an array ref as argument};
96 }
97 13 my $filter = $self->{'filter_line'};
98 13 $filter->get_one_start($arg);
99 13 return;
100 }
101  
102 76 ▶sub get_one {
Subroutine get_one: called CC=5 SCAR=16.5
Pod documented
103 76 my $self = shift;
104 76 my $data;
105 76 my $filter = $self->{'filter_line'};
106 76 $data = $filter->get_one();
107  
108 # remove the leading transparent dot
109 76 ▶ for ( my $i = 0 ; $i < scalar @{$data} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$data;}) 68 76 144
110 68 ▶ if ( $data->[$i] =~ /^\.(\..*)$/os ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->[$i] =~ /^\.(\..*)$/so) 12 56 68
111 12 $data->[$i] = $1;
112 }
113 68 ▶ if ( $self->{'Warn'} and $data->[$i] =~ /^\..+$/os ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Warn"} and $data->[$i] =~ /^\..+$/so) 0 68 68
Condition33%1/3
$self->{"Warn"} and $data->[$i] =~ /^\..+$/so
!ll&&!rl&&r
6800
MC/DC0%0/2
$self->{"Warn"} and $data->[$i] =~ /^\..+$/so
$self->{"Warn"} $data->[$i] =~ /^\..+$/so
Truth table33%1/3
A and B
A= $self->{"Warn"}B= $data->[$i] =~ /^\..+$/so
ABresult
0X0
100
111
114 0 carp q{Data contains a single leading dot }
115 . q{and is not conforming to RFC 821 Section }
116 . q{4.5.2. TRANSPARENCY};
117 }
118 }
119 76 return $data;
120 }
121  
122 6 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
123 6 my $self = shift;
124 6 my $raw_data = shift;
125  
126 6 ▶ if ( ref $raw_data ne q{ARRAY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_data ne "ARRAY") 0 6 6
127 0 croak q{->get() accepts an array ref as argument};
128 }
129 6 my $data = [];
130 6 my $temp;
131  
132 6 $self->get_one_start($raw_data);
133 6 $temp = $self->get_one();
134 6 ▶ while ( scalar @{$temp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$temp;}) 37 6 43
135 37 push @{$data}, $temp->[0];
136 37 $temp = $self->get_one();
137 }
138  
139 6 return $data;
140 }
141  
142 6 ▶sub put {
Subroutine put: called CC=7 SCAR=21.4
Pod documented
143 6 my $self = shift;
144 6 my $raw_data = shift;
145 6 ▶ if ( ref $raw_data ne q{ARRAY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_data ne "ARRAY") 0 6 6
146 0 croak q{->get_one_start() accepts an array ref as argument};
147 }
148 6 my ( $filter, $lines, $literal );
149 6 $literal = $self->{'OutputLiteral'};
150 6 $filter = $self->{'filter_line'};
151 6 $lines = $filter->put($raw_data);
152  
153 # add an extra leading dot on lines starting with a dot
154 6 ▶ for ( my $i = 0 ; $i < scalar @{$lines} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$lines;}) 24 6 30
155 24 ▶ if ( $lines->[$i] =~ /^\..+$literal$/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[$i] =~ /^\..+$literal$/s) 6 18 24
156 6 $lines->[$i] = q{.} . $lines->[$i];
157 }
158  
159 # do we escape single dot? (for filtering message bodies, not
160 # entire SMTP transaction
161 24 ▶ if ( $self->{'EscapeSingleInputDot'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EscapeSingleInputDot"} and $lines->[$i] =~ /^\.$/so || $lines->[$i] =~ /^\.$literal$/so) 0 24 24
Condition16%1/6
$self->{"EscapeSingleInputDot"} and $lines->[$i] =~ /^\.$/so || $lines->[$i] =~ /^\.$literal$/so
!ll&&!rl&&r
2400
$lines->[$i] =~ /^\.$/so or $lines->[$i] =~ /^\.$literal$/so
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"EscapeSingleInputDot"} and $lines->[$i] =~ /^\.$/so || $lines->[$i] =~ /^\.$literal$/so
$self->{"EscapeSingleInputDot"} $lines->[$i] =~ /^\.$/so $lines->[$i] =~ /^\.$literal$/so
Truth table25%1/4
A and B or C
A= $self->{"EscapeSingleInputDot"}B= $lines->[$i] =~ /^\.$/soC= $lines->[$i] =~ /^\.$literal$/so
ABCresult
0XX0
1000
11X1
1011
162 and ( $lines->[$i] =~ /^\.$/so or $lines->[$i] =~ /^\.$literal$/so )
163 )
164 {
165 0 $lines->[$i] = q{.} . $lines->[$i];
166 }
167 }
168  
169 6 return $lines;
170 }
171  
172 6 ▶sub get_pending {
Subroutine get_pending: called CC=1 SCAR=0.0
Pod documented
173 6 my $self = shift;
174 6 my $filter = $self->{'filter_line'};
175 6 return $filter->get_pending();
176 }
177  
178 5 1;
179  
180 __END__
↑ Summary