| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $options{$_} and defined $options{$_}
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{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
exists $options{"Warn"} and defined $options{"Warn"} and $options{"Warn"}
exists $options{"Warn"} and defined $options{"Warn"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
exists $options{"EscapeSingleInputDot"} and defined $options{"EscapeSingleInputDot"} and $options{"EscapeSingleInputDot"}
exists $options{"EscapeSingleInputDot"} and defined $options{"EscapeSingleInputDot"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 68 | ▶ | if ( $data->[$i] =~ /^\.(\..*)$/os ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | $data->[$i] = $1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 68 | ▶ | if ( $self->{'Warn'} and $data->[$i] =~ /^\..+$/os ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"Warn"} and $data->[$i] =~ /^\..+$/so
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | ▶ | if ( $lines->[$i] =~ /^\..+$literal$/s ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$self->{"EscapeSingleInputDot"} and $lines->[$i] =~ /^\.$/so || $lines->[$i] =~ /^\.$literal$/so
$lines->[$i] =~ /^\.$/so or $lines->[$i] =~ /^\.$literal$/so
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||