| 1 | package Net::SMTP::Server::Client2; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw($VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | $VERSION = '0.2'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | my %_cmds = ( | |||||||||||||||||||||||||||
| 15 | DATA => \&_data, | ||||||||||||||||||||||||||||
| 16 | EXPN => \&_noway, | ||||||||||||||||||||||||||||
| 17 | HELO => \&_hello, | ||||||||||||||||||||||||||||
| 18 | HELP => \&_help, | ||||||||||||||||||||||||||||
| 19 | MAIL => \&_mail, | ||||||||||||||||||||||||||||
| 20 | NOOP => \&_noop, | ||||||||||||||||||||||||||||
| 21 | QUIT => \&_quit, | ||||||||||||||||||||||||||||
| 22 | RCPT => \&_receipt, | ||||||||||||||||||||||||||||
| 23 | RSET => \&_reset, | ||||||||||||||||||||||||||||
| 24 | VRFY => \&_noway | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Utility functions. | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _put { | ||||||||||||||||||||||||||
|
Subroutine
_put: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 0 | print {shift->{SOCK}} @_, "\r\n"; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _reset0 { | ||||||||||||||||||||||||||
|
Subroutine
_reset0: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 0 | $self->{FROM} = undef; | |||||||||||||||||||||||||||
| 36 | 0 | $self->{TO} = []; | |||||||||||||||||||||||||||
| 37 | 0 | $self->{MSG} = undef; | |||||||||||||||||||||||||||
| 38 | 0 | $self->{faults} = 0; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _reset { | ||||||||||||||||||||||||||
|
Subroutine
_reset: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 0 | $self->_reset0; | |||||||||||||||||||||||||||
| 45 | 0 | $self->_put("250 buffahs ah cleah, suh!"); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # New instance. | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my($this, $sock) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table0%0/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||
| 53 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | bless($self, $class); | |||||||||||||||||||||||||||
| 56 | 0 | $self->_reset0; | |||||||||||||||||||||||||||
| 57 | 0 | $self->{SOCK} = $sock; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | croak("No client connection specified.") unless defined($self->{SOCK}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | return $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub greet { | ||||||||||||||||||||||||||
|
Subroutine
greet: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $_[0]->_put("220 Debatable SMTP $VERSION Ready."); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub basta{ | ||||||||||||||||||||||||||
|
Subroutine
basta: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 0 | $self -> _put("421 closing transmission channel"); | |||||||||||||||||||||||||||
| 71 | 0 | $self->{SOCK}->close; | |||||||||||||||||||||||||||
| 72 | 0 | 1; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # sub process { | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub get_message { | ||||||||||||||||||||||||||
|
Subroutine
get_message: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my($cmd, @args); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $sock = $self->{SOCK}; | |||||||||||||||||||||||||||
| 81 | 0 | $self->_reset0; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | while(<$sock>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | print "$$ command: $_"; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $$self{faults} > 15 and $self->basta and last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"faults"} > 15 and $self->basta
MC/DC0%0/2
$self->{"faults"} > 15 and $self->basta
$self->{"faults"} > 15
$self->basta
Truth table0%0/3
A and B
A= $self->{"faults"} > 15B= $self->basta
| |||||||||||||||||||||||||||||
| 86 | # Clean up. | ||||||||||||||||||||||||||||
| 87 | 0 | chomp; | |||||||||||||||||||||||||||
| 88 | 0 | s/^\s+//; | |||||||||||||||||||||||||||
| 89 | 0 | s/\s+$//; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | unless(length $_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | ++$$self{faults}; | |||||||||||||||||||||||||||
| 92 | 0 | $self->greet; | |||||||||||||||||||||||||||
| 93 | 0 | next; | |||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||
| 95 | 0 | ($cmd, @args) = split(/\s+/); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | $cmd =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if(!defined($_cmds{$cmd})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | sleep ++$$self{faults}; | |||||||||||||||||||||||||||
| 101 | 0 | $self->_put("500 sorry, I don't know how to $cmd"); | |||||||||||||||||||||||||||
| 102 | 0 | next; | |||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # all commands return TRUE to indicate that | ||||||||||||||||||||||||||||
| 106 | # we need to keep working to get the message. | ||||||||||||||||||||||||||||
| 107 | 0 | &{$_cmds{$cmd}}($self, \@args) or | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | return(defined($self->{MSG})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | return undef; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub find_addresses { | ||||||||||||||||||||||||||
|
Subroutine
find_addresses: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | # find e-mail addresses in the arguments and return them. | ||||||||||||||||||||||||||||
| 116 | # max one e-mail address per argument. | ||||||||||||||||||||||||||||
| 117 | # print "looking for addresses in <@_>\n"; | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return map { /([^<|;]+\@[^>|;&,\s]+)/ ? $1 : () } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub okay { | ||||||||||||||||||||||||||
|
Subroutine
okay: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 0 | $self -> _put("250 OK @_"); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub fail { | ||||||||||||||||||||||||||
|
Subroutine
fail: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | $self -> _put("554 @_"); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub too_long { | ||||||||||||||||||||||||||
|
Subroutine
too_long: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | $_[0] -> _put("552 Too much mail data"); | |||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub _mail { | ||||||||||||||||||||||||||
|
Subroutine
_mail: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 136 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||
| 137 | 0 | my @who = find_addresses(@{$_[1]}); | |||||||||||||||||||||||||||
| 138 | 0 | my $who = shift @who; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($who){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | $self->{FROM} = $who; | |||||||||||||||||||||||||||
| 141 | 0 | return $self->okay("Envelope sender set to <$who> ") | |||||||||||||||||||||||||||
| 142 | }else{ | ||||||||||||||||||||||||||||
| 143 | 0 | $self->{faults}++; | |||||||||||||||||||||||||||
| 144 | 0 | return $self-> _put("501 could not find name\@postoffice in <@{$_[1]}>") | |||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub rcpt_syntax{ | ||||||||||||||||||||||||||
|
Subroutine
rcpt_syntax: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 0 | $_[0] -> _put("553 no user\@host addresses found in <@{$_[1]}>"); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _receipt { | ||||||||||||||||||||||||||
|
Subroutine
_receipt: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||
| 154 | 0 | my @recipients = find_addresses(@{$_[1]}); | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | @recipients or return $self->rcpt_syntax($_[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | push @{ $self->{TO} }, @recipients; | |||||||||||||||||||||||||||
| 157 | 0 | $self->okay("sending to @{$self->{TO}}"); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _data { | ||||||||||||||||||||||||||
|
Subroutine
_data: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my @msg; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if(!$self->{FROM}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | $self-> _put("503 start with 'mail from: ...'"); | |||||||||||||||||||||||||||
| 167 | 0 | $self->{faults}++; | |||||||||||||||||||||||||||
| 168 | 0 | return 1; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if(!@{$self->{TO}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | $self->_put("503 specify recipients with 'rcpt to: ...'"); | |||||||||||||||||||||||||||
| 173 | 0 | $self->{faults}++; | |||||||||||||||||||||||||||
| 174 | 0 | return 1; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $self->_put("354 And what am I to tell them?"); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $sock = $self->{SOCK}; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | while(<$sock>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | print "$$ data: $_"; | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | if(/^\.\r*\n*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | $self->{MSG} = join ('', @msg); | |||||||||||||||||||||||||||
| 185 | 0 | return 0; # please examine MSG | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # RFC 821 compliance. | ||||||||||||||||||||||||||||
| 189 | 0 | s/^\.\./\./; | |||||||||||||||||||||||||||
| 190 | 0 | push @msg, $_; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | return 0; # socket died | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub _noway { | ||||||||||||||||||||||||||
|
Subroutine
_noway: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 197 | 0 | shift->_put("252 Nice try."); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub _noop { | ||||||||||||||||||||||||||
|
Subroutine
_noop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 201 | 0 | shift->_put("250 Whatever."); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _help { | ||||||||||||||||||||||||||
|
Subroutine
_help: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 207 | 0 | my $str = "214-Commands\r\n"; | |||||||||||||||||||||||||||
| 208 | 0 | my $total = keys(%_cmds); | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | foreach(sort(keys(%_cmds))) { | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | if(!($i++ % 5)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if(($total - $i) < 5) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | $str .= "\r\n214 "; | |||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||
| 215 | 0 | $str .= "\r\n214-"; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||
| 218 | 0 | $str .= ' '; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | $str .= $_; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | $self->_put($str); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _quit { | ||||||||||||||||||||||||||
|
Subroutine
_quit: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | $self->_put("221 Ciao"); | |||||||||||||||||||||||||||
| 231 | 0 | $self->{SOCK}->close; | |||||||||||||||||||||||||||
| 232 | 0 | return 0; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub _hello { | ||||||||||||||||||||||||||
|
Subroutine
_hello: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 236 | 0 | shift->okay( "Welcome" ); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 1 | 1; | |||||||||||||||||||||||||||
| 240 | __END__ | ||||||||||||||||||||||||||||