blib/lib/Net/LMTP.pm

filter: Statementstmt 12.3% 22 / 178 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 14.2% 6 / 42 Podpod 94.4% 17 / 18 totaltotal 12.3% 45 / 364 CC 55 SCAR 43.8
CC
55
Cov
8%
mail
240.0
recipient
182.0
new
90.0
CRAP 79.4
↑ Summary
1 # Net::LMTP.pm
2 #
3 # Copyright (c) 2001 Les Howard <lhoward@spamcop.net>. This module
4 # is directly derived from the Net::SMTP module. All rights reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 package Net::LMTP;
9  
10 1 require 5.001;
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Socket 1.3;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Net::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 $VERSION = "0.02"; # $Id$
20  
21 1 @ISA = qw(Net::Cmd IO::Socket::INET);
22  
23 sub new
24 0 ▶{
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
25 0 my $self = shift;
26 0 ▶ my $type = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
27 0 my $host = shift;
28 0 my $port = shift;
29 0 my %arg = @_;
30 0 my $obj;
31  
32 0 ▶ if(!defined $host){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host) 0 0 0
33 0 warn "Net::LMTP:new - no host specified\n";
34 0 return undef;
35 }
36 0 ▶ if(!defined $port){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $port) 0 0 0
37 0 warn "Net::LMTP:new - no port specified\n";
38 0 return undef;
39 }
40  
41 $obj = $type->SUPER::new(PeerAddr => ($host = $host),
42 PeerPort => $port,
43 Proto => 'tcp',
44 Timeout => defined $arg{Timeout}
45 ? $arg{Timeout}
46 0 ▶ : 120
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'Timeout'} ? : 0 0 0
47 );
48 0 $obj->autoflush(1);
49  
50 0 ▶ $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
Branch: 1 branch
BranchTrueFalseTotal
exists $arg{'Debug'} ? : 0 0 0
51  
52 0 ▶ unless ($obj->response() == CMD_OK)
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->response == 2) 0 0 0
53 {
54 0 $obj->close();
55 0 return undef;
56 }
57  
58 0 ${*$obj}{'net_lmtp_host'} = $host;
59  
60 0 (${*$obj}{'net_lmtp_banner'}) = $obj->message;
61 0 (${*$obj}{'net_lmtp_domain'}) = $obj->message =~ /\A\s*(\S+)/;
62  
63 0 ▶ unless($obj->hello($arg{Hello} || ""))
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->hello($arg{"Hello"} || "")) 0 0 0
Condition0%0/2
$arg{'Hello'} || ''
l!l
00
MC/DC0%0/1
$arg{'Hello'} || ''
$arg{'Hello'}
Truth table0%0/2
A
A= $arg{'Hello'}
Aresult
11
00
64 {
65 0 $obj->close();
66 0 return undef;
67 }
68  
69 0 $obj;
70 }
71  
72 ##
73 ## User interface methods
74 ##
75  
76 sub banner
77 0 ▶{
Subroutine banner: not called CC=2 SCAR=17.9
Pod documented
78 0 my $me = shift;
79  
80 0 ▶ return ${*$me}{'net_lmtp_banner'} || undef;
Condition0%0/2
do { *$me }->{'net_lmtp_banner'} || undef
l!l
00
MC/DC0%0/1
do { *$me }->{'net_lmtp_banner'} || undef
do { *$me }->{'net_lmtp_banner'}
Truth table0%0/2
A
A= do { *$me }->{'net_lmtp_banner'}
Aresult
11
00
81 }
82  
83 sub domain
84 0 ▶{
Subroutine domain: not called CC=2 SCAR=17.9
Pod documented
85 0 my $me = shift;
86  
87 0 ▶ return ${*$me}{'net_lmtp_domain'} || undef;
Condition0%0/2
do { *$me }->{'net_lmtp_domain'} || undef
l!l
00
MC/DC0%0/1
do { *$me }->{'net_lmtp_domain'} || undef
do { *$me }->{'net_lmtp_domain'}
Truth table0%0/2
A
A= do { *$me }->{'net_lmtp_domain'}
Aresult
11
00
88 }
89  
90 0 ▶sub etrn {
Subroutine etrn: not called CC=2 SCAR=17.9
Pod documented
91 0 my $self = shift;
92 0 ▶ defined($self->supports('ETRN',500,["Command unknown: 'ETRN'"])) &&
Branch: 1 branch
BranchTrueFalseTotal
defined $self->supports("ETRN", 500, ["Command unknown: 'ETRN'"]) and $self->_ETRN(@_) 0 0 0
93 $self->_ETRN(@_);
94 }
95  
96 sub hello
97 0 ▶{
Subroutine hello: not called CC=8 SCAR=42.8
Pod documented
98 0 my $me = shift;
99 my $domain = shift ||
100 0 ▶ eval {
Condition0%0/5
shift() || eval { do { require Net::Domain; Net::Domain::hostfqdn() } } || ''
l!l
00
shift() or eval { do { require Net::Domain; Net::Domain::hostfqdn() } }
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || eval { do { require Net::Domain; Net::Domain::hostfqdn() } } || ''
shift() eval { do { require Net::Domain; Net::Domain::hostfqdn() } }
Truth table0%0/3
A or B
A= shift()B= eval { do { require Net::Domain; Net::Domain::hostfqdn() } }
ABresult
1X1
011
000
101 0 require Net::Domain;
102 0 Net::Domain::hostfqdn();
103 } ||
104 "";
105 0 my $ok = $me->_LHLO($domain);
106 0 my @msg = $me->message;
107  
108 0 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 0 0 0
109 {
110 0 my $h = ${*$me}{'net_lmtp_lmtp'} = {};
111 0 my $ln;
112 0 foreach $ln (@msg) {
113 0 ▶ $h->{$1} = $2
Branch: 1 branch
BranchTrueFalseTotal
if $ln =~ /(\S+)\b[ \t]*([^\n]*)/ 0 0 0
114 if $ln =~ /(\S+)\b[ \t]*([^\n]*)/;
115 }
116 }
117  
118 0 ▶ $ok && $msg[0] =~ /\A(\S+)/
Branch: 1 branch
BranchTrueFalseTotal
$ok && $msg[0] =~ /\A(\S+)/ ? : 0 0 0
Condition0%0/3
$ok and $msg[0] =~ /\A(\S+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and $msg[0] =~ /\A(\S+)/
$ok $msg[0] =~ /\A(\S+)/
Truth table0%0/3
A and B
A= $okB= $msg[0] =~ /\A(\S+)/
ABresult
0X0
100
111
119 ? $1
120 : undef;
121 }
122  
123 0 ▶sub supports {
Subroutine supports: not called CC=3 SCAR=24.8
Pod undocumented
124 0 my $self = shift;
125 0 my $cmd = uc shift;
126 0 return ${*$self}{'net_lmtp_lmtp'}->{$cmd}
127 0 ▶ if exists ${*$self}{'net_lmtp_lmtp'}->{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if exists do { *$self }->{"net_lmtp_lmtp"}{$cmd} 0 0 0
128 0 ▶ $self->set_status(@_)
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
129 if @_;
130 0 return;
131 }
132  
133 sub _addr
134 0 ▶{
Subroutine _addr: not called CC=3 SCAR=24.8
135 0 ▶ my $addr = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
136  
137 0 ▶ return $1
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /(<[^>]+>)/so 0 0 0
138 if $addr =~ /(<[^>]+>)/so;
139  
140 0 $addr =~ s/\n/ /sog;
141 0 $addr =~ s/(\A\s+|\s+\Z)//sog;
142  
143 0 return "<" . $addr . ">";
144 }
145  
146  
147 sub mail
148 0 ▶{
Subroutine mail: not called CC=15 SCAR=54.8
Pod documented
149 0 my $me = shift;
150 0 my $addr = _addr(shift);
151 0 my $opts = "";
152  
153 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
154 {
155 0 my %opt = @_;
156 0 my($k,$v);
157  
158 0 ▶ if(exists ${*$me}{'net_lmtp_lmtp'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { *$me }->{'net_lmtp_lmtp'}) { } 0 0 0
159 {
160 0 my $lmtp = ${*$me}{'net_lmtp_lmtp'};
161  
162 0 ▶ if(defined($v = delete $opt{Size}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Size"})) 0 0 0
163 {
164 0 ▶ if(exists $lmtp->{SIZE})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'SIZE'}) { } 0 0 0
165 {
166 0 $opts .= sprintf " SIZE=%d", $v + 0
167 }
168 else
169 {
170 0 carp 'Net::LMTP::mail: SIZE option not supported by host';
171 }
172 }
173  
174 0 ▶ if(defined($v = delete $opt{Return}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Return"})) 0 0 0
175 {
176 0 ▶ if(exists $lmtp->{DSN})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'DSN'}) { } 0 0 0
177 {
178 0 $opts .= " RET=" . uc $v
179 }
180 else
181 {
182 0 carp 'Net:::LMTP::mail: DSN option not supported by host';
183 }
184 }
185  
186 0 ▶ if(defined($v = delete $opt{Bits}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Bits"})) 0 0 0
187 {
188 0 ▶ if(exists $lmtp->{'8BITMIME'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'8BITMIME'}) { } 0 0 0
189 {
190 0 ▶ $opts .= $v == 8 ? " BODY=8BITMIME" : " BODY=7BIT"
Branch: 1 branch
BranchTrueFalseTotal
$v == 8 ? : 0 0 0
191 }
192 else
193 {
194 0 carp 'Net::LMTP::mail: 8BITMIME option not supported by host';
195 }
196 }
197  
198 0 ▶ if(defined($v = delete $opt{Transaction}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Transaction"})) 0 0 0
199 {
200 0 ▶ if(exists $lmtp->{CHECKPOINT})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'CHECKPOINT'}) { } 0 0 0
201 {
202 0 $opts .= " TRANSID=" . _addr($v);
203 }
204 else
205 {
206 0 carp 'Net::LMTP::mail: CHECKPOINT option not supported by host';
207 }
208 }
209  
210 0 ▶ if(defined($v = delete $opt{Envelope}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Envelope"})) 0 0 0
211 {
212 0 ▶ if(exists $lmtp->{DSN})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'DSN'}) { } 0 0 0
213 {
214 0 $v =~ s/([^\041-\176]|=|\+)/sprintf "+%02x", ord($1)/sge;
215 0 $opts .= " ENVID=$v"
216 }
217 else
218 {
219 0 carp 'Net::LMTP::mail: DSN option not supported by host';
220 }
221 }
222  
223 0 ▶ carp 'Net::LMTP::recipient: unknown option(s) '
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opt 0 0 0
224 . join(" ", keys %opt)
225 . ' - ignored'
226 if scalar keys %opt;
227 }
228 else
229 {
230 0 carp 'Net::LMTP::mail: LMTP not supported by host - options discarded :-(';
231 }
232 }
233  
234 0 $me->_MAIL("FROM:".$addr.$opts);
235 }
236  
237 0 ▶sub send { shift->_SEND("FROM:" . _addr($_[0])) }
Subroutine send: not called CC=1 SCAR=6.9
Pod documented
238 0 ▶sub send_or_mail { shift->_SOML("FROM:" . _addr($_[0])) }
Subroutine send_or_mail: not called CC=1 SCAR=6.9
Pod documented
239 0 ▶sub send_and_mail { shift->_SAML("FROM:" . _addr($_[0])) }
Subroutine send_and_mail: not called CC=1 SCAR=6.9
Pod documented
240  
241 sub reset
242 0 ▶{
Subroutine reset: not called CC=2 SCAR=17.9
Pod documented
243 0 my $me = shift;
244  
245 $me->dataend()
246 0 ▶ if(exists ${*$me}{'net_lmtp_lastch'});
Branch: 1 branch
BranchTrueFalseTotal
if exists do { *$me }->{"net_lmtp_lastch"} 0 0 0
247  
248 0 $me->_RSET();
249 }
250  
251  
252 sub recipient
253 0 ▶{
Subroutine recipient: not called CC=13 SCAR=52.0
Pod documented
254 0 my $lmtp = shift;
255 0 my $opts = "";
256 0 my $skip_bad = 0;
257  
258 0 ▶ if(@_ && ref($_[-1]))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and ref $_[-1]) 0 0 0
Condition0%0/3
@_ and ref $_[-1]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1]
@_ ref $_[-1]
Truth table0%0/3
A and B
A= @_B= ref $_[-1]
ABresult
0X0
100
111
259 {
260 0 my %opt = %{pop(@_)};
261 0 my $v;
262  
263 0 $skip_bad = delete $opt{'SkipBad'};
264  
265 0 ▶ if(exists ${*$lmtp}{'net_lmtp_lmtp'})
Branch: 2 branches
BranchTrueFalseTotal
if (exists do { *$lmtp }->{'net_lmtp_lmtp'}) { } 0 0 0
elsif (%opt) { } 0 0 0
266 {
267 0 my $lmtp = ${*$lmtp}{'net_lmtp_lmtp'};
268  
269 0 ▶ if(defined($v = delete $opt{Notify}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = delete $opt{"Notify"})) 0 0 0
270 {
271 0 ▶ if(exists $lmtp->{DSN})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lmtp->{'DSN'}) { } 0 0 0
272 {
273 0 $opts .= " NOTIFY=" . join(",",map { uc $_ } @$v)
274 }
275 else
276 {
277 0 carp 'Net::LMTP::recipient: DSN option not supported by host';
278 }
279 }
280  
281 0 ▶ carp 'Net::LMTP::recipient: unknown option(s) '
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opt 0 0 0
282 . join(" ", keys %opt)
283 . ' - ignored'
284 if scalar keys %opt;
285 }
286 elsif(%opt)
287 {
288 0 carp 'Net::LMTP::recipient: LMTP not supported by host - options discarded :-(';
289 }
290 }
291  
292 0 my @ok;
293 my $addr;
294 0 foreach $addr (@_)
295 {
296 0 ▶ if($lmtp->_RCPT("TO:" . _addr($addr) . $opts)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lmtp->_RCPT('TO:' . _addr($addr) . $opts)) { } 0 0 0
elsif (not $skip_bad) { } 0 0 0
297 0 ▶ push(@ok,$addr) if $skip_bad;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_bad 0 0 0
298 }
299 elsif(!$skip_bad) {
300 0 return 0;
301 }
302 }
303  
304 0 ▶ return $skip_bad ? @ok : 1;
Branch: 1 branch
BranchTrueFalseTotal
$skip_bad ? : 0 0 0
305 }
306  
307 0 ▶sub to { shift->recipient(@_) }
Subroutine to: not called CC=1 SCAR=6.9
Pod documented
308  
309 sub data
310 0 ▶{
Subroutine data: not called CC=4 SCAR=30.0
Pod documented
311 0 my $me = shift;
312  
313 0 ▶ my $ok = $me->_DATA() && $me->datasend(@_);
Condition0%0/3
$me->_DATA && $me->datasend(@_)
!ll&&!rl&&r
000
MC/DC0%0/2
$me->_DATA && $me->datasend(@_)
$me->_DATA $me->datasend(@_)
Truth table0%0/3
A && B
A= $me->_DATAB= $me->datasend(@_)
ABresult
0X0
100
111
314  
315 0 ▶ $ok && @_ ? $me->dataend
Branch: 1 branch
BranchTrueFalseTotal
$ok && @_ ? : 0 0 0
Condition0%0/3
$ok and @_
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and @_
$ok @_
Truth table0%0/3
A and B
A= $okB= @_
ABresult
0X0
100
111
316 : $ok;
317 }
318  
319 sub expand
320 0 ▶{
Subroutine expand: not called CC=2 SCAR=17.9
Pod documented
321 0 my $me = shift;
322  
323 0 ▶ $me->_EXPN(@_) ? ($me->message)
Branch: 1 branch
BranchTrueFalseTotal
$me->_EXPN(@_) ? : 0 0 0
324 : ();
325 }
326  
327  
328 0 ▶sub verify { shift->_VRFY(@_) }
Subroutine verify: not called CC=1 SCAR=6.9
Pod documented
329  
330 sub help
331 0 ▶{
Subroutine help: not called CC=2 SCAR=17.9
Pod documented
332 0 my $me = shift;
333  
334 0 ▶ $me->_HELP(@_) ? scalar $me->message
Branch: 1 branch
BranchTrueFalseTotal
$me->_HELP(@_) ? : 0 0 0
335 : undef;
336 }
337  
338 sub quit
339 0 ▶{
Subroutine quit: not called CC=1 SCAR=6.9
Pod documented
340 0 my $me = shift;
341  
342 0 $me->_QUIT;
343 0 $me->close;
344 }
345  
346 sub DESTROY
347 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
348 # ignore
349 }
350  
351 ##
352 ## SMTP commands that remain in LMTP
353 ##
354  
355 0 ▶sub _MAIL { shift->command("MAIL", @_)->response() == CMD_OK }
Subroutine _MAIL: not called CC=1 SCAR=6.9
356 0 ▶sub _RCPT { shift->command("RCPT", @_)->response() == CMD_OK }
Subroutine _RCPT: not called CC=1 SCAR=6.9
357 0 ▶sub _SEND { shift->command("SEND", @_)->response() == CMD_OK }
Subroutine _SEND: not called CC=1 SCAR=6.9
358 0 ▶sub _SAML { shift->command("SAML", @_)->response() == CMD_OK }
Subroutine _SAML: not called CC=1 SCAR=6.9
359 0 ▶sub _SOML { shift->command("SOML", @_)->response() == CMD_OK }
Subroutine _SOML: not called CC=1 SCAR=6.9
360 0 ▶sub _VRFY { shift->command("VRFY", @_)->response() == CMD_OK }
Subroutine _VRFY: not called CC=1 SCAR=6.9
361 0 ▶sub _EXPN { shift->command("EXPN", @_)->response() == CMD_OK }
Subroutine _EXPN: not called CC=1 SCAR=6.9
362 0 ▶sub _HELP { shift->command("HELP", @_)->response() == CMD_OK }
Subroutine _HELP: not called CC=1 SCAR=6.9
363 0 ▶sub _RSET { shift->command("RSET")->response() == CMD_OK }
Subroutine _RSET: not called CC=1 SCAR=6.9
364 0 ▶sub _NOOP { shift->command("NOOP")->response() == CMD_OK }
Subroutine _NOOP: not called CC=1 SCAR=6.9
365 0 ▶sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
Subroutine _QUIT: not called CC=1 SCAR=6.9
366 0 ▶sub _DATA { shift->command("DATA")->response() == CMD_MORE }
Subroutine _DATA: not called CC=1 SCAR=6.9
367 0 ▶sub _TURN { shift->unsupported(@_); }
Subroutine _TURN: not called CC=1 SCAR=6.9
368 0 ▶sub _ETRN { shift->command("ETRN", @_)->response() == CMD_OK }
Subroutine _ETRN: not called CC=1 SCAR=6.9
369  
370  
371 ##
372 ## RFC2033 commands
373 ##
374 0 ▶sub _LHLO { shift->command("LHLO", @_)->response() == CMD_OK }
Subroutine _LHLO: not called CC=1 SCAR=6.9
375 0 ▶sub _BDAT { shift->unsupported(@_); }
Subroutine _BDAT: not called CC=1 SCAR=6.9
376  
377 1 1;
378  
379 __END__
↑ Summary