blib/lib/Mail/OpenRelay/Simple.pm

filter: Statementstmt 59.0% 39 / 66 Branchbran 17.5% 7 / 40 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 46.6% 56 / 120 CC 24 SCAR 52.0
CC
24
Cov
44%
check
225.4
BEGIN
1.0
BEGIN
1.0
CRAP 180.6
↑ Summary
1 package Mail::OpenRelay::Simple;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::Telnet;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.02';
11 1 $VERSION = eval $VERSION;
12  
13 1 __PACKAGE__->mk_accessors( qw(host port timeout from_email rcpt_email banner debug));
14  
15 1 $| = 1;
16  
17 1 ▶sub check {
Subroutine check: called CC=24 SCAR=54.2
Pod documented
18  
19 1 my $self = shift;
20 1 my $host = $self->host;
21 1 my $port = $self->port;
22 1 my $timeout = $self->timeout;
23 1 my $from_email = $self->from_email;
24 1 my $rcpt_email = $self->rcpt_email;
25 1 my $banner = $self->banner;
26 1 my $debug = $self->debug;
27  
28 1 ▶ $banner = $banner ? $banner : 0;
Branch: 1 branch
BranchTrueFalseTotal
$banner ? : 0 1 1
29 1 ▶ $debug = $debug ? $debug : 0;
Branch: 1 branch
BranchTrueFalseTotal
$debug ? : 0 1 1
30 1 ▶ $from_email = $from_email ? $from_email : "test\@foobar.com";
Branch: 1 branch
BranchTrueFalseTotal
$from_email ? : 1 0 1
31 1 ▶ $rcpt_email = $rcpt_email ? $rcpt_email : "test\@foobar.com";
Branch: 1 branch
BranchTrueFalseTotal
$rcpt_email ? : 1 0 1
32  
33 1 ▶ print ". Try to connect to $host...\n" if $debug == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 2 0 1 1
34  
35 1 ▶ my $t = new Net::Telnet(
Condition50%2/4
$port || '25'
l!l
01
$timeout || '8'
l!l
10
MC/DC0%0/1
$port || '25'
$port
MC/DC0%0/1
$timeout || '8'
$timeout
Truth table50%1/2
A
A= $port
Aresult
11
00
Truth table50%1/2
A
A= $timeout
Aresult
11
00
36 Host => $host,
37 Port => $port || '25',
38 Timeout => $timeout || '8',
39 Errmode => "return"
40 );
41  
42 1 ▶ if ($t){
Branch: 1 branch
BranchTrueFalseTotal
if ($t) { } 0 1 1
43 0 my $match = $t->getline;
44  
45 0 ▶ if ($match){
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 0 0 0
46  
47 0 my $Banner = $match;
48 0 chomp $Banner; for ($Banner) { s/^220\s//; }
49
50 0 ▶ if ($match =~ m/^220/){
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ /^220/) 0 0 0
51  
52 0 ▶ print ". HELO foo\n" if $debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 1 0 0 0
53 0 $t->print("HELO foo");
54  
55 0 $match = $t->getline;
56 0 ▶ if ($match){
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 0 0 0
57 0 ▶ if ($match =~ /^250/){
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ /^250/) 0 0 0
58  
59 0 ▶ print ". MAIL FROM:<$from_email>\n" if $debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 1 0 0 0
60 0 $t->print("MAIL FROM:<$from_email>");
61  
62 0 $match = $t->getline;
63
64 0 ▶ if ($match){
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 0 0 0
65 0 ▶ if ($match =~ /^250/){
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ /^250/) 0 0 0
66  
67 0 ▶ print ". RCPT TO:<$rcpt_email>\n" if $debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 1 0 0 0
68 0 $t->print("RCPT TO:<$rcpt_email>");
69
70 0 $match = $t->getline;
71
72 0 ▶ if ($match){
Branch: 1 branch
BranchTrueFalseTotal
if ($match) { } 0 0 0
73 0 ▶ if ($match =~ /^250/){
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ /^250/) { } 0 0 0
74 0 ▶ print "$Banner\n" if $banner == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $banner == 1 0 0 0
75 0 return 1;
76 } else {
77 0 return 0;
78 }
79 } else {
80 0 ▶ print ". can't send email with $host!\n" if $debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 1 0 0 0
81 }
82 }
83 }
84 }
85 }
86 }
87 }
88 0 $t->close;
89 } else {
90 1 ▶ print ". can't connect to host $host on port $port\n" if $debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug == 1 0 1 1
91 }
92  
93 1 return;
94 }
95  
96 1 1;
97 __END__
↑ Summary