Mail/Internet.pm

filter: Statementstmt 18.4% 56 / 304 Branchbran 10.3% 17 / 164 Conditioncond 7.4% 6 / 81 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 35.1% 13 / 37 Podpod 87.5% 28 / 32 totaltotal 18.1% 120 / 663 CC 124 SCAR 61.7
CC
124
Cov
14%
reply
1640.0
smtpsend
380.0
nntppost
110.0
CRAP 477.5
↑ Summary Mail/Util.pm »
1 # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of the bundle MailTools. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md for Copyright.
7 # Licensed under the same terms as Perl itself.
8  
9 package Mail::Internet;{
10 2 our $VERSION = '2.22';
11 }
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 # use warnings? probably breaking too much code
15  
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Mail::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Mail::Util qw/mailaddress/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub new(@)
23 3 ▶{ my $call = shift;
Subroutine new: called CC=15 SCAR=33.2
Pod documented
24 3 ▶ my $arg = @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 1 2 3
25 3 my %opt = @_;
26  
27 3 ▶ my $class = ref($call) || $call;
Condition33%1/3
ref $call || $call
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $call || $call
ref $call $call
Truth table33%1/3
A || B
A= ref $callB= $call
ABresult
1X1
011
000
28 3 my $self = bless {}, $class;
29  
30 3 ▶ $self->{mail_inet_head} = $opt{Header} if exists $opt{Header};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Header"} 0 3 3
31 3 ▶ $self->{mail_inet_body} = $opt{Body} if exists $opt{Body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Body"} 0 3 3
32  
33 3 my $head = $self->head;
34 3 ▶ $head->fold_length(delete $opt{FoldLength} || 79);
Condition50%1/2
delete $opt{'FoldLength'} || 79
l!l
03
MC/DC0%0/1
delete $opt{'FoldLength'} || 79
delete $opt{'FoldLength'}
Truth table50%1/2
A
A= delete $opt{'FoldLength'}
Aresult
11
00
35 3 ▶ $head->mail_from($opt{MailFrom}) if exists $opt{MailFrom};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"MailFrom"} 0 3 3
36 3 ▶ $head->modify(exists $opt{Modify} ? $opt{Modify} : 1);
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'Modify'} ? : 1 2 3
37  
38 3 ▶ if(!defined $arg) { }
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $arg) { } 2 1 3
elsif (ref $arg eq 'ARRAY') { } 1 0 1
elsif (defined fileno $arg) { } 0 0 0
39 elsif(ref($arg) eq 'ARRAY')
40 1 ▶ { $self->header($arg) unless exists $opt{Header};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{"Header"} 1 0 1
41 1 ▶ $self->body($arg) unless exists $opt{Body};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{"Body"} 1 0 1
42 }
43 elsif(defined fileno($arg))
44 0 ▶ { $self->read_header($arg) unless exists $opt{Header};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{"Header"} 0 0 0
45 0 ▶ $self->read_body($arg) unless exists $opt{Body};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{"Body"} 0 0 0
46 }
47 else
48 0 { croak "couldn't understand $arg to Mail::Internet constructor";
49 }
50  
51 3 $self;
52 }
53  
54  
55 sub read(@)
56 0 ▶{ my $self = shift;
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
57 0 $self->read_header(@_);
58 0 $self->read_body(@_);
59 }
60  
61 sub read_body($)
62 0 ▶{ my ($self, $fd) = @_;
Subroutine read_body: not called CC=1 SCAR=6.9
Pod undocumented
63 0 $self->body( [ <$fd> ] );
64 }
65  
66 sub read_header(@)
67 0 ▶{ my $head = shift->head;
Subroutine read_header: not called CC=1 SCAR=6.9
Pod undocumented
68 0 $head->read(@_);
69 0 $head->header;
70 }
71  
72  
73 sub extract($)
74 0 ▶{ my ($self, $lines) = @_;
Subroutine extract: not called CC=1 SCAR=6.9
Pod documented
75 0 $self->head->extract($lines);
76 0 $self->body($lines);
77 }
78  
79  
80 sub dup()
81 2 ▶{ my $self = shift;
Subroutine dup: called CC=3 SCAR=11.2
Pod documented
82 2 my $dup = ref($self)->new;
83  
84 2 ▶ my $body = $self->{mail_inet_body} || [];
Condition50%1/2
$self->{'mail_inet_body'} || []
l!l
20
MC/DC0%0/1
$self->{'mail_inet_body'} || []
$self->{'mail_inet_body'}
Truth table50%1/2
A
A= $self->{'mail_inet_body'}
Aresult
11
00
85 2 my $head = $self->{mail_inet_head};;
86  
87 2 $dup->{mail_inet_body} = [ @$body ];
88 2 ▶ $dup->{mail_inet_head} = $head->dup if $head;
Branch: 1 branch
BranchTrueFalseTotal
if $head 2 0 2
89 2 $dup;
90 }
91  
92 #---------------
93  
94 sub body(;$@)
95 7 ▶{ my $self = shift;
Subroutine body: called CC=4 SCAR=14.3
Pod documented
96  
97 7 ▶ return $self->{mail_inet_body} ||= []
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 6 1 7
Condition50%1/2
$self->{"mail_inet_body"} ||= []
l!l
60
MC/DC0%0/1
$self->{"mail_inet_body"} ||= []
$self->{"mail_inet_body"}
Truth table50%1/2
A
A= $self->{"mail_inet_body"}
Aresult
11
00
98 unless @_;
99  
100 1 ▶ $self->{mail_inet_body} = ref $_[0] eq 'ARRAY' ? $_[0] : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 1 0 1
101 }
102  
103  
104 10 ▶sub head { shift->{mail_inet_head} ||= Mail::Header->new }
Subroutine head: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
+(shift())->{"mail_inet_head"} ||= "Mail::Header"->new
l!l&&r!l&&!r
730
MC/DC0%0/2
+(shift())->{"mail_inet_head"} ||= "Mail::Header"->new
+(shift())->{"mail_inet_head"} "Mail::Header"->new
Truth table66%2/3
A ||= B
A= +(shift())->{"mail_inet_head"}B= "Mail::Header"->new
ABresult
1X1
011
000
105  
106 #---------------
107  
108 sub print($)
109 0 ▶{ my $self = shift;
Subroutine print: not called CC=4 SCAR=30.0
Pod documented
110 0 ▶ my $fd = shift || \*STDOUT;
Condition0%0/2
shift() || \*STDOUT
l!l
00
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
111  
112 0 ▶ $self->print_header($fd)
Branch: 1 branch
BranchTrueFalseTotal
$self->print_header($fd) and print $fd "\n" and $self->print_body($fd) 0 0 0
Condition0%0/3
$self->print_header($fd) and print $fd "\n"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->print_header($fd) and print $fd "\n"
$self->print_header($fd) print $fd "\n"
Truth table0%0/3
A and B
A= $self->print_header($fd)B= print $fd "\n"
ABresult
0X0
100
111
113 and print $fd "\n"
114 and $self->print_body($fd);
115 }
116  
117  
118 0 ▶sub print_header($) { shift->head->print(@_) }
Subroutine print_header: not called CC=1 SCAR=6.9
Pod documented
119  
120 sub print_body($)
121 0 ▶{ my $self = shift;
Subroutine print_body: not called CC=4 SCAR=30.0
Pod documented
122 0 ▶ my $fd = shift || \*STDOUT;
Condition0%0/2
shift() || \*STDOUT
l!l
00
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
123  
124 0 foreach my $ln (@{$self->body})
125 0 ▶ { print $fd $ln or return 0;
Branch: 1 branch
BranchTrueFalseTotal
print $fd $ln or return 0 0 0 0
126 }
127  
128 0 1;
129 }
130  
131  
132 sub as_string()
133 4 ▶{ my $self = shift;
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
134 4 $self->head->as_string . "\n" . join '', @{$self->body};
135 }
136  
137  
138 sub as_mbox_string($)
139 2 ▶{ my $self = shift->dup;
Subroutine as_mbox_string: called CC=2 SCAR=7.0
Pod documented
140 2 my $escaped = shift;
141  
142 2 $self->head->delete('Content-Length');
143 2 ▶ $self->escape_from unless $escaped;
Branch: 1 branch
BranchTrueFalseTotal
unless $escaped 2 0 2
144 2 $self->as_string . "\n";
145 }
146  
147 #---------------
148  
149 1 ▶sub header { shift->head->header(@_) }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
150 0 ▶sub fold { shift->head->fold(@_) }
Subroutine fold: not called CC=1 SCAR=6.9
Pod documented
151 0 ▶sub fold_length { shift->head->fold_length(@_) }
Subroutine fold_length: not called CC=1 SCAR=6.9
Pod documented
152 0 ▶sub combine { shift->head->combine(@_) }
Subroutine combine: not called CC=1 SCAR=6.9
Pod documented
153  
154  
155 sub add(@)
156 0 ▶{ my $head = shift->head;
Subroutine add: not called CC=3 SCAR=24.8
Pod documented
157 0 my $ret;
158 0 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
159 0 { my ($tag, $line) = splice @_, 0, 2;
160 0 ▶ $ret = $head->add($tag, $line, -1)
Branch: 1 branch
BranchTrueFalseTotal
$ret = $head->add($tag, $line, -1) or return undef 0 0 0
161 or return undef;
162 }
163  
164 0 $ret;
165 }
166  
167  
168 sub replace(@)
169 0 ▶{ my $head = shift->head;
Subroutine replace: not called CC=3 SCAR=24.8
Pod documented
170 0 my $ret;
171  
172 0 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
173 0 { my ($tag, $line) = splice @_, 0, 2;
174 0 ▶ $ret = $head->replace($tag, $line, 0)
Branch: 1 branch
BranchTrueFalseTotal
$ret = $head->replace($tag, $line, 0) or return undef 0 0 0
175 or return undef;
176 }
177  
178 0 $ret;
179 }
180  
181  
182 sub get(@)
183 0 ▶{ my $head = shift->head;
Subroutine get: not called CC=4 SCAR=30.0
Pod documented
184  
185 0 ▶ return map { $head->get($_) } @_
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
186 if wantarray;
187  
188 0 foreach my $tag (@_)
189 0 { my $r = $head->get($tag);
190 0 ▶ return $r if defined $r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
191 }
192  
193 0 undef;
194 }
195  
196  
197 sub delete(@)
198 0 ▶{ my $head = shift->head;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
199 0 map { $head->delete($_) } @_;
200 }
201  
202 # Undocumented; unused???
203 sub empty()
204 0 ▶{ my $self = shift;
Subroutine empty: not called CC=1 SCAR=6.9
Pod undocumented
205 0 %$self = ();
206 0 1;
207 }
208  
209 #---------------
210  
211 sub remove_sig($)
212 0 ▶{ my $body = shift->body;
Subroutine remove_sig: not called CC=5 SCAR=34.0
Pod documented
213 0 ▶ my $nlines = shift || 10;
Condition0%0/2
shift() || 10
l!l
00
MC/DC0%0/1
shift() || 10
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
214 0 my $start = @$body;
215  
216 0 my $i = 0;
217 0 ▶ while($i++ < $nlines && $start--)
Branch: 1 branch
BranchTrueFalseTotal
if ($i++ < $nlines and $start--) 0 0 0
Condition0%0/3
$i++ < $nlines and $start--
!ll&&!rl&&r
000
MC/DC0%0/2
$i++ < $nlines and $start--
$i++ < $nlines $start--
Truth table0%0/3
A and B
A= $i++ < $nlinesB= $start--
ABresult
0X0
100
111
218 0 ▶ { next if $body->[$start] !~ /^--[ ]?[\r\n]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $body->[$start] =~ /^--[ ]?[\r\n]/ 0 0 0
219  
220 0 splice @$body, $start, $i;
221 0 last;
222 }
223 }
224  
225  
226 sub sign(@)
227 0 ▶{ my ($self, %arg) = @_;
Subroutine sign: not called CC=9 SCAR=45.0
Pod documented
228 0 my ($sig, @sig);
229  
230 0 ▶ if($sig = delete $arg{File})
Branch: 2 branches
BranchTrueFalseTotal
if ($sig = delete $arg{'File'}) { } 0 0 0
elsif ($sig = delete $arg{'Signature'}) { } 0 0 0
231 0 { local *SIG;
232  
233 0 ▶ if(open(SIG, $sig))
Branch: 1 branch
BranchTrueFalseTotal
if (open SIG, $sig) 0 0 0
234 0 { local $_;
235 0 ▶ while(<SIG>) { last unless /^(--)?\s*$/ }
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = readline SIG)) 0 0 0
unless /^(--)?\s*$/ 0 0 0
236 0 @sig = ($_, <SIG>, "\n");
237 0 close SIG;
238 }
239 }
240 elsif($sig = delete $arg{Signature})
241 0 ▶ { @sig = ref($sig) ? @$sig : split(/\n/, $sig);
Branch: 1 branch
BranchTrueFalseTotal
ref $sig ? : 0 0 0
242 }
243  
244 0 ▶ if(@sig)
Branch: 1 branch
BranchTrueFalseTotal
if (@sig) 0 0 0
245 0 { $self->remove_sig;
246 0 s/[\r\n]*$/\n/ for @sig;
247 0 push @{$self->body}, "-- \n", @sig;
248 }
249  
250 0 $self;
251 }
252  
253  
254 sub tidy_body()
255 0 ▶{ my $body = shift->body;
Subroutine tidy_body: not called CC=5 SCAR=34.0
Pod documented
256  
257 0 ▶ shift @$body while @$body && $body->[0] =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
@$body and $body->[0] =~ /^\s*$/ and do { shift @$body } 0 0 0
Condition0%0/3
@$body and $body->[0] =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
@$body and $body->[0] =~ /^\s*$/
@$body $body->[0] =~ /^\s*$/
Truth table0%0/3
A and B
A= @$bodyB= $body->[0] =~ /^\s*$/
ABresult
0X0
100
111
258 0 ▶ pop @$body while @$body && $body->[-1] =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
@$body and $body->[-1] =~ /^\s*$/ and do { pop @$body } 0 0 0
Condition0%0/3
@$body and $body->[-1] =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
@$body and $body->[-1] =~ /^\s*$/
@$body $body->[-1] =~ /^\s*$/
Truth table0%0/3
A and B
A= @$bodyB= $body->[-1] =~ /^\s*$/
ABresult
0X0
100
111
259 0 $body;
260 }
261  
262 #---------------
263  
264 sub reply(@)
265 0 ▶{ my ($self, %arg) = @_;
Subroutine reply: not called CC=40 SCAR=74.0
Pod documented
266 0 my $class = ref $self;
267 0 my @reply;
268  
269 0 local *MAILHDR;
270 0 ▶ if(open(MAILHDR, "$ENV{HOME}/.mailhdr"))
Branch: 1 branch
BranchTrueFalseTotal
if (open MAILHDR, qq[$ENV{"HOME"}/.mailhdr]) 0 0 0
271 { # User has defined a mail header template
272 0 @reply = <MAILHDR>;
273 0 close MAILHDR;
274 }
275  
276 0 my $reply = $class->new(\@reply);
277  
278 # The Subject line
279 0 ▶ my $subject = $self->get('Subject') || "";
Condition0%0/2
$self->get('Subject') || ''
l!l
00
MC/DC0%0/1
$self->get('Subject') || ''
$self->get('Subject')
Truth table0%0/2
A
A= $self->get('Subject')
Aresult
11
00
280 0 ▶ $subject = "Re: " . $subject
Branch: 1 branch
BranchTrueFalseTotal
if $subject =~ /\S+/ and not $subject =~ /Re:/i 0 0 0
Condition0%0/3
$subject =~ /\S+/ and not $subject =~ /Re:/i
!ll&&!rl&&r
000
MC/DC0%0/2
$subject =~ /\S+/ and not $subject =~ /Re:/i
$subject =~ /\S+/ not $subject =~ /Re:/i
Truth table0%0/3
A and not(B)
A= $subject =~ /\S+/B= not $subject =~ /Re:/i
ABresult
0X0
100
111
281 if $subject =~ /\S+/ && $subject !~ /Re:/i;
282  
283 0 $reply->replace(Subject => $subject);
284  
285 # Locate who we are sending to
286 0 ▶ my $to = $self->get('Reply-To')
Condition0%0/8
$self->get('Reply-To') || $self->get('From') || $self->get('Return-Path') || ''
l!l
00
$self->get("Reply-To") or $self->get("From") or $self->get("Return-Path")
l!l&&r!l&&!r
000
$self->get("Reply-To") or $self->get("From")
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->get('Reply-To') || $self->get('From') || $self->get('Return-Path') || ''
$self->get("Reply-To") $self->get("From") $self->get("Return-Path")
Truth table0%0/4
A or B or C
A= $self->get("Reply-To")B= $self->get("From")C= $self->get("Return-Path")
ABCresult
1XX1
01X1
0011
0000
287 || $self->get('From')
288 || $self->get('Return-Path')
289 || "";
290  
291 0 my $sender = (Mail::Address->parse($to))[0];
292  
293 0 my $name = $sender->name;
294 0 ▶ unless(defined $name)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 0 0
295 0 { my $fr = $self->get('From');
296 0 ▶ $fr = (Mail::Address->parse($fr))[0] if defined $fr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fr 0 0 0
297 0 ▶ $name = $fr->name if defined $fr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fr 0 0 0
298 }
299  
300 0 ▶ my $indent = $arg{Indent} || ">";
Condition0%0/2
$arg{'Indent'} || '>'
l!l
00
MC/DC0%0/1
$arg{'Indent'} || '>'
$arg{'Indent'}
Truth table0%0/2
A
A= $arg{'Indent'}
Aresult
11
00
301 0 ▶ if($indent =~ /\%/)
Branch: 1 branch
BranchTrueFalseTotal
if ($indent =~ /\%/) 0 0 0
302 0 { my %hash = ( '%' => '%');
303 0 ▶ my @name = $name ? grep( {length $_} split /[\n\s]+/, $name) : '';
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 0 0 0
304  
305 0 $hash{f} = $name[0];
306 0 ▶ $hash{F} = $#name ? substr($hash{f},0,1) : $hash{f};
Branch: 1 branch
BranchTrueFalseTotal
$#name ? : 0 0 0
307  
308 0 ▶ $hash{l} = $#name ? $name[$#name] : "";
Branch: 1 branch
BranchTrueFalseTotal
$#name ? : 0 0 0
309 0 ▶ $hash{L} = substr($hash{l},0,1) || "";
Condition0%0/2
substr($hash{'l'}, 0, 1) || ''
l!l
00
MC/DC0%0/1
substr($hash{'l'}, 0, 1) || ''
substr($hash{'l'}, 0, 1)
Truth table0%0/2
A
A= substr($hash{'l'}, 0, 1)
Aresult
11
00
310  
311 0 ▶ $hash{n} = $name || "";
Condition0%0/2
$name || ''
l!l
00
MC/DC0%0/1
$name || ''
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
312 0 $hash{I} = join "", map {substr($_,0,1)} @name;
313  
314 0 ▶ $indent =~ s/\%(.)/defined $hash{$1} ? $hash{$1} : $1/eg;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash{$1} ? : 0 0 0
315 }
316  
317 0 my $id = $sender->address;
318 0 $reply->replace(To => $id);
319  
320 # Find addresses not to include
321 0 ▶ my $mailaddresses = $ENV{MAILADDRESSES} || "";
Condition0%0/2
$ENV{'MAILADDRESSES'} || ''
l!l
00
MC/DC0%0/1
$ENV{'MAILADDRESSES'} || ''
$ENV{'MAILADDRESSES'}
Truth table0%0/2
A
A= $ENV{'MAILADDRESSES'}
Aresult
11
00
322  
323 0 my %nocc = (lc($id) => 1);
324 $nocc{lc $_->address} = 1
325 0 for Mail::Address->parse($reply->get('Bcc'), $mailaddresses);
326  
327 0 ▶ if($arg{ReplyAll}) # Who shall we copy this to
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"ReplyAll"}) 0 0 0
328 0 { my %cc;
329 0 foreach my $addr (Mail::Address->parse($self->get('To'), $self->get('Cc')))
330 0 { my $lc = lc $addr->address;
331 $cc{$lc} = $addr->format
332 0 ▶ unless $nocc{$lc};
Branch: 1 branch
BranchTrueFalseTotal
unless $nocc{$lc} 0 0 0
333 }
334 0 my $cc = join ', ', values %cc;
335 0 $reply->replace(Cc => $cc);
336 }
337  
338 # References
339 0 ▶ my $refs = $self->get('References') || "";
Condition0%0/2
$self->get('References') || ''
l!l
00
MC/DC0%0/1
$self->get('References') || ''
$self->get('References')
Truth table0%0/2
A
A= $self->get('References')
Aresult
11
00
340 0 my $mid = $self->get('Message-Id');
341  
342 0 ▶ $refs .= " " . $mid if defined $mid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mid 0 0 0
343 0 $reply->replace(References => $refs);
344  
345 # In-Reply-To
346 0 my $date = $self->get('Date');
347 0 my $inreply = "";
348  
349 0 ▶ if(defined $mid)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $mid) { } 0 0 0
elsif (defined $name) { } 0 0 0
350 0 { $inreply = $mid;
351 0 my @comment;
352 0 ▶ push @comment, "from $name" if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
353 0 ▶ push @comment, "on $date" if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
354 0 local $" = ' ';
355 0 ▶ $inreply .= " (@comment)" if @comment;
Branch: 1 branch
BranchTrueFalseTotal
if @comment 0 0 0
356 }
357 elsif(defined $name)
358 0 { $inreply = $name . "'s message";
359 0 ▶ $inreply .= "of " . $date if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
360 }
361 0 $reply->replace('In-Reply-To' => $inreply);
362  
363 # Quote the body
364 0 my $body = $reply->body;
365 0 @$body = @{$self->body}; # copy body
366 0 $reply->remove_sig;
367 0 $reply->tidy_body;
368 0 s/\A/$indent/ for @$body;
369  
370 # Add references
371 0 ▶ unshift @{$body}, (defined $name ? $name . " " : "") . "<$id> writes:\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 0 0 0
372  
373 0 ▶ if(defined $arg{Keep} && ref $arg{Keep} eq 'ARRAY') # Include lines
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg{"Keep"} and ref $arg{"Keep"} eq "ARRAY") 0 0 0
Condition0%0/3
defined $arg{"Keep"} and ref $arg{"Keep"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg{"Keep"} and ref $arg{"Keep"} eq "ARRAY"
defined $arg{"Keep"} ref $arg{"Keep"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $arg{"Keep"}B= ref $arg{"Keep"} eq "ARRAY"
ABresult
0X0
100
111
374 0 { foreach my $keep (@{$arg{Keep}})
375 0 { my $ln = $self->get($keep);
376 0 ▶ $reply->replace($keep => $ln) if defined $ln;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ln 0 0 0
377 }
378 }
379  
380 0 ▶ if(defined $arg{Exclude} && ref $arg{Exclude} eq 'ARRAY') # Exclude lines
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg{"Exclude"} and ref $arg{"Exclude"} eq "ARRAY") 0 0 0
Condition0%0/3
defined $arg{"Exclude"} and ref $arg{"Exclude"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg{"Exclude"} and ref $arg{"Exclude"} eq "ARRAY"
defined $arg{"Exclude"} ref $arg{"Exclude"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $arg{"Exclude"}B= ref $arg{"Exclude"} eq "ARRAY"
ABresult
0X0
100
111
381 0 { $reply->delete(@{$arg{Exclude}});
382 }
383  
384 0 $reply->head->cleanup; # remove empty header lines
385 0 $reply;
386 }
387  
388  
389 sub smtpsend($@)
390 0 ▶{ my ($self, %opt) = @_;
Subroutine smtpsend: not called CC=19 SCAR=59.4
Pod documented
391  
392 0 require Net::SMTP;
393 0 require Net::Domain;
394  
395 0 my $host = $opt{Host};
396 0 ▶ my $envelope = $opt{MailFrom} || mailaddress();
Condition0%0/3
$opt{'MailFrom'} || &mailaddress()
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'MailFrom'} || &mailaddress()
$opt{'MailFrom'} &mailaddress()
Truth table0%0/3
A || B
A= $opt{'MailFrom'}B= &mailaddress()
ABresult
1X1
011
000
397 0 my $quit = 1;
398  
399 0 my ($smtp, @hello);
400  
401 push @hello, Hello => $opt{Hello}
402 0 ▶ if defined $opt{Hello};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt{"Hello"} 0 0 0
403  
404 push @hello, Port => $opt{Port}
405 0 ▶ if exists $opt{Port};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Port"} 0 0 0
406  
407 push @hello, Debug => $opt{Debug}
408 0 ▶ if exists $opt{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Debug"} 0 0 0
409  
410 0 ▶ if(!defined $host)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $host) { } 0 0 0
elsif (UNIVERSAL::isa($host, 'Net::SMTP') or UNIVERSAL::isa($host, 'Net::SMTP::SSL')) { } 0 0 0
411 0 { local $SIG{__DIE__};
412 0 my @hosts = qw(mailhost localhost);
413 unshift @hosts, split /\:/, $ENV{SMTPHOSTS}
414 0 ▶ if defined $ENV{SMTPHOSTS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"SMTPHOSTS"} 0 0 0
415  
416 0 foreach $host (@hosts)
417 0 { $smtp = eval { Net::SMTP->new($host, @hello) };
418 0 ▶ last if defined $smtp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $smtp 0 0 0
419 }
420 }
421 ▶ elsif(UNIVERSAL::isa($host,'Net::SMTP')
Condition0%0/3
UNIVERSAL::isa($host, "Net::SMTP") or UNIVERSAL::isa($host, "Net::SMTP::SSL")
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($host, "Net::SMTP") or UNIVERSAL::isa($host, "Net::SMTP::SSL")
UNIVERSAL::isa($host, "Net::SMTP") UNIVERSAL::isa($host, "Net::SMTP::SSL")
Truth table0%0/3
A or B
A= UNIVERSAL::isa($host, "Net::SMTP")B= UNIVERSAL::isa($host, "Net::SMTP::SSL")
ABresult
1X1
011
000
422 || UNIVERSAL::isa($host,'Net::SMTP::SSL'))
423 0 { $smtp = $host;
424 0 $quit = 0;
425 }
426 else
427 0 { local $SIG{__DIE__};
428 0 $smtp = eval { Net::SMTP->new($host, @hello) };
429 }
430  
431 0 ▶ defined $smtp or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $smtp or return () 0 0 0
432  
433 0 my $head = $self->cleaned_header_dup;
434  
435 # Who is it to
436  
437 0 ▶ my @rcpt = map { ref $_ ? @$_ : $_ } grep { defined } @opt{'To','Cc','Bcc'};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
438 0 ▶ @rcpt = map { $head->get($_) } qw(To Cc Bcc)
Branch: 1 branch
BranchTrueFalseTotal
unless @rcpt 0 0 0
439 unless @rcpt;
440  
441 0 my @addr = map {$_->address} Mail::Address->parse(@rcpt);
442 0 ▶ @addr or return ();
Branch: 1 branch
BranchTrueFalseTotal
@addr or return () 0 0 0
443  
444 0 $head->delete('Bcc');
445  
446 # Send it
447  
448 my $ok = $smtp->mail($envelope)
449 && $smtp->to(@addr)
450 0 ▶ && $smtp->data(join("", @{$head->header}, "\n", @{$self->body}));
Condition0%0/6
$smtp->mail($envelope) && $smtp->to(@addr) && $smtp->data(join('', @{$head->header;}, "\n", @{$self->body;}))
!ll&&!rl&&r
000
$smtp->mail($envelope) and $smtp->to(@addr)
!ll&&!rl&&r
000
MC/DC0%0/3
$smtp->mail($envelope) && $smtp->to(@addr) && $smtp->data(join('', @{$head->header;}, "\n", @{$self->body;}))
$smtp->mail($envelope) $smtp->to(@addr) $smtp->data(join('', @{$head->header;}, "\n", @{$self->body;}))
Truth table0%0/4
A and B && C
A= $smtp->mail($envelope)B= $smtp->to(@addr)C= $smtp->data(join('', @{$head->header;}, "\n", @{$self->body;}))
ABCresult
0XX0
10X0
1100
1111
451  
452 0 ▶ $quit && $smtp->quit;
Branch: 1 branch
BranchTrueFalseTotal
$quit and $smtp->quit 0 0 0
453 0 ▶ $ok ? @addr : ();
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
454 }
455  
456  
457 sub send($@)
458 0 ▶{ my ($self, $type, @args) = @_;
Subroutine send: not called CC=1 SCAR=6.9
Pod documented
459  
460 0 require Mail::Mailer;
461  
462 0 my $head = $self->cleaned_header_dup;
463 0 my $mailer = Mail::Mailer->new($type, @args);
464  
465 0 $mailer->open($head->header_hashref);
466 0 $self->print_body($mailer);
467 0 $mailer->close;
468 }
469  
470  
471 sub nntppost
472 0 ▶{ my ($self, %opt) = @_;
Subroutine nntppost: not called CC=10 SCAR=47.0
Pod documented
473  
474 0 require Net::NNTP;
475  
476 0 ▶ my $groups = $self->get('Newsgroups') || "";
Condition0%0/2
$self->get('Newsgroups') || ''
l!l
00
MC/DC0%0/1
$self->get('Newsgroups') || ''
$self->get('Newsgroups')
Truth table0%0/2
A
A= $self->get('Newsgroups')
Aresult
11
00
477 0 my @groups = split /[\s,]+/, $groups;
478 0 ▶ @groups or return ();
Branch: 1 branch
BranchTrueFalseTotal
@groups or return () 0 0 0
479  
480 0 my $head = $self->cleaned_header_dup;
481  
482 # Remove these incase the NNTP host decides to mail as well as me
483 0 $head->delete(qw(To Cc Bcc));
484  
485 0 my $news;
486 0 my $quit = 1;
487  
488 0 my $host = $opt{Host};
489 0 ▶ if(ref($host) && UNIVERSAL::isa($host,'Net::NNTP'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $host and UNIVERSAL::isa($host, 'Net::NNTP')) { } 0 0 0
Condition0%0/3
ref $host and UNIVERSAL::isa($host, "Net::NNTP")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $host and UNIVERSAL::isa($host, "Net::NNTP")
ref $host UNIVERSAL::isa($host, "Net::NNTP")
Truth table0%0/3
A and B
A= ref $hostB= UNIVERSAL::isa($host, "Net::NNTP")
ABresult
0X0
100
111
490 0 { $news = $host;
491 0 $quit = 0;
492 }
493 else
494 0 { my @opt = $opt{Host};
495  
496 push @opt, Port => $opt{Port}
497 0 ▶ if exists $opt{Port};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Port"} 0 0 0
498  
499 push @opt, Debug => $opt{Debug}
500 0 ▶ if exists $opt{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"Debug"} 0 0 0
501  
502 0 ▶ $news = Net::NNTP->new(@opt)
Branch: 1 branch
BranchTrueFalseTotal
$news = "Net::NNTP"->new(@opt) or return () 0 0 0
503 or return ();
504 }
505  
506 0 $news->post(@{$head->header}, "\n", @{$self->body});
507 0 my $rc = $news->code;
508  
509 0 ▶ $news->quit if $quit;
Branch: 1 branch
BranchTrueFalseTotal
if $quit 0 0 0
510  
511 0 ▶ $rc == 240 ? @groups : ();
Branch: 1 branch
BranchTrueFalseTotal
$rc == 240 ? : 0 0 0
512 }
513  
514  
515 sub escape_from
516 2 ▶{ my $body = shift->body;
Subroutine escape_from: called CC=1 SCAR=0.0
Pod documented
517 2 scalar grep { s/\A(>*From) />$1 /o } @$body;
518 }
519  
520  
521  
522 sub unescape_from
523 0 ▶{ my $body = shift->body;
Subroutine unescape_from: not called CC=1 SCAR=6.9
Pod documented
524 0 scalar grep { s/\A>(>*From) /$1 /o } @$body;
525 }
526  
527 # Don't tell people it exists
528 sub cleaned_header_dup()
529 0 ▶{ my $head = shift->head->dup;
Subroutine cleaned_header_dup: not called CC=8 SCAR=42.8
Pod undocumented
530  
531 0 $head->delete('From '); # Just in case :-)
532  
533 # An original message should not have any Received lines
534 0 $head->delete('Received');
535  
536 0 ▶ $head->replace('X-Mailer', "Perl5 Mail::Internet v".$Mail::Internet::VERSION)
Branch: 1 branch
BranchTrueFalseTotal
unless $head->count("X-Mailer") 0 0 0
537 unless $head->count('X-Mailer');
538  
539 0 ▶ my $name = eval {local $SIG{__DIE__}; (getpwuid($>))[6]} || $ENV{NAME} ||"";
Condition0%0/5
eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[6] } } || $ENV{'NAME'} || ''
l!l
00
eval { do { local $SIG{"__DIE__"}; (getpwuid $>)[6] } } or $ENV{"NAME"}
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[6] } } || $ENV{'NAME'} || ''
eval { do { local $SIG{"__DIE__"}; (getpwuid $>)[6] } } $ENV{"NAME"}
Truth table0%0/3
A or B
A= eval { do { local $SIG{"__DIE__"}; (getpwuid $>)[6] } }B= $ENV{"NAME"}
ABresult
1X1
011
000
540  
541 0 ▶ while($name =~ s/\([^\(\)]*\)//) { 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/\([^\(\)]*\)//) 0 0 0
542  
543 0 ▶ if($name =~ /[^\w\s]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[^\w\s]/) 0 0 0
544 0 { $name =~ s/"/\"/g;
545 0 $name = '"' . $name . '"';
546 }
547  
548 0 my $from = sprintf "%s <%s>", $name, mailaddress();
549 0 $from =~ s/\s{2,}/ /g;
550  
551 0 foreach my $tag (qw(From Sender))
552 0 ▶ { $head->get($tag) or $head->add($tag, $from);
Branch: 1 branch
BranchTrueFalseTotal
$head->get($tag) or $head->add($tag, $from) 0 0 0
553 }
554  
555 0 $head;
556 }
557  
558 2 1;
↑ Summary Mail/Util.pm »