Message/Construct/Reply.pm

filter: Statementstmt 91.4% 96 / 105 Branchbran 63.8% 60 / 94 Conditioncond 48.3% 30 / 62 MC/DCmcdc 16.2% 6 / 37 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 65.9% 205 / 311 CC 74 SCAR 47.0
CC
74
Cov
71%
reply
166.1
replyPrelude
15.9
replySubject
14.1
CRAP 110.2
« Message/Construct/Build.pm ↑ Summary Message/Field/Date.pm »
1 # Copyrights 2001-2022 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 distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message;
10 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '3.012';
12  
13  
14 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use Mail::Message::Body::Multipart;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 # tests in t/55reply1r.t, demo in the examples/ directory
23  
24 sub reply(@)
25 3 ▶{ my ($self, %args) = @_;
Subroutine reply: called CC=53 SCAR=51.1
Pod documented
26  
27 3 my $body = $args{body};
28 3 ▶ my $strip = !exists $args{strip_signature} || $args{strip_signature};
Condition66%2/3
!exists $args{'strip_signature'} || $args{'strip_signature'}
l!l&&r!l&&!r
201
MC/DC50%1/2
!exists $args{'strip_signature'} || $args{'strip_signature'}
!exists $args{'strip_signature'} $args{'strip_signature'}
Truth table66%2/3
not(A) || B
A= !exists $args{'strip_signature'}B= $args{'strip_signature'}
ABresult
1X1
011
000
29 3 ▶ my $include = $args{include} || 'INLINE';
Condition50%1/2
$args{'include'} || 'INLINE'
l!l
03
MC/DC0%0/1
$args{'include'} || 'INLINE'
$args{'include'}
Truth table50%1/2
A
A= $args{'include'}
Aresult
11
00
30  
31 3 ▶ if($include eq 'NO')
Branch: 2 branches
BranchTrueFalseTotal
if ($include eq 'NO') { } 0 3 3
elsif ($include eq 'INLINE' or $include eq 'ATTACH') { } 3 0 3
32 { # Throw away real body.
33 0 ▶ $body = Mail::Message::Body->new
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 0 0
34 (data => ["\n[The original message is not included]\n\n"])
35 unless defined $body;
36 }
37 ▶ elsif($include eq 'INLINE' || $include eq 'ATTACH')
Condition33%1/3
$include eq "INLINE" or $include eq "ATTACH"
l!l&&r!l&&!r
300
MC/DC0%0/2
$include eq "INLINE" or $include eq "ATTACH"
$include eq "INLINE" $include eq "ATTACH"
Truth table33%1/3
A or B
A= $include eq "INLINE"B= $include eq "ATTACH"
ABresult
1X1
011
000
38 {
39 3 ▶ unless(defined $body)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body) 3 0 3
40 { # text attachment
41 3 $body = $self->body;
42 3 ▶ $body = $body->part(0)->body if $body->isMultipart && $body->parts==1;
Branch: 1 branch
BranchTrueFalseTotal
if $body->isMultipart and $body->parts == 1 0 3 3
Condition33%1/3
$body->isMultipart and $body->parts == 1
!ll&&!rl&&r
300
MC/DC0%0/2
$body->isMultipart and $body->parts == 1
$body->isMultipart $body->parts == 1
Truth table33%1/3
A and B
A= $body->isMultipartB= $body->parts == 1
ABresult
0X0
100
111
43 3 ▶ $body = $body->nested->body if $body->isNested;
Branch: 1 branch
BranchTrueFalseTotal
if $body->isNested 0 3 3
44  
45 $body
46 = $strip && ! $body->isMultipart && !$body->isBinary
47 ? $body->decoded->stripSignature
48 ( pattern => $args{strip_signature}
49 , max_lines => $args{max_signature}
50 )
51 3 ▶ : $body->decoded;
Branch: 1 branch
BranchTrueFalseTotal
$strip && !$body->isMultipart && !$body->isBinary ? : 2 1 3
Condition66%4/6
$strip and not $body->isMultipart and not $body->isBinary
!ll&&!rl&&r
102
$strip and not $body->isMultipart
!ll&&!rl&&r
102
MC/DC33%1/3
$strip and not $body->isMultipart and not $body->isBinary
$strip not $body->isMultipart not $body->isBinary
Truth table50%2/4
A and not(B) and not(C)
A= $stripB= not $body->isMultipartC= not $body->isBinary
ABCresult
0XX0
10X0
1100
1111
52 }
53  
54 3 ▶ if($include eq 'INLINE' && $body->isMultipart) { $include = 'ATTACH' }
Branch: 2 branches
BranchTrueFalseTotal
if ($include eq 'INLINE' and $body->isMultipart) { } 0 3 3
elsif ($include eq 'INLINE' and $body->isBinary) { } 0 3 3
Condition33%1/3
$include eq "INLINE" and $body->isMultipart
!ll&&!rl&&r
030
MC/DC0%0/2
$include eq "INLINE" and $body->isMultipart
$include eq "INLINE" $body->isMultipart
Truth table33%1/3
A and B
A= $include eq "INLINE"B= $body->isMultipart
ABresult
0X0
100
111
55 ▶ elsif($include eq 'INLINE' && $body->isBinary)
Condition33%1/3
$include eq "INLINE" and $body->isBinary
!ll&&!rl&&r
030
MC/DC0%0/2
$include eq "INLINE" and $body->isBinary
$include eq "INLINE" $body->isBinary
Truth table33%1/3
A and B
A= $include eq "INLINE"B= $body->isBinary
ABresult
0X0
100
111
56 0 { $include = 'ATTACH';
57 0 $body = Mail::Message::Body::Multipart->new(parts => [$body]);
58 }
59  
60 3 ▶ if($include eq 'INLINE')
Branch: 1 branch
BranchTrueFalseTotal
if ($include eq "INLINE") 3 0 3
61 { my $quote
62 = defined $args{quote} ? $args{quote}
63 : exists $args{quote} ? undef
64 3 ▶ : '> ';
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'quote'} ? : 2 1 3
exists $args{'quote'} ? : 1 0 1
65  
66 3 ▶ if(defined $quote)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quote) 2 1 3
67 2 ▶ { my $quoting = ref $quote ? $quote : sub {$quote . $_};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
ref $quote ? : 1 1 2
68 2 $body = $body->foreachLine($quoting);
69 }
70 }
71 }
72 else
73 0 { $self->log(ERROR => "Cannot include reply source as $include.");
74 0 return;
75 }
76  
77 #
78 # Collect header info
79 #
80  
81 3 my $mainhead = $self->toplevel->head;
82  
83 # Where it comes from
84 3 my $from = delete $args{From};
85 3 ▶ unless(defined $from)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $from) 3 0 3
86 3 { my @from = $self->to;
87 3 ▶ $from = \@from if @from;
Branch: 1 branch
BranchTrueFalseTotal
if @from 3 0 3
88 }
89  
90 # To whom to send
91 my $to = delete $args{To}
92 3 ▶ || $mainhead->get('reply-to') || $mainhead->get('from');
Condition33%2/6
delete $args{'To'} || $mainhead->get('reply-to') || $mainhead->get('from')
l!l&&r!l&&!r
030
delete $args{"To"} or $mainhead->get("reply-to")
l!l&&r!l&&!r
003
MC/DC0%0/3
delete $args{'To'} || $mainhead->get('reply-to') || $mainhead->get('from')
delete $args{"To"} $mainhead->get("reply-to") $mainhead->get('from')
Truth table25%1/4
A or B || C
A= delete $args{"To"}B= $mainhead->get("reply-to")C= $mainhead->get('from')
ABCresult
1XX1
01X1
0011
0000
93 3 ▶ defined $to or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $to or return 0 3 3
94  
95 # Add Cc
96 3 my $cc = delete $args{Cc};
97 3 ▶ if(!defined $cc && $args{group_reply})
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cc and $args{"group_reply"}) 1 2 3
Condition66%2/3
not defined $cc and $args{"group_reply"}
!ll&&!rl&&r
021
MC/DC50%1/2
not defined $cc and $args{"group_reply"}
not defined $cc $args{"group_reply"}
Truth table66%2/3
not(A) and B
A= not defined $ccB= $args{"group_reply"}
ABresult
0X0
100
111
98 1 { my @cc = $self->cc;
99 1 ▶ $cc = [ $self->cc ] if @cc;
Branch: 1 branch
BranchTrueFalseTotal
if @cc 1 0 1
100 }
101  
102 # Create a subject
103 3 my $srcsub = delete $args{Subject};
104 3 ▶ my $subject
Branch: 2 branches
BranchTrueFalseTotal
!defined($srcsub) ? : 3 0 3
ref $srcsub ? : 0 0 0
105 = ! defined $srcsub ? $self->replySubject($self->subject)
106 : ref $srcsub ? $srcsub->($self->subject)
107 : $srcsub;
108  
109 # Create a nice message-id
110 3 my $msgid = delete $args{'Message-ID'};
111 3 ▶ $msgid = "<$msgid>" if $msgid && $msgid !~ /^\s*\<.*\>\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $msgid and not $msgid =~ /^\s*\<.*\>\s*$/ 0 3 3
Condition33%1/3
$msgid and not $msgid =~ /^\s*\<.*\>\s*$/
!ll&&!rl&&r
300
MC/DC0%0/2
$msgid and not $msgid =~ /^\s*\<.*\>\s*$/
$msgid not $msgid =~ /^\s*\<.*\>\s*$/
Truth table33%1/3
A and not(B)
A= $msgidB= not $msgid =~ /^\s*\<.*\>\s*$/
ABresult
0X0
100
111
112  
113 # Thread information
114 3 my $origid = '<'.$self->messageId.'>';
115 3 my $refs = $mainhead->get('references');
116  
117 # Prelude
118 my $prelude
119 = defined $args{prelude} ? $args{prelude}
120 : exists $args{prelude} ? undef
121 3 ▶ : [ $self->replyPrelude($to) ];
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'prelude'} ? : 0 3 3
exists $args{'prelude'} ? : 1 2 3
122  
123 3 ▶ $prelude = Mail::Message::Body->new(data => $prelude)
Branch: 1 branch
BranchTrueFalseTotal
if defined $prelude and not builtin::blessed($prelude) 2 1 3
Condition66%2/3
defined $prelude and not builtin::blessed($prelude)
!ll&&!rl&&r
102
MC/DC50%1/2
defined $prelude and not builtin::blessed($prelude)
defined $prelude not builtin::blessed($prelude)
Truth table66%2/3
A and not(B)
A= defined $preludeB= not builtin::blessed($prelude)
ABresult
0X0
100
111
124 if defined $prelude && ! blessed $prelude;
125
126 3 my $postlude = $args{postlude};
127 3 ▶ $postlude = Mail::Message::Body->new(data => $postlude)
Branch: 1 branch
BranchTrueFalseTotal
if defined $postlude and not builtin::blessed($postlude) 0 3 3
Condition66%2/3
defined $postlude and not builtin::blessed($postlude)
!ll&&!rl&&r
120
MC/DC0%0/2
defined $postlude and not builtin::blessed($postlude)
defined $postlude not builtin::blessed($postlude)
Truth table66%2/3
A and not(B)
A= defined $postludeB= not builtin::blessed($postlude)
ABresult
0X0
100
111
128 if defined $postlude && ! blessed $postlude;
129  
130 #
131 # Create the message.
132 #
133  
134 3 my $total;
135 3 ▶ if($include eq 'NO') {$total = $body}
Branch: 2 branches
BranchTrueFalseTotal
if ($include eq 'NO') { } 0 3 3
elsif ($include eq 'INLINE') { } 3 0 3
136 elsif($include eq 'INLINE')
137 3 { my $signature = $args{signature};
138 3 ▶ $signature = $signature->body
Branch: 1 branch
BranchTrueFalseTotal
if defined $signature and $signature->isa("Mail::Message") 0 3 3
Condition33%1/3
defined $signature and $signature->isa("Mail::Message")
!ll&&!rl&&r
300
MC/DC0%0/2
defined $signature and $signature->isa("Mail::Message")
defined $signature $signature->isa("Mail::Message")
Truth table33%1/3
A and B
A= defined $signatureB= $signature->isa("Mail::Message")
ABresult
0X0
100
111
139 if defined $signature && $signature->isa('Mail::Message');
140  
141 3 ▶ $total = $body->concatenate
Branch: 1 branch
BranchTrueFalseTotal
defined $signature ? : 0 3 3
142 ( $prelude, $body, $postlude
143 , (defined $signature ? "-- \n" : undef), $signature
144 );
145 }
146 3 ▶ if($include eq 'ATTACH')
Branch: 1 branch
BranchTrueFalseTotal
if ($include eq "ATTACH") 0 3 3
147 {
148 0 my $intro = $prelude->concatenate
149 ( $prelude
150 , [ "\n", "[Your message is attached]\n" ]
151 , $postlude
152 );
153  
154 $total = Mail::Message::Body::Multipart->new
155 0 ( parts => [ $intro, $body, $args{signature} ]
156 );
157 }
158  
159 3 ▶ my $msgtype = $args{message_type} || 'Mail::Message';
Condition50%1/2
$args{'message_type'} || 'Mail::Message'
l!l
03
MC/DC0%0/1
$args{'message_type'} || 'Mail::Message'
$args{'message_type'}
Truth table50%1/2
A
A= $args{'message_type'}
Aresult
11
00
160  
161 3 ▶ my $reply = $msgtype->buildFromBody
Branch: 1 branch
BranchTrueFalseTotal
$refs ? : 0 3 3
Condition50%1/2
$from || 'Undisclosed senders:;'
l!l
30
MC/DC0%0/1
$from || 'Undisclosed senders:;'
$from
Truth table50%1/2
A
A= $from
Aresult
11
00
162 ( $total
163 , From => $from || 'Undisclosed senders:;'
164 , To => $to
165 , Subject => $subject
166 , 'In-Reply-To' => $origid
167 , References => ($refs ? "$refs $origid" : $origid)
168 );
169  
170 3 my $newhead = $reply->head;
171 3 ▶ $newhead->set(Cc => $cc) if $cc;
Branch: 1 branch
BranchTrueFalseTotal
if $cc 1 2 3
172 3 ▶ $newhead->set(Bcc => delete $args{Bcc}) if $args{Bcc};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Bcc"} 1 2 3
173 $newhead->add($_ => $args{$_})
174 3 for sort grep /^[A-Z]/, keys %args;
175  
176 # Ready
177  
178 3 $self->log(PROGRESS => 'Reply created from '.$origid);
179 3 $self->label(replied => 1);
180 3 $reply;
181 }
182  
183 #------------------------------------------
184  
185  
186 # tests in t/35reply1rs.t
187  
188 sub replySubject($)
189 24 ▶{ my ($thing, $subject) = @_;
Subroutine replySubject: called CC=14 SCAR=26.5
Pod documented
190 24 ▶ $subject = 'your mail' unless defined $subject && length $subject;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subject and length $subject 2 22 24
Condition100%3/3
defined $subject and length $subject
!ll&&!rl&&r
1122
MC/DC100%2/2
defined $subject and length $subject
defined $subject length $subject
Truth table100%3/3
A and B
A= defined $subjectB= length $subject
ABresult
0X0
100
111
191 24 my @subject = split /\:/, $subject;
192 24 my $re_count = 1;
193  
194 # Strip multiple Re's from the start.
195  
196 24 ▶ while(@subject)
Branch: 1 branch
BranchTrueFalseTotal
if (@subject) 38 0 38
197 38 ▶ { last if $subject[0] =~ /[A-QS-Za-qs-z][A-DF-Za-df-z]/;
Branch: 1 branch
BranchTrueFalseTotal
if $subject[0] =~ /[A-QS-Za-qs-z][A-DF-Za-df-z]/ 24 14 38
198  
199 14 for(shift @subject)
200 14 ▶ { while( /\bRe(?:\[\s*(\d+)\s*\]|\b)/g )
Branch: 1 branch
BranchTrueFalseTotal
if (/\bRe(?:\[\s*(\d+)\s*\]|\b)/g) 17 14 31
201 17 ▶ { $re_count += defined $1 ? $1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 4 13 17
202 }
203 }
204 }
205  
206 # Strip multiple Re's from the end.
207  
208 24 ▶ if(@subject)
Branch: 1 branch
BranchTrueFalseTotal
if (@subject) 24 0 24
209 24 { for($subject[-1])
210 24 ▶ { $re_count++ while s/\s*\(\s*(re|forw)\W*\)\s*$//i;
Branch: 1 branch
BranchTrueFalseTotal
s/\s*\(\s*(re|forw)\W*\)\s*$//i and do { ++$re_count } 9 24 33
211 }
212 }
213  
214 # Create the new subject string.
215  
216 24 ▶ my $text = (join ':', @subject) || 'your mail';
Condition50%1/2
join(':', @subject) || 'your mail'
l!l
240
MC/DC0%0/1
join(':', @subject) || 'your mail'
join(':', @subject)
Truth table50%1/2
A
A= join(':', @subject)
Aresult
11
00
217 24 for($text)
218 24 { s/^\s+//;
219 24 s/\s+$//;
220 }
221  
222 24 ▶ $re_count==1 ? "Re: $text" : "Re[$re_count]: $text";
Branch: 1 branch
BranchTrueFalseTotal
$re_count == 1 ? : 8 16 24
223 }
224  
225 #------------------------------------------
226  
227  
228 sub replyPrelude($)
229 2 ▶{ my ($self, $who) = @_;
Subroutine replyPrelude: called CC=9 SCAR=27.7
Pod documented
230
231 2 ▶ $who = $who->[0] if ref $who eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $who eq "ARRAY" 0 2 2
232  
233 2 ▶ my $user
Branch: 3 branches
BranchTrueFalseTotal
!defined($who) ? : 0 2 2
!ref($who) ? : 0 2 2
$who->isa('Mail::Message::Field') ? : 2 0 2
234 = !defined $who ? undef
235 : !ref $who ? (Mail::Address->parse($who))[0]
236 : $who->isa('Mail::Message::Field') ? ($who->addresses)[0]
237 : $who;
238  
239 2 ▶ my $from
Branch: 1 branch
BranchTrueFalseTotal
ref $user && $user->isa('Mail::Address') ? : 2 0 2
Condition33%3/9
ref $user and $user->isa("Mail::Address")
!ll&&!rl&&r
002
$user->name or $user->address or $user->format
l!l&&r!l&&!r
200
$user->name or $user->address
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $user and $user->isa("Mail::Address")
ref $user $user->isa("Mail::Address")
MC/DC0%0/3
$user->name or $user->address or $user->format
$user->name $user->address $user->format
Truth table33%1/3
A and B
A= ref $userB= $user->isa("Mail::Address")
ABresult
0X0
100
111
Truth table25%1/4
A or B or C
A= $user->nameB= $user->addressC= $user->format
ABCresult
1XX1
01X1
0011
0000
240 = ref $user && $user->isa('Mail::Address')
241 ? ($user->name || $user->address || $user->format)
242 : 'someone';
243  
244 2 my $time = gmtime $self->timestamp;
245 2 "On $time, $from wrote:\n";
246 }
247  
248 3 1;
« Message/Construct/Build.pm ↑ Summary Message/Field/Date.pm »