SimpleSMTP.pm

filter: Statementstmt 69.4% 427 / 615 Branchbran 51.5% 136 / 264 Conditioncond 39.8% 43 / 108 MC/DCmcdc 15.3% 10 / 65 Subroutinesub 75.3% 55 / 73 Podpod 62.0% 18 / 29 totaltotal 59.7% 689 / 1154 CC 191 SCAR 26.1
CC
191
Cov
61%
register
42.0
_unregister
42.0
_smtp_send_relay
42.0
CRAP 13.6
↑ Summary SimpleSMTP/Constants.pm »
1 package POE::Component::Server::SimpleSMTP;
2 14 $POE::Component::Server::SimpleSMTP::VERSION = '1.52';
3 #ABSTRACT: A simple to use POE SMTP Server.
4  
5 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use POE qw(Component::Client::SMTP Component::Client::DNS Wheel::SocketFactory Wheel::ReadWrite Filter::Transparent::SMTP);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use POE::Component::Client::DNSBL;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use base qw(POE::Component::Pluggable);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use POE::Component::Pluggable::Constants qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Email::MessageID;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 14 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 14 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 13 ▶sub spawn {
Subroutine spawn: called CC=18 SCAR=30.6
Pod documented
20 13 my $package = shift;
21 13 my %opts = @_;
22 13 $opts{lc $_} = delete $opts{$_} for keys %opts;
23 13 my $options = delete $opts{options};
24 13 ▶ _massage_handlers( $opts{handlers} ) if $opts{handlers};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"handlers"} 6 7 13
25 13 ▶ $opts{handlers} = [ ] unless $opts{handlers} and ref $opts{handlers} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"handlers"} and ref $opts{"handlers"} eq "ARRAY" 7 6 13
Condition66%2/3
$opts{"handlers"} and ref $opts{"handlers"} eq "ARRAY"
!ll&&!rl&&r
706
MC/DC50%1/2
$opts{"handlers"} and ref $opts{"handlers"} eq "ARRAY"
$opts{"handlers"} ref $opts{"handlers"} eq "ARRAY"
Truth table66%2/3
A and B
A= $opts{"handlers"}B= ref $opts{"handlers"} eq "ARRAY"
ABresult
0X0
100
111
26 13 ▶ $opts{domains} = [ ] unless $opts{domains} and ref $opts{domains} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"domains"} and ref $opts{"domains"} eq "ARRAY" 12 1 13
Condition66%2/3
$opts{"domains"} and ref $opts{"domains"} eq "ARRAY"
!ll&&!rl&&r
1201
MC/DC50%1/2
$opts{"domains"} and ref $opts{"domains"} eq "ARRAY"
$opts{"domains"} ref $opts{"domains"} eq "ARRAY"
Truth table66%2/3
A and B
A= $opts{"domains"}B= ref $opts{"domains"} eq "ARRAY"
ABresult
0X0
100
111
27 13 ▶ $opts{simple} = 1 unless defined $opts{simple} and !$opts{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"simple"} and not $opts{"simple"} 10 3 13
Condition66%2/3
defined $opts{"simple"} and not $opts{"simple"}
!ll&&!rl&&r
1003
MC/DC50%1/2
defined $opts{"simple"} and not $opts{"simple"}
defined $opts{"simple"} not $opts{"simple"}
Truth table66%2/3
A and not(B)
A= defined $opts{"simple"}B= not $opts{"simple"}
ABresult
0X0
100
111
28 13 ▶ $opts{handle_connects} = 1 unless defined $opts{handle_connects} and !$opts{handle_connects};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"handle_connects"} and not $opts{"handle_connects"} 13 0 13
Condition33%1/3
defined $opts{"handle_connects"} and not $opts{"handle_connects"}
!ll&&!rl&&r
1300
MC/DC0%0/2
defined $opts{"handle_connects"} and not $opts{"handle_connects"}
defined $opts{"handle_connects"} not $opts{"handle_connects"}
Truth table33%1/3
A and not(B)
A= defined $opts{"handle_connects"}B= not $opts{"handle_connects"}
ABresult
0X0
100
111
29 13 ▶ $opts{hostname} = 'localhost' unless defined $opts{hostname};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"hostname"} 13 0 13
30 13 ▶ $opts{relay} = 0 unless $opts{relay};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"relay"} 13 0 13
31 13 ▶ $opts{origin} = 0 unless $opts{origin};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"origin"} 12 1 13
32 13 ▶ $opts{maxrelay} = 5 unless $opts{maxrelay};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"maxrelay"} 13 0 13
33 13 ▶ $opts{relay_auth} = 'PLAIN' if $opts{relay_auth};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"relay_auth"} 0 13 13
34 13 ▶ $opts{version} = join('-', __PACKAGE__, $POE::Component::Server::SimpleSMTP::VERSION ) unless $opts{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"version"} 13 0 13
35 13 my $self = bless \%opts, $package;
36 13 $self->_pluggable_init( prefix => 'smtpd_', types => [ 'SMTPD', 'SMTPC' ], debug => 1 );
37 13 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 13 0 13
38 object_states => [
39 $self => { shutdown => '_shutdown',
40 send_event => '__send_event',
41 send_to_client => '_send_to_client',
42 start_listener => '_start_listener',
43 },
44 $self => [ qw(_start register unregister _accept_client _accept_failed _conn_input _conn_error _conn_flushed _conn_alarm _send_to_client __send_event _process_queue _smtp_send_relay _smtp_send_mx _smtp_send_success _smtp_send_failure _process_dns_mx _fh_buffer _buffer_error _buffer_flush _dnsbl _sender_verify) ],
45 ],
46 heap => $self,
47 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
48 )->ID();
49 13 return $self;
50 }
51  
52 13 ▶sub session_id {
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
53 13 return $_[0]->{session_id};
54 }
55  
56 3 ▶sub mail_queue {
Subroutine mail_queue: called CC=1 SCAR=0.0
Pod documented
57 3 my $self = shift;
58 3 return map { { %$_ } } @{ $self->{_mail_queue} };
59 }
60  
61 0 ▶sub pause_queue {
Subroutine pause_queue: not called CC=1 SCAR=6.9
Pod documented
62 0 my $self = shift;
63 0 $self->{paused} = 1;
64 }
65  
66 2 ▶sub resume_queue {
Subroutine resume_queue: called CC=2 SCAR=7.1
Pod documented
67 2 my $self = shift;
68 2 my $pause = delete $self->{paused};
69 2 ▶ $poe_kernel->post( $self->{session_id}, '_process_queue' ) if $pause;
Branch: 1 branch
BranchTrueFalseTotal
if $pause 2 0 2
70 }
71  
72 2 ▶sub paused {
Subroutine paused: called CC=1 SCAR=0.0
Pod documented
73 2 return $_[0]->{paused};
74 }
75  
76 1 ▶sub cancel_message {
Subroutine cancel_message: called CC=5 SCAR=16.7
Pod documented
77 1 my $self = shift;
78 1 ▶ my $uid = shift || return;
Condition50%1/2
shift() || (return)
l!l
10
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
79 1 ▶ return unless scalar @{ $self->{_mail_queue} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"_mail_queue"};} 0 1 1
80 1 my $i = 0;
81 1 for ( @{ $self->{_mail_queue} } ) {
82 1 splice( @{ $self->{_mail_queue} }, $i, 1 ), last
83 1 ▶ if $_->{uid} eq $uid;
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"uid"} eq $uid 1 0 1
84 0 ++$i;
85 }
86 1 return 1;
87 }
88  
89 3 ▶sub data_mode {
Subroutine data_mode: called CC=5 SCAR=16.4
Pod documented
90 3 my $self = shift;
91 3 ▶ my $id = shift || return;
Condition50%1/2
shift() || (return)
l!l
30
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
92 3 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 3 3
93 3 my $handle = shift;
94 3 ▶ if ( $handle and $^O ne 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle and $^O ne 'MSWin32') { } 1 2 3
Condition66%2/3
$handle and $^O ne "MSWin32"
!ll&&!rl&&r
201
MC/DC50%1/2
$handle and $^O ne "MSWin32"
$handle $^O ne "MSWin32"
Truth table66%2/3
A and B
A= $handleB= $^O ne "MSWin32"
ABresult
0X0
100
111
95 1 $poe_kernel->call( $self->{session_id}, '_fh_buffer', $id, $handle );
96 }
97 else {
98 2 $self->{clients}->{ $id }->{buffer} = [ ];
99 }
100 3 return 1;
101 }
102  
103 12 ▶sub getsockname {
Subroutine getsockname: called CC=2 SCAR=7.2
Pod documented
104 12 ▶ return unless $_[0]->{listener};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"listener"} 0 12 12
105 12 return $_[0]->{listener}->getsockname();
106 }
107  
108 0 ▶sub get_handlers {
Subroutine get_handlers: not called CC=2 SCAR=17.9
Pod documented
109 0 my $self = shift;
110 0 my $handlers = Storable::dclone( $self->{handlers} );
111 0 delete $_->{RE} for @{ $handlers };
112 0 return $handlers;
113 }
114  
115 0 ▶sub set_handlers {
Subroutine set_handlers: not called CC=2 SCAR=17.9
Pod documented
116 0 my $self = shift;
117 0 ▶ my $handlers = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
118 0 _massage_handlers( $handlers );
119 0 $self->{handlers} = $handlers;
120 0 return 1;
121 }
122  
123 409 ▶sub _conn_exists {
Subroutine _conn_exists: called CC=3 SCAR=12.5
124 409 my ($self,$wheel_id) = @_;
125 409 ▶ return 0 unless $wheel_id and defined $self->{clients}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel_id and defined $self->{"clients"}{$wheel_id} 0 409 409
Condition33%1/3
$wheel_id and defined $self->{"clients"}{$wheel_id}
!ll&&!rl&&r
00409
MC/DC0%0/2
$wheel_id and defined $self->{"clients"}{$wheel_id}
$wheel_id defined $self->{"clients"}{$wheel_id}
Truth table33%1/3
A and B
A= $wheel_idB= defined $self->{"clients"}{$wheel_id}
ABresult
0X0
100
111
126 409 return 1;
127 }
128  
129 70 ▶sub _valid_cmd {
Subroutine _valid_cmd: called CC=3 SCAR=11.2
130 70 my $self = shift;
131 70 ▶ my $cmd = shift || return;
Condition50%1/2
shift() || (return)
l!l
700
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
132 70 $cmd = lc $cmd;
133 70 ▶ return 0 unless grep { $_ eq $cmd } @{ $self->{cmds} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cmd;} @{$$self{"cmds"};} 0 70 70
134 70 return 1;
135 }
136  
137 6 ▶sub _massage_handlers {
Subroutine _massage_handlers: called CC=13 SCAR=29.1
138 6 ▶ my $handler = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
139 6 ▶ croak( "HANDLERS is not a ref to an array!" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler and ref $handler eq "ARRAY" 0 6 6
Condition33%1/3
ref $handler and ref $handler eq "ARRAY"
!ll&&!rl&&r
006
MC/DC0%0/2
ref $handler and ref $handler eq "ARRAY"
ref $handler ref $handler eq "ARRAY"
Truth table33%1/3
A and B
A= ref $handlerB= ref $handler eq "ARRAY"
ABresult
0X0
100
111
140 unless ref $handler and ref $handler eq 'ARRAY';
141 6 my $count = 0;
142 6 ▶ while ( $count < scalar( @$handler ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < scalar @$handler) 6 6 12
143 6 ▶ if ( ref $handler->[ $count ] and ref( $handler->[ $count ] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handler->[$count] and ref $handler->[$count] eq 'HASH') { } 6 0 6
Condition33%1/3
ref $handler->[$count] and ref $handler->[$count] eq "HASH"
!ll&&!rl&&r
006
MC/DC0%0/2
ref $handler->[$count] and ref $handler->[$count] eq "HASH"
ref $handler->[$count] ref $handler->[$count] eq "HASH"
Truth table33%1/3
A and B
A= ref $handler->[$count]B= ref $handler->[$count] eq "HASH"
ABresult
0X0
100
111
144 $handler->[ $count ]->{ uc $_ } = delete $handler->[ $count ]->{ $_ }
145 6 for keys %{ $handler->[ $count ] };
146 croak( "HANDLER number $count does not have a SESSION argument!" )
147 6 ▶ unless $handler->[ $count ]->{'SESSION'};
Branch: 1 branch
BranchTrueFalseTotal
unless $handler->[$count]{"SESSION"} 0 6 6
148 croak( "HANDLER number $count does not have an EVENT argument!" )
149 6 ▶ unless $handler->[ $count ]->{'EVENT'};
Branch: 1 branch
BranchTrueFalseTotal
unless $handler->[$count]{"EVENT"} 0 6 6
150 croak( "HANDLER number $count does not have a MATCH argument!" )
151 6 ▶ unless $handler->[ $count ]->{'MATCH'};
Branch: 1 branch
BranchTrueFalseTotal
unless $handler->[$count]{"MATCH"} 0 6 6
152 $handler->[ $count ]->{'SESSION'} = $handler->[ $count ]->{'SESSION'}->ID()
153 6 ▶ if UNIVERSAL::isa( $handler->[ $count ]->{'SESSION'}, 'POE::Session' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($handler->[$count]{"SESSION"}, "POE::Session") 0 6 6
154 6 my $regex;
155 6 eval { $regex = qr/$handler->[ $count ]->{'MATCH'}/ };
156 6 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 6 6
157 0 croak( "HANDLER number $count has a malformed MATCH -> $@" );
158 }
159 else {
160 6 $handler->[ $count ]->{'RE'} = $regex;
161 }
162 }
163 else {
164 0 croak( "HANDLER number $count is not a reference to a HASH!" );
165 }
166 6 $count++;
167 }
168 6 return 1;
169 }
170  
171 13 ▶sub shutdown {
Subroutine shutdown: called CC=1 SCAR=0.0
Pod documented
172 13 my $self = shift;
173 13 $poe_kernel->post( $self->{session_id}, 'shutdown' );
174 }
175  
176 13 ▶sub _start {
Subroutine _start: called CC=6 SCAR=18.5
177 13 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
178 13 $self->{session_id} = $_[SESSION]->ID();
179 13 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 13 13
180 0 $kernel->alias_set( $self->{alias} );
181 }
182 else {
183 13 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
184 }
185 13 ▶ if ( $kernel != $sender ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kernel != $sender) 13 0 13
186 13 my $sender_id = $sender->ID;
187 13 $self->{events}->{'smtpd_all'}->{$sender_id} = $sender_id;
188 13 $self->{sessions}->{$sender_id}->{'ref'} = $sender_id;
189 13 $kernel->refcount_increment($sender_id, __PACKAGE__);
190 13 $kernel->post( $sender, 'smtpd_registered', $self );
191 }
192  
193 #$self->{filter} = POE::Filter::Line->new( Literal => "\015\012" );
194 13 $self->{filter} = POE::Filter::Transparent::SMTP->new(
195 InputLiteral => qq{\015\012},
196 OutputLiteral => qq{\015\012},
197 );
198  
199 13 $self->{cmds} = [ qw(ehlo helo mail rcpt data noop vrfy rset expn help quit) ];
200  
201 13 $kernel->call( $self->{session_id}, 'start_listener' );
202  
203 $self->{resolver} = POE::Component::Client::DNS->spawn()
204 13 ▶ unless $self->{resolver} and $self->{resolver}->isa('POE::Component::Client::DNS');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"resolver"} and $self->{"resolver"}->isa("POE::Component::Client::DNS") 13 0 13
Condition33%1/3
$self->{"resolver"} and $self->{"resolver"}->isa("POE::Component::Client::DNS")
!ll&&!rl&&r
1300
MC/DC0%0/2
$self->{"resolver"} and $self->{"resolver"}->isa("POE::Component::Client::DNS")
$self->{"resolver"} $self->{"resolver"}->isa("POE::Component::Client::DNS")
Truth table33%1/3
A and B
A= $self->{"resolver"}B= $self->{"resolver"}->isa("POE::Component::Client::DNS")
ABresult
0X0
100
111
205  
206 $self->{_dnsbl} = POE::Component::Client::DNSBL->spawn(
207 resolver => $self->{resolver},
208 dnsbl => $self->{dnsbl},
209 13 ▶ ) if $self->{dnsbl_enable};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dnsbl_enable"} 1 12 13
210  
211  
212 13 return;
213 }
214  
215 0 ▶sub start_listener {
Subroutine start_listener: not called CC=1 SCAR=6.9
Pod documented
216 0 my $self = shift;
217 0 $poe_kernel->post( $self->{session_id}, 'start_listener', @_ );
218 }
219  
220 13 ▶sub _start_listener {
Subroutine _start_listener: called CC=4 SCAR=16.4
221 13 my ($kernel,$self) = @_[KERNEL,OBJECT];
222 13 ▶ if ( $self->{listener} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"listener"}) 0 13 13
223 0 warn "Listener already started\n";
224 0 return;
225 }
226 $self->{listener} = POE::Wheel::SocketFactory->new(
227 ( defined $self->{address} ? ( BindAddress => $self->{address} ) : () ),
228 13 ▶ ( defined $self->{port} ? ( BindPort => $self->{port} ) : ( BindPort => 25 ) ),
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{'address'} ? : 13 0 13
defined $self->{'port'} ? : 13 0 13
229 SuccessEvent => '_accept_client',
230 FailureEvent => '_accept_failed',
231 SocketDomain => AF_INET, # Sets the socket() domain
232 SocketType => SOCK_STREAM, # Sets the socket() type
233 SocketProtocol => 'tcp', # Sets the socket() protocol
234 Reuse => 'on', # Lets the port be reused
235 );
236 13 return;
237 }
238  
239 12 ▶sub _accept_client {
Subroutine _accept_client: called CC=3 SCAR=11.0
240 12 my ($kernel,$self,$socket,$peeraddr,$peerport) = @_[KERNEL,OBJECT,ARG0..ARG2];
241 12 my $sockaddr = eval { inet_ntoa( ( sockaddr_in ( CORE::getsockname($socket)) )[1] ) };
242 12 my $sockport = eval { ( sockaddr_in ( CORE::getsockname($socket)) )[0] };
243 12 $peeraddr = inet_ntoa( $peeraddr );
244  
245 my $wheel = POE::Wheel::ReadWrite->new(
246 Handle => $socket,
247 Filter => $self->{filter},
248 12 InputEvent => '_conn_input',
249 ErrorEvent => '_conn_error',
250 FlushedEvent => '_conn_flushed',
251 );
252  
253 12 ▶ return unless $wheel;
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel 0 12 12
254
255 12 my $id = $wheel->ID();
256 12 $self->{clients}->{ $id } =
257 {
258 wheel => $wheel,
259 peeraddr => $peeraddr,
260 peerport => $peerport,
261 sockaddr => $sockaddr,
262 sockport => $sockport,
263 };
264 12 $self->_send_event( 'smtpd_connection', $id, $peeraddr, $peerport, $sockaddr, $sockport );
265  
266 12 ▶ $self->{clients}->{ $id }->{alarm} = $kernel->delay_set( '_conn_alarm', $self->{client_time_out} || 300, $id );
Condition100%2/2
$self->{'client_time_out'} || 300
l!l
111
MC/DC100%1/1
$self->{'client_time_out'} || 300
$self->{'client_time_out'}
Truth table100%2/2
A
A= $self->{'client_time_out'}
Aresult
11
00
267 12 return;
268 }
269  
270  
271 0 ▶sub _accept_failed {
Subroutine _accept_failed: not called CC=1 SCAR=6.9
272 0 my ($kernel,$self,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,OBJECT,ARG0..ARG3];
273 0 warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
274 0 delete $self->{listener};
275 0 $self->_send_event( 'smtpd_listener_failed', $operation, $errnum, $errstr );
276 0 return;
277 }
278  
279 134 ▶sub _conn_input {
Subroutine _conn_input: called CC=13 SCAR=25.7
280 134 my ($kernel,$self,$input,$id) = @_[KERNEL,OBJECT,ARG0,ARG1];
281 134 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 134 134
282 134 ▶ $kernel->delay_adjust( $self->{clients}->{ $id }->{alarm}, $self->{client_time_out} || 300 );
Condition100%2/2
$self->{'client_time_out'} || 300
l!l
1133
MC/DC100%1/1
$self->{'client_time_out'} || 300
$self->{'client_time_out'}
Truth table100%2/2
A
A= $self->{'client_time_out'}
Aresult
11
00
283 134 ▶ if ( $self->{clients}->{ $id }->{buffer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"clients"}{$id}{"buffer"}) 64 70 134
284 64 ▶ if ( $input eq '.' and $self->{simple} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($input eq '.' and $self->{'simple'}) { } 5 59 64
elsif ($input eq '.' and ref $self->{'clients'}{$id}{'buffer'} eq 'ARRAY') { } 2 57 59
elsif ($input eq '.') { } 1 56 57
Condition100%3/3
$input eq "." and $self->{"simple"}
!ll&&!rl&&r
5635
MC/DC100%2/2
$input eq "." and $self->{"simple"}
$input eq "." $self->{"simple"}
Truth table100%3/3
A and B
A= $input eq "."B= $self->{"simple"}
ABresult
0X0
100
111
285 5 my $mail = delete $self->{clients}->{ $id }->{mail};
286 5 my $rcpt = delete $self->{clients}->{ $id }->{rcpt};
287 5 my $buffer = delete $self->{clients}->{ $id }->{buffer};
288 5 $self->_send_event( 'smtpd_message', $id, $mail, $rcpt, $buffer );
289 5 return;
290 }
291 ▶ elsif ( $input eq '.' and ref( $self->{clients}->{ $id }->{buffer} ) eq 'ARRAY' ) {
Condition100%3/3
$input eq "." and ref $self->{"clients"}{$id}{"buffer"} eq "ARRAY"
!ll&&!rl&&r
5612
MC/DC100%2/2
$input eq "." and ref $self->{"clients"}{$id}{"buffer"} eq "ARRAY"
$input eq "." ref $self->{"clients"}{$id}{"buffer"} eq "ARRAY"
Truth table100%3/3
A and B
A= $input eq "."B= ref $self->{"clients"}{$id}{"buffer"} eq "ARRAY"
ABresult
0X0
100
111
292 2 my $buffer = delete $self->{clients}->{ $id }->{buffer};
293 2 $self->_send_event( 'smtpd_data', $id, $buffer );
294 2 return;
295 }
296 elsif ( $input eq '.' ) {
297 1 my $wheel_id = delete $self->{clients}->{ $id }->{buffer};
298 1 $self->{buffers}->{ $wheel_id }->{shutdown} = 1;
299 1 return;
300 }
301 56 ▶ if ( ref( $self->{clients}->{ $id }->{buffer} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'clients'}{$id}{'buffer'} eq 'ARRAY') { } 50 6 56
302 50 push @{ $self->{clients}->{ $id }->{buffer} }, $input;
303 }
304 else {
305 6 my $buffer = $self->{clients}->{ $id }->{buffer};
306 6 $self->{buffers}->{ $buffer }->{wheel}->put( $input );
307 }
308 56 return;
309 }
310 70 $input =~ s/^\s+//g;
311 70 $input =~ s/\s+$//g;
312 70 my @args = split /\s+/, $input, 2;
313 70 my $cmd = shift @args;
314 70 ▶ return unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 70 70
315 70 ▶ unless ( $self->_valid_cmd( $cmd ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_valid_cmd($cmd)) 0 70 70
316 0 $self->send_to_client( $id, "500 Syntax error, command unrecognized" );
317 0 return;
318 }
319 70 $cmd = lc $cmd;
320 70 ▶ if ( $cmd eq 'quit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "quit") 8 62 70
321 8 $self->{clients}->{ $id }->{quit} = 1;
322 8 $self->send_to_client( $id, '221 closing connection - goodbye!' );
323 8 return;
324 }
325 62 $self->_send_event( 'smtpd_cmd_' . $cmd, $id, @args );
326 62 return;
327 }
328  
329 0 ▶sub _conn_error {
Subroutine _conn_error: not called CC=2 SCAR=17.9
330 0 my ($self,$errstr,$id) = @_[OBJECT,ARG2,ARG3];
331 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
332 0 delete $self->{clients}->{ $id };
333 0 $self->_send_event( 'smtpd_disconnected', $id );
334 0 return;
335 }
336  
337 90 ▶sub _conn_flushed {
Subroutine _conn_flushed: called CC=3 SCAR=11.0
338 90 my ($self,$id) = @_[OBJECT,ARG0];
339 90 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 90 90
340 90 ▶ return unless $self->{clients}->{ $id }->{quit};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"clients"}{$id}{"quit"} 82 8 90
341 8 delete $self->{clients}->{ $id };
342 8 $self->_send_event( 'smtpd_disconnected', $id );
343 8 return;
344 }
345  
346 1 ▶sub _conn_alarm {
Subroutine _conn_alarm: called CC=2 SCAR=7.0
347 1 my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
348 1 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 1 1
349 1 delete $self->{clients}->{ $id };
350 1 $self->_send_event( 'smtpd_disconnected', $id );
351 1 return;
352 }
353  
354 13 ▶sub _shutdown {
Subroutine _shutdown: called CC=4 SCAR=13.9
355 13 my ($kernel,$self) = @_[KERNEL,OBJECT];
356 13 delete $self->{listener};
357 13 delete $self->{clients};
358 13 delete $self->{buffers};
359 13 $kernel->alarm_remove_all();
360 13 $kernel->alias_remove( $_ ) for $kernel->alias_list();
361 13 ▶ $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 13 0 13
362 13 $self->_pluggable_destroy();
363 13 $self->_unregister_sessions();
364 13 ▶ $self->{_dnsbl}->shutdown() if $self->{dnsbl_enable};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dnsbl_enable"} 1 12 13
365 13 $self->{resolver}->shutdown();
366 13 undef;
367 }
368  
369 1 ▶sub _fh_buffer {
Subroutine _fh_buffer: called CC=2 SCAR=7.0
370 1 my ($kernel,$self,$id,$handle) = @_[KERNEL,OBJECT,ARG0,ARG1];
371 1 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 1 1
372 1 my $wheel = POE::Wheel::ReadWrite->new(
373 Handle => $handle,
374 FlushedEvent => '_buffer_flush',
375 ErrorEvent => '_buffer_error',
376 );
377 1 my $wheel_id = $wheel->ID();
378 1 $self->{clients}->{ $id }->{buffer} = $wheel_id;
379 1 $self->{buffers}->{ $wheel_id } = { wheel => $wheel, id => $id };
380 1 return;
381 }
382  
383 1 ▶sub _buffer_flush {
Subroutine _buffer_flush: called CC=2 SCAR=7.0
384 1 my ($self,$wheel_id) = @_[OBJECT,ARG0];
385 1 ▶ return unless $self->{buffers}->{ $wheel_id }->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"buffers"}{$wheel_id}{"shutdown"} 0 1 1
386 1 my $data = delete $self->{buffers}->{ $wheel_id };
387 1 my $id = delete $data->{id};
388 1 $self->send_event( 'smtpd_data_fh', $id );
389 1 return;
390 }
391  
392 0 ▶sub _buffer_error {
Subroutine _buffer_error: not called CC=1 SCAR=6.9
393 0 my ($kernel,$self,$error,$wheel_id) = @_[KERNEL,OBJECT,ARG1,ARG3];
394 0 return;
395 }
396  
397 0 ▶sub register {
Subroutine register: not called CC=6 SCAR=37.4
Pod documented
398 0 my ($kernel, $self, $session, $sender, @events) =
399 @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_];
400  
401 0 ▶ unless (@events) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@events) 0 0 0
402 0 warn "register: Not enough arguments";
403 0 return;
404 }
405  
406 0 my $sender_id = $sender->ID();
407  
408 0 foreach (@events) {
409 0 ▶ $_ = "smtpd_" . $_ unless /^_/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 0 0 0
410 0 $self->{events}->{$_}->{$sender_id} = $sender_id;
411 0 $self->{sessions}->{$sender_id}->{'ref'} = $sender_id;
412 0 ▶ unless ($self->{sessions}->{$sender_id}->{refcnt}++ or $session == $sender) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender) 0 0 0
Condition0%0/3
$self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender
$self->{"sessions"}{$sender_id}{"refcnt"}++ $session == $sender
Truth table0%0/3
A or B
A= $self->{"sessions"}{$sender_id}{"refcnt"}++B= $session == $sender
ABresult
1X1
011
000
413 0 $kernel->refcount_increment($sender_id, __PACKAGE__);
414 }
415 }
416  
417 0 $kernel->post( $sender, 'smtpd_registered', $self );
418 0 return;
419 }
420  
421 0 ▶sub unregister {
Subroutine unregister: not called CC=2 SCAR=17.9
Pod documented
422 0 my ($kernel, $self, $session, $sender, @events) =
423 @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_];
424  
425 0 ▶ unless (@events) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@events) 0 0 0
426 0 warn "unregister: Not enough arguments";
427 0 return;
428 }
429  
430 0 $self->_unregister($session,$sender,@events);
431 0 undef;
432 }
433  
434 0 ▶sub _unregister {
Subroutine _unregister: not called CC=6 SCAR=37.4
435 0 my ($self,$session,$sender) = splice @_,0,3;
436 0 my $sender_id = $sender->ID();
437  
438 0 foreach (@_) {
439 0 ▶ $_ = "smtpd_" . $_ unless /^_/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 0 0 0
440 0 my $blah = delete $self->{events}->{$_}->{$sender_id};
441 0 ▶ unless ( $blah ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blah) 0 0 0
442 0 warn "$sender_id hasn't registered for '$_' events\n";
443 0 next;
444 }
445 0 ▶ if (--$self->{sessions}->{$sender_id}->{refcnt} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"sessions"}{$sender_id}{"refcnt"} <= 0) 0 0 0
446 0 delete $self->{sessions}->{$sender_id};
447 0 ▶ unless ($session == $sender) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session == $sender) 0 0 0
448 0 $poe_kernel->refcount_decrement($sender_id, __PACKAGE__);
449 }
450 }
451 }
452 0 undef;
453 }
454  
455 13 ▶sub _unregister_sessions {
Subroutine _unregister_sessions: called CC=4 SCAR=14.1
456 13 my $self = shift;
457 13 my $smtpd_id = $self->session_id();
458 13 foreach my $session_id ( keys %{ $self->{sessions} } ) {
459 13 ▶ if (--$self->{sessions}->{$session_id}->{refcnt} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"sessions"}{$session_id}{"refcnt"} <= 0) 13 0 13
460 13 delete $self->{sessions}->{$session_id};
461 13 ▶ $poe_kernel->refcount_decrement($session_id, __PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
unless $session_id eq $smtpd_id 13 0 13
462 unless ( $session_id eq $smtpd_id );
463 }
464 }
465 }
466  
467 6 ▶sub __send_event {
Subroutine __send_event: called CC=1 SCAR=0.0
468 6 my( $self, $event, @args ) = @_[ OBJECT, ARG0, ARG1 .. $#_ ];
469 6 $self->_send_event( $event, @args );
470 6 return;
471 }
472  
473 0 ▶sub _pluggable_event {
Subroutine _pluggable_event: not called CC=1 SCAR=6.9
474 0 my $self = shift;
475 0 $poe_kernel->post( $self->{session_id}, '__send_event', @_ );
476 }
477  
478 6 ▶sub send_event {
Subroutine send_event: called CC=1 SCAR=0.0
Pod documented
479 6 my $self = shift;
480 6 $poe_kernel->post( $self->{session_id}, '__send_event', @_ );
481 }
482  
483 97 ▶sub _send_event {
Subroutine _send_event: called CC=5 SCAR=16.1
484 97 my $self = shift;
485 97 my ($event, @args) = @_;
486 97 my $kernel = $POE::Kernel::poe_kernel;
487 97 my $session = $kernel->get_active_session()->ID();
488 97 my %sessions;
489  
490 my @extra_args;
491  
492 97 ▶ return 1 if $self->_pluggable_process( 'SMTPD', $event, \( @args ), \@extra_args ) == PLUGIN_EAT_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_pluggable_process("SMTPD", $event, \(@args), \@extra_args) == 4 55 42 97
493  
494 42 ▶ push @args, @extra_args if scalar @extra_args;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @extra_args 0 42 42
495  
496 42 $sessions{$_} = $_ for (values %{$self->{events}->{'smtpd_all'}}, values %{$self->{events}->{$event}});
497  
498 42 $kernel->post( $_ => $event => @args ) for values %sessions;
499 42 undef;
500 }
501  
502 90 ▶sub send_to_client {
Subroutine send_to_client: called CC=1 SCAR=0.0
Pod documented
503 90 my $self = shift;
504 90 $poe_kernel->call( $self->{session_id}, '_send_to_client', @_ );
505 }
506  
507 90 ▶sub _send_to_client {
Subroutine _send_to_client: called CC=6 SCAR=19.9
508 90 my ($kernel,$self,$id,$output) = @_[KERNEL,OBJECT,ARG0..ARG1];
509 90 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 90 90
510 90 ▶ return unless $output;
Branch: 1 branch
BranchTrueFalseTotal
unless $output 0 90 90
511  
512 90 ▶ return 1 if $self->_pluggable_process( 'SMTPC', 'response', $id, \$output ) == PLUGIN_EAT_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_pluggable_process("SMTPC", "response", $id, \$output) == 4 0 90 90
513  
514 90 ▶ return unless $self->_conn_exists( $id ) and defined $self->{clients}->{ $id }->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) and defined $self->{"clients"}{$id}{"wheel"} 0 90 90
Condition33%1/3
$self->_conn_exists($id) and defined $self->{"clients"}{$id}{"wheel"}
!ll&&!rl&&r
0090
MC/DC0%0/2
$self->_conn_exists($id) and defined $self->{"clients"}{$id}{"wheel"}
$self->_conn_exists($id) defined $self->{"clients"}{$id}{"wheel"}
Truth table33%1/3
A and B
A= $self->_conn_exists($id)B= defined $self->{"clients"}{$id}{"wheel"}
ABresult
0X0
100
111
515 90 $self->{clients}->{ $id }->{wheel}->put($output);
516 90 return 1;
517 }
518  
519 5 ▶sub _check_recipient {
Subroutine _check_recipient: called CC=4 SCAR=14.9
520 5 my $self = shift;
521 5 ▶ my $recipient = shift || return;
Condition50%1/2
shift() || (return)
l!l
50
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
522 5 foreach my $handler ( @{ $self->{handlers} } ) {
523 5 ▶ return $handler if $recipient =~ $handler->{RE};
Branch: 1 branch
BranchTrueFalseTotal
if $recipient =~ /$handler->{"RE"}/ 5 0 5
524 }
525 0 return;
526 }
527  
528 8 ▶sub _process_queue {
Subroutine _process_queue: called CC=10 SCAR=28.1
529 8 my ($kernel,$self) = @_[KERNEL,OBJECT];
530 8 ▶ return if $self->{paused};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"paused"} 2 6 8
531 6 ▶ return if $self->{_smtp_clients} and $self->{_smtp_clients} >= $self->{maxrelay};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_smtp_clients"} and $self->{"_smtp_clients"} >= $self->{"maxrelay"} 0 6 6
Condition33%1/3
$self->{"_smtp_clients"} and $self->{"_smtp_clients"} >= $self->{"maxrelay"}
!ll&&!rl&&r
600
MC/DC0%0/2
$self->{"_smtp_clients"} and $self->{"_smtp_clients"} >= $self->{"maxrelay"}
$self->{"_smtp_clients"} $self->{"_smtp_clients"} >= $self->{"maxrelay"}
Truth table33%1/3
A and B
A= $self->{"_smtp_clients"}B= $self->{"_smtp_clients"} >= $self->{"maxrelay"}
ABresult
0X0
100
111
532 6 my $item = shift @{ $self->{_mail_queue} };
533 6 $kernel->delay_set( '_process_queue', 120 );
534 6 ▶ return unless $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 1 5 6
535 5 $item->{attempt}++;
536 # Process Recipient Handlers here
537 5 ▶ if ( $self->{relay} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"relay"}) 0 5 5
538 0 $kernel->yield( '_smtp_send_relay', $item );
539 0 return;
540 }
541 5 my %domains;
542 5 foreach my $recipient ( @{ $item->{rcpt} } ) {
543 5 ▶ if ( my $handler = $self->_check_recipient( $recipient ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $self->_check_recipient($recipient)) 5 0 5
544 5 $kernel->post( $handler->{'SESSION'}, $handler->{'EVENT'}, $item );
545 5 next;
546 }
547 0 my $host = Email::Address->new(undef,$recipient,undef)->host();
548 0 push @{ $domains{ $host } }, $recipient;
549 }
550 5 foreach my $domain ( keys %domains ) {
551 0 my $copy = { %{ $item } };
552 0 $copy->{rcpt} = $domains{ $domain };
553 my $response = $self->{resolver}->resolve(
554 0 event => '_process_dns_mx',
555 type => 'MX',
556 host => $domain,
557 context => $copy,
558 );
559 0 ▶ $kernel->yield( '_process_dns_mx', $response ) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
560 }
561 5 return;
562 }
563  
564 0 ▶sub _process_dns_mx {
Subroutine _process_dns_mx: not called CC=4 SCAR=30.0
565 0 my ($kernel,$self,$response) = @_[KERNEL,OBJECT,ARG0];
566 0 my $item = $response->{context};
567 0 ▶ unless ( $response->{response} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"response"}) 0 0 0
568 0 ▶ if ( time() - $item->{ts} > 345600 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $item->{"ts"} > 345600) 0 0 0
569 0 return;
570 }
571 0 push @{ $self->{_mail_queue} }, $item;
572 0 return;
573 }
574 0 my @answers = $response->{response}->answer();
575 0 my %mx = map { ( $_->exchange(), $_->preference() ) }
576 0 grep { $_->type() eq 'MX' } @answers;
577 0 my @mx = sort { $mx{$a} <=> $mx{$b} } keys %mx;
578 0 ▶ push @mx, $response->{host} unless scalar @mx;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @mx 0 0 0
579 0 $item->{mx} = \@mx;
580 0 $kernel->yield( '_smtp_send_mx', $item );
581 0 return;
582 }
583  
584 0 ▶sub _smtp_send_mx {
Subroutine _smtp_send_mx: not called CC=2 SCAR=17.9
585 0 my ($kernel,$self,$item) = @_[KERNEL,OBJECT,ARG0];
586 0 $item->{count}++;
587 0 my $exchange = shift @{ $item->{mx} };
588 0 push @{ $item->{mx} }, $exchange;
589 0 $self->{_smtp_clients}++;
590 POE::Component::Client::SMTP->send(
591 From => $item->{from},
592 To => $item->{rcpt},
593 Body => $item->{msg},
594 Server => $exchange,
595 Context => $item,
596 Debug => $self->{smtpc_debug},
597 Timeout => $self->{time_out} || 300,
598 MyHostname => $self->{hostname},
599 0 ▶ SMTP_Success => '_smtp_send_success',
Condition0%0/2
$self->{'time_out'} || 300
l!l
00
MC/DC0%0/1
$self->{'time_out'} || 300
$self->{'time_out'}
Truth table0%0/2
A
A= $self->{'time_out'}
Aresult
11
00
600 SMTP_Failure => '_smtp_send_failure',
601 );
602 0 return;
603 }
604  
605 0 ▶sub _smtp_send_relay {
Subroutine _smtp_send_relay: not called CC=6 SCAR=37.4
606 0 my ($kernel,$self,$item) = @_[KERNEL,OBJECT,ARG0];
607 0 $item->{count}++;
608 0 my %auth;
609 0 ▶ if ( $self->{relay_user} and $self->{relay_pass} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"relay_user"} and $self->{"relay_pass"}) 0 0 0
Condition0%0/3
$self->{"relay_user"} and $self->{"relay_pass"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"relay_user"} and $self->{"relay_pass"}
$self->{"relay_user"} $self->{"relay_pass"}
Truth table0%0/3
A and B
A= $self->{"relay_user"}B= $self->{"relay_pass"}
ABresult
0X0
100
111
610 $auth{mechanism} = $self->{relay_auth} || 'PLAIN',
611 $auth{user} = $self->{relay_user},
612 $auth{pass} = $self->{relay_pass},
613 0 ▶ }
Condition0%0/2
$self->{'relay_auth'} || 'PLAIN'
l!l
00
MC/DC0%0/1
$self->{'relay_auth'} || 'PLAIN'
$self->{'relay_auth'}
Truth table0%0/2
A
A= $self->{'relay_auth'}
Aresult
11
00
614 0 $self->{_smtp_clients}++;
615 POE::Component::Client::SMTP->send(
616 From => $item->{from},
617 To => $item->{rcpt},
618 Body => $item->{msg},
619 Server => $self->{relay},
620 Context => $item,
621 Timeout => $self->{time_out} || 300,
622 MyHostname => $self->{hostname},
623 0 ▶ SMTP_Success => '_smtp_send_success',
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %auth ? : 0 0 0
Condition0%0/2
$self->{'time_out'} || 300
l!l
00
MC/DC0%0/1
$self->{'time_out'} || 300
$self->{'time_out'}
Truth table0%0/2
A
A= $self->{'time_out'}
Aresult
11
00
624 SMTP_Failure => '_smtp_send_failure',
625 ( scalar keys %auth ? ( Auth => \%auth ) : () ),
626 );
627 0 return;
628 }
629  
630 0 ▶sub _smtp_send_success {
Subroutine _smtp_send_success: not called CC=1 SCAR=6.9
631 0 my ($kernel,$self,$item) = @_[KERNEL,OBJECT,ARG0];
632 0 $self->send_event( 'smtpd_send_success', $item->{uid} );
633 0 $kernel->delay_set( '_process_queue', 20 );
634 0 $self->{_smtp_clients}--;
635 0 return;
636 }
637  
638 0 ▶sub _smtp_send_failure {
Subroutine _smtp_send_failure: not called CC=4 SCAR=30.0
639 0 my ($kernel,$self,$item,$error) = @_[KERNEL,OBJECT,ARG0,ARG1];
640 0 $self->send_event( 'smtpd_send_failed', $item->{uid}, $error );
641 0 $self->{_smtp_clients}--;
642 0 ▶ if ( $error->{SMTP_Server_Error} and $error->{SMTP_Server_Error} =~ /^5/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"SMTP_Server_Error"} and $error->{"SMTP_Server_Error"} =~ /^5/) 0 0 0
Condition0%0/3
$error->{"SMTP_Server_Error"} and $error->{"SMTP_Server_Error"} =~ /^5/
!ll&&!rl&&r
000
MC/DC0%0/2
$error->{"SMTP_Server_Error"} and $error->{"SMTP_Server_Error"} =~ /^5/
$error->{"SMTP_Server_Error"} $error->{"SMTP_Server_Error"} =~ /^5/
Truth table0%0/3
A and B
A= $error->{"SMTP_Server_Error"}B= $error->{"SMTP_Server_Error"} =~ /^5/
ABresult
0X0
100
111
643 0 return;
644 }
645 0 ▶ if ( time() - $item->{ts} > 345600 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $item->{"ts"} > 345600) 0 0 0
646 0 return;
647 }
648 0 push @{ $self->{_mail_queue} }, $item;
649 0 $kernel->delay_set( '_process_queue', 20 );
650 0 return;
651 }
652  
653 12 ▶sub SMTPD_connection {
Subroutine SMTPD_connection: called CC=3 SCAR=11.0
Pod undocumented
654 12 my ($self,$smtpd) = splice @_, 0, 2;
655 12 my $id = ${ $_[0] };
656 12 my $peeraddr = ${ $_[1] };
657 12 ▶ return PLUGIN_EAT_NONE unless $self->{handle_connects};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"handle_connects"} 0 12 12
658 12 ▶ unless ( $self->{dnsbl_enable} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dnsbl_enable'}) { } 1 11 12
659 11 $self->send_to_client( $id, join( ' ', '220', $self->{hostname}, $self->{version}, 'ready' ) );
660 }
661 else {
662 1 $self->{_dnsbl}->lookup( session => $self->{session_id}, event => '_dnsbl', address => $peeraddr, _id => $id );
663 }
664 12 return PLUGIN_EAT_NONE;
665 }
666  
667 1 ▶sub _dnsbl {
Subroutine _dnsbl: called CC=4 SCAR=14.2
668 1 my ($kernel,$self,$data) = @_[KERNEL,OBJECT,ARG0];
669 1 my $id = delete $data->{_id};
670 1 delete $data->{$_} for qw(event session);
671 1 my $to_client = join ' ', '220', $self->{hostname}, $self->{version}, 'ready';
672 1 ▶ if ( $data->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'error'}) { } 0 1 1
673 0 $self->{clients}->{ $id }->{dnsbl} = 'NXDOMAIN';
674 }
675 else {
676 1 $self->{clients}->{ $id }->{dnsbl} = $data->{response};
677 1 ▶ $to_client = '554 No SMTP service here' if $data->{response} ne 'NXDOMAIN';
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"response"} ne "NXDOMAIN" 0 1 1
678 }
679 1 $self->send_to_client( $id, $to_client );
680 1 $self->_send_event( 'smtpd_dnsbl', $id, $to_client, $data );
681 1 return;
682 }
683  
684 0 ▶sub _sender_verify {
Subroutine _sender_verify: not called CC=4 SCAR=30.0
685 0 my ($kernel,$self,$data) = @_[KERNEL,OBJECT,ARG0];
686 0 ▶ if ( $data->{error} and $data->{error} eq 'NOERROR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"error"} and $data->{"error"} eq "NOERROR") 0 0 0
Condition0%0/3
$data->{"error"} and $data->{"error"} eq "NOERROR"
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{"error"} and $data->{"error"} eq "NOERROR"
$data->{"error"} $data->{"error"} eq "NOERROR"
Truth table0%0/3
A and B
A= $data->{"error"}B= $data->{"error"} eq "NOERROR"
ABresult
0X0
100
111
687 0 my @answers = $data->{response}->answer();
688 0 ▶ return if scalar @answers;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @answers 0 0 0
689 0 $data->{error} = 'NXDOMAIN';
690 }
691 0 my $id = delete $data->{context};
692 0 $self->{clients}->{ $id }->{fverify} = $data->{error};
693 0 return;
694 }
695  
696 4 ▶sub SMTPD_cmd_helo {
Subroutine SMTPD_cmd_helo: called CC=2 SCAR=6.9
Pod undocumented
697 4 my ($self,$smtpd) = splice @_, 0, 2;
698 4 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 3 1 4
699 1 my $id = ${ $_[0] };
700 1 $self->send_to_client( $id, '250 OK' );
701 1 return PLUGIN_EAT_ALL;
702 }
703  
704 0 ▶sub SMTPD_cmd_ehlo {
Subroutine SMTPD_cmd_ehlo: not called CC=2 SCAR=17.9
Pod undocumented
705 0 my ($self,$smtpd) = splice @_, 0, 2;
706 0 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 0 0
707 0 my $id = ${ $_[0] };
708 0 $self->send_to_client( $id, '250 ' . $self->{hostname} . ' Hello [' . $self->{clients}->{ $id }->{peeraddr} . '], pleased to meet you' );
709 0 return PLUGIN_EAT_ALL;
710 }
711  
712 11 ▶sub SMTPD_cmd_mail {
Subroutine SMTPD_cmd_mail: called CC=11 SCAR=30.7
Pod undocumented
713 11 my ($self,$smtpd) = splice @_, 0, 2;
714 11 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 3 8 11
715 8 my $id = ${ $_[0] };
716 8 my $args = ${ $_[1] };
717 8 my $response;
718 8 ▶ if ( $self->{dnsbl_enable} and ( !$self->{clients}->{ $id }->{dnsbl} or $self->{clients}->{ $id }->{dnsbl} ne 'NXDOMAIN' ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'dnsbl_enable'} and !$self->{'clients'}{$id}{'dnsbl'} || $self->{'clients'}{$id}{'dnsbl'} ne 'NXDOMAIN') { } 0 8 8
elsif ($self->{'clients'}{$id}{'mail'}) { } 0 8 8
elsif (my($from) = $args =~ /^from:\s*<(.+)>/i) { } 8 0 8
Condition50%3/6
$self->{"dnsbl_enable"} and !$self->{"clients"}{$id}{"dnsbl"} || $self->{"clients"}{$id}{"dnsbl"} ne "NXDOMAIN"
!ll&&!rl&&r
710
not $self->{"clients"}{$id}{"dnsbl"} or $self->{"clients"}{$id}{"dnsbl"} ne "NXDOMAIN"
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->{"dnsbl_enable"} and !$self->{"clients"}{$id}{"dnsbl"} || $self->{"clients"}{$id}{"dnsbl"} ne "NXDOMAIN"
$self->{"dnsbl_enable"} not $self->{"clients"}{$id}{"dnsbl"} $self->{"clients"}{$id}{"dnsbl"} ne "NXDOMAIN"
Truth table50%2/4
A and not(B) or C
A= $self->{"dnsbl_enable"}B= not $self->{"clients"}{$id}{"dnsbl"}C= $self->{"clients"}{$id}{"dnsbl"} ne "NXDOMAIN"
ABCresult
0XX0
1000
11X1
1011
719 0 $response = '503 bad sequence of commands';
720 }
721 elsif ( $self->{clients}->{ $id }->{mail} ) {
722 0 $response = '503 Sender already specified';
723 }
724 elsif ( my ($from) = $args =~ /^from:\s*<(.+)>/i ) {
725 8 ▶ if ( my $host = Email::Address->new(undef,$from,undef)->host() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = 'Email::Address'->new(undef, $from, undef)->host) { } 8 0 8
726 8 $response = "250 <$from>... Sender OK";
727 8 $self->{clients}->{ $id }->{mail} = $from;
728 8 ▶ if ( $self->{sender_verify} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sender_verify"}) 0 8 8
729 my $response = $self->{resolver}->resolve(
730 0 event => '_sender_verify',
731 type => 'MX',
732 host => $host,
733 context => $id,
734 );
735 0 ▶ $poe_kernel->post( $self->{session_id}, '_sender_verify', $response ) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
736 }
737 }
738 else {
739 0 $response = "501 Sender address must contain a domain";
740 }
741 }
742 else {
743 0 ▶ $args = '' unless $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $args 0 0 0
744 0 $response = "501 Syntax error in parameters scanning '$args'";
745 }
746 8 $self->send_to_client( $id, $response );
747 8 return PLUGIN_EAT_ALL;
748 }
749  
750 15 ▶sub SMTPD_cmd_rcpt {
Subroutine SMTPD_cmd_rcpt: called CC=9 SCAR=27.4
Pod undocumented
751 15 my ($self,$smtpd) = splice @_, 0, 2;
752 15 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 3 12 15
753 12 my $id = ${ $_[0] };
754 12 my $args = ${ $_[1] };
755 12 my $response;
756 12 ▶ if ( !$self->{clients}->{ $id }->{mail} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $self->{'clients'}{$id}{'mail'}) { } 2 10 12
elsif ($self->{'sender_verify'} and defined $self->{'clients'}{$id}{'fverify'}) { } 0 10 10
elsif (my($to) = $args =~ /^to:\s*<(.+)>/i) { } 10 0 10
757 2 $response = '503 Need MAIL before RCPT';
758 }
759 ▶ elsif ( $self->{sender_verify} and defined $self->{clients}->{ $id }->{fverify} ) {
Condition33%1/3
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
$self->{"sender_verify"} defined $self->{"clients"}{$id}{"fverify"}
Truth table33%1/3
A and B
A= $self->{"sender_verify"}B= defined $self->{"clients"}{$id}{"fverify"}
ABresult
0X0
100
111
760 0 my $fverify = uc $self->{clients}->{ $id }->{fverify};
761 0 ▶ if ( $fverify eq 'NXDOMAIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fverify eq 'NXDOMAIN') { } 0 0 0
762 0 $response = '550 Sender verify failed';
763 }
764 else {
765 0 $response = '451 Temporary local problem - please try later';
766 }
767 0 delete $self->{clients}->{ $id }->{mail};
768 0 delete $self->{clients}->{ $id }->{rcpt};
769 0 delete $self->{clients}->{ $id }->{buffer};
770 0 delete $self->{clients}->{ $id }->{fverify};
771 0 $self->_send_event( 'smtpd_fverify', $id, $response, $fverify );
772 }
773 elsif ( my ($to) = $args =~ /^to:\s*<(.+)>/i ) {
774 # TODO scan through $self->{domains} and reject as necessary.
775 10 ▶ unless ( $self->_recipient_domain( $to ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_recipient_domain($to)) { } 9 1 10
776 1 $response = "550 #5.1.0 Address rejected $to";
777 }
778 else {
779 9 $response = "250 <$to>... Recipient OK";
780 9 push @{ $self->{clients}->{ $id }->{rcpt} }, $to;
781 }
782 }
783 else {
784 0 ▶ $args = '' unless $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $args 0 0 0
785 0 $response = "501 Syntax error in parameters scanning '$args'";
786 }
787 12 $self->send_to_client( $id, $response );
788 12 return PLUGIN_EAT_ALL;
789 }
790  
791 10 ▶sub _recipient_domain {
Subroutine _recipient_domain: called CC=5 SCAR=16.2
792 10 my $self = shift;
793 10 ▶ return 1 unless scalar @{ $self->{domains} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"domains"};} 7 3 10
794 3 ▶ my $address = shift || return;
Condition50%1/2
shift() || (return)
l!l
30
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
795 3 my $hostpart = ( split /\@/, $address )[-1];
796 3 ▶ return unless $hostpart;
Branch: 1 branch
BranchTrueFalseTotal
unless $hostpart 0 3 3
797 3 ▶ return 1 if grep { uc $_ eq uc $hostpart } @{ $self->{domains} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {uc $_ eq uc $hostpart;} @{$$self{"domains"};} 2 1 3
798 1 return 0;
799 }
800  
801 8 ▶sub SMTPD_cmd_data {
Subroutine SMTPD_cmd_data: called CC=7 SCAR=26.6
Pod undocumented
802 8 my ($self,$smtpd) = splice @_, 0, 2;
803 8 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 3 5 8
804 5 my $id = ${ $_[0] };
805 5 my $response;
806 5 ▶ if ( !$self->{clients}->{ $id }->{mail} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $self->{'clients'}{$id}{'mail'}) { } 0 5 5
elsif (not $self->{'clients'}{$id}{'rcpt'}) { } 0 5 5
elsif ($self->{'sender_verify'} and defined $self->{'clients'}{$id}{'fverify'}) { } 0 5 5
807 0 $response = '503 Need MAIL command';
808 }
809 elsif ( !$self->{clients}->{ $id }->{rcpt} ) {
810 0 $response = '503 Need RCPT (recipient)';
811 }
812 ▶ elsif ( $self->{sender_verify} and defined $self->{clients}->{ $id }->{fverify} ) {
Condition33%1/3
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
$self->{"sender_verify"} defined $self->{"clients"}{$id}{"fverify"}
Truth table33%1/3
A and B
A= $self->{"sender_verify"}B= defined $self->{"clients"}{$id}{"fverify"}
ABresult
0X0
100
111
813 0 my $fverify = uc $self->{clients}->{ $id }->{fverify};
814 0 ▶ if ( $fverify eq 'NXDOMAIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fverify eq 'NXDOMAIN') { } 0 0 0
815 0 $response = '550 Sender verify failed';
816 }
817 else {
818 0 $response = '451 Temporary local problem - please try later';
819 }
820 0 delete $self->{clients}->{ $id }->{mail};
821 0 delete $self->{clients}->{ $id }->{rcpt};
822 0 delete $self->{clients}->{ $id }->{buffer};
823 0 delete $self->{clients}->{ $id }->{fverify};
824 0 $self->_send_event( 'smtpd_fverify', $id, $response, $fverify );
825 }
826 else {
827 5 $response = '354 Enter mail, end with "." on a line by itself';
828 5 $self->{clients}->{ $id }->{buffer} = [ ];
829 }
830 5 $self->send_to_client( $id, $response );
831 5 return PLUGIN_EAT_ALL;
832 }
833  
834 8 ▶sub SMTPD_cmd_noop {
Subroutine SMTPD_cmd_noop: called CC=2 SCAR=7.0
Pod undocumented
835 8 my ($self,$smtpd) = splice @_, 0, 2;
836 8 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 8 8
837 8 my $id = ${ $_[0] };
838 8 $self->send_to_client( $id, '250 OK' );
839 8 return PLUGIN_EAT_ALL;
840 }
841  
842 7 ▶sub SMTPD_cmd_expn {
Subroutine SMTPD_cmd_expn: called CC=2 SCAR=7.0
Pod undocumented
843 7 my ($self,$smtpd) = splice @_, 0, 2;
844 7 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 7 7
845 7 my $id = ${ $_[0] };
846 7 $self->send_to_client( $id, '502 Command not implemented; unsupported operation (EXPN)' );
847 7 return PLUGIN_EAT_ALL;
848 }
849  
850 7 ▶sub SMTPD_cmd_vrfy {
Subroutine SMTPD_cmd_vrfy: called CC=2 SCAR=7.0
Pod undocumented
851 7 my ($self,$smtpd) = splice @_, 0, 2;
852 7 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 7 7
853 7 my $id = ${ $_[0] };
854 7 $self->send_to_client( $id, '252 Cannot VRFY user, but will accept message for delivery' );
855 7 return PLUGIN_EAT_ALL;
856 }
857  
858 2 ▶sub SMTPD_cmd_rset {
Subroutine SMTPD_cmd_rset: called CC=3 SCAR=11.0
Pod undocumented
859 2 my ($self,$smtpd) = splice @_, 0, 2;
860 2 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 2 2
861 2 my $id = ${ $_[0] };
862 2 delete $self->{clients}->{$id}->{$_} for qw(mail rcpt buffer);
863 2 $self->send_to_client( $id, '250 Reset state' );
864 2 return PLUGIN_EAT_ALL;
865 }
866  
867 5 ▶sub SMTPD_message {
Subroutine SMTPD_message: called CC=11 SCAR=26.8
Pod undocumented
868 5 my ($self,$smtpd) = splice @_, 0, 2;
869 5 ▶ return PLUGIN_EAT_NONE unless $self->{simple};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"simple"} 0 5 5
870 5 my $id = ${ $_[0] };
871 5 ▶ if ( $self->{sender_verify} and defined $self->{clients}->{ $id }->{fverify} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}) 0 5 5
Condition33%1/3
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"sender_verify"} and defined $self->{"clients"}{$id}{"fverify"}
$self->{"sender_verify"} defined $self->{"clients"}{$id}{"fverify"}
Truth table33%1/3
A and B
A= $self->{"sender_verify"}B= defined $self->{"clients"}{$id}{"fverify"}
ABresult
0X0
100
111
872 0 my $response;
873 0 my $fverify = uc $self->{clients}->{ $id }->{fverify};
874 0 ▶ if ( $fverify eq 'NXDOMAIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fverify eq 'NXDOMAIN') { } 0 0 0
875 0 $response = '550 Sender verify failed';
876 }
877 else {
878 0 $response = '451 Temporary local problem - please try later';
879 }
880 0 delete $self->{clients}->{ $id }->{mail};
881 0 delete $self->{clients}->{ $id }->{rcpt};
882 0 delete $self->{clients}->{ $id }->{buffer};
883 0 delete $self->{clients}->{ $id }->{fverify};
884 0 $self->_send_event( 'smtpd_fverify', $id, $response, $fverify );
885 0 return PLUGIN_EAT_ALL;
886 }
887 5 my $from = ${ $_[1] };
888 5 my $rcpt = ${ $_[2] };
889 5 my $buf = ${ $_[3] };
890 5 my $msg_id = Email::MessageID->new( host => $self->{hostname} );
891 5 my $uid = $msg_id->user();
892 3 unshift @{ $buf }, "Message-ID: " . $msg_id->in_brackets()
893 5 ▶ unless grep { /^Message-ID:/i } @{ $buf };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/^Message-ID:/i;} @{$buf;} 3 2 5
894 4 unshift @{ $buf }, "Received: from Unknown [" . $self->{clients}->{ $id }->{peeraddr} . "] by " . $self->{hostname} . " " . $self->{version} . " with SMTP id $uid; " . strftime("%a, %d %b %Y %H:%M:%S %z", localtime)
895 5 ▶ unless $self->{origin};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"origin"} 4 1 5
896 5 $self->send_to_client( $id, "250 $uid Message accepted for delivery" );
897 5 my $email = Email::Simple->new( join "\r\n", @{ $buf } );
898 5 ▶ $email->header_set('Received') if $self->{origin};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"origin"} 1 4 5
899 5 ▶ my $subject = $email->header('Subject') || '';
Condition50%1/2
$email->header('Subject') || ''
l!l
50
MC/DC0%0/1
$email->header('Subject') || ''
$email->header('Subject')
Truth table50%1/2
A
A= $email->header('Subject')
Aresult
11
00
900 5 push @{ $self->{_mail_queue} }, { uid => $uid, from => $from, rcpt => $rcpt, msg => $email->as_string, ts => time(), subject => $subject };
901 5 $poe_kernel->post( $self->{session_id}, '_process_queue' );
902 5 ▶ $self->send_event( 'smtpd_message_queued', $id, $from, $rcpt, $uid, scalar @{ $buf }, $subject || '' );
Condition50%1/2
$subject || ''
l!l
50
MC/DC0%0/1
$subject || ''
$subject
Truth table50%1/2
A
A= $subject
Aresult
11
00
903 5 delete $self->{clients}->{$id}->{$_} for qw(mail rcpt buffer);
904 5 return PLUGIN_EAT_ALL;
905 }
906  
907 1 ▶sub enqueue {
Subroutine enqueue: called CC=15 SCAR=35.3
Pod documented
908 1 my $self = shift;
909 1 my %item;
910 1 ▶ if ( ref $_[0] and ref $_[0] eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] and ref $_[0] eq 'HASH') { } 1 0 1
elsif (ref $_[0] and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition33%1/3
ref $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "HASH"
ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
911 1 %item = %{ $_[0] };
912 }
913 ▶ elsif ( ref $_[0] and ref $_[0] eq 'ARRAY' ) {
Condition0%0/3
ref $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "ARRAY"
ref $_[0] ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
914 0 %item = @{ $_[0] };
915 }
916 else {
917 0 %item = @_;
918 }
919 1 $item{lc $_} = delete $item{$_} for keys %item;
920 1 ▶ return unless $item{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"from"} 0 1 1
921 1 ▶ return unless $item{msg};
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"msg"} 0 1 1
922 1 ▶ return unless $item{rcpt} and ref $item{rcpt} eq 'ARRAY' and scalar @{ $item{rcpt} };
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"rcpt"} and ref $item{"rcpt"} eq "ARRAY" and scalar @{$item{"rcpt"};} 0 1 1
Condition40%2/5
$item{"rcpt"} and ref $item{"rcpt"} eq "ARRAY" and scalar @{$item{"rcpt"};}
!ll
01
$item{"rcpt"} and ref $item{"rcpt"} eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
$item{"rcpt"} and ref $item{"rcpt"} eq "ARRAY" and scalar @{$item{"rcpt"};}
$item{"rcpt"} ref $item{"rcpt"} eq "ARRAY"
Truth table33%1/3
A and B
A= $item{"rcpt"}B= ref $item{"rcpt"} eq "ARRAY"
ABresult
0X0
100
111
923 1 ▶ $item{ts} = time() unless $item{ts} and $item{ts} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"ts"} and $item{"ts"} =~ /^\d+$/ 1 0 1
Condition33%1/3
$item{"ts"} and $item{"ts"} =~ /^\d+$/
!ll&&!rl&&r
100
MC/DC0%0/2
$item{"ts"} and $item{"ts"} =~ /^\d+$/
$item{"ts"} $item{"ts"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $item{"ts"}B= $item{"ts"} =~ /^\d+$/
ABresult
0X0
100
111
924 1 ▶ $item{uid} = Email::MessageID->new( host => $self->{hostname} )->user() unless $item{uid};
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"uid"} 1 0 1
925 1 ▶ $item{subject} = '' unless $item{subject};
Branch: 1 branch
BranchTrueFalseTotal
unless $item{"subject"} 1 0 1
926 1 push @{ $self->{_mail_queue} }, \%item;
927 1 $poe_kernel->post( $self->{session_id}, '_process_queue' );
928 1 return 1;
929 }
930  
931 14 1;
932  
933 __END__
↑ Summary SimpleSMTP/Constants.pm »