Mail/Make.pm

filter: Statementstmt 68.3% 491 / 718 Branchbran 45.9% 217 / 472 Conditioncond 32.1% 133 / 414 MC/DCmcdc 13.3% 31 / 233 Subroutinesub 71.8% 46 / 64 Podpod 94.7% 36 / 38 totaltotal 49.2% 954 / 1939 CC 413 SCAR 56.4
CC
413
Cov
52%
_hti_fetch
1852.6
smtpsend
301.5
gpg_sign_encrypt
156.0
CRAP 281.1
↑ Summary Mail/Make/SMIME.pm »
1 ##----------------------------------------------------------------------------
2 ## MIME Email Builder - ~/lib/Mail/Make.pm
3 ## Version v0.23.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/03/02
7 ## Modified 2026/05/10
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package Mail::Make;
15 BEGIN
16 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 warnings::register_categories( 'Mail::Make' );
20 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use vars qw( $VERSION $EXCEPTION_CLASS $CRLF $MAX_BODY_IN_MEMORY_SIZE );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use Mail::Make::Entity;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶ use Mail::Make::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶ use Mail::Make::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use Mail::Make::Headers::Subject;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 our $CRLF = "\015\012";
28 6 our $MAX_BODY_IN_MEMORY_SIZE = 1_048_576; # 1 MiB default
29 6 our $EXCEPTION_CLASS = 'Mail::Make::Exception';
30 6 our $VERSION = 'v0.23.0';
31 }
32  
33 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 sub init
37 72 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod documented
38 72 my $self = shift( @_ );
39 # Top-level envelope headers live in a Mail::Make::Headers instance.
40 # All RFC 2822 envelope fields (From, To, Cc, Bcc, Subject, Date, Message-ID,
41 # In-Reply-To, References, Reply-To, Sender) are stored there directly, avoiding any
42 # duplication between Mail::Make and the final Mail::Make::Entity's headers object.
43 72 $self->{_headers} = Mail::Make::Headers->new;
44 # Accumulated body parts (Mail::Make::Entity objects, in order of addition)
45 72 $self->{_parts} = [];
46 # When the serialised message exceeds this byte threshold (or when use_temp_file is true),
47 # as_string_ref() spools to a temporary file rather than keeping the entire message in RAM.
48 # Set to 0 or undef to disable file spooling entirely.
49 72 $self->{max_body_in_memory_size} = $MAX_BODY_IN_MEMORY_SIZE;
50 72 $self->{use_temp_file} = 0;
51 72 $self->{_exception_class} = $EXCEPTION_CLASS;
52 72 $self->{_init_strict_use_sub} = 1;
53 72 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 72 0 72
54 72 return( $self );
55 }
56  
57 # as_entity()
58 # Returns the fully assembled top-level Mail::Make::Entity object.
59 # The MIME structure is chosen based on the accumulated parts:
60 #
61 # Only plain text -> text/plain
62 # Only HTML -> text/html
63 # Plain + HTML -> multipart/alternative
64 # Any of the above + inlines -> multipart/related
65 # Any of the above + attachments -> multipart/mixed
66 sub as_entity
67 80 ▶{
Subroutine as_entity: called CC=30 SCAR=34.3
Pod documented
68 80 my $self = shift( @_ );
69  
70 # When gpg_sign() / gpg_encrypt() / gpg_sign_encrypt() have already assembled the
71 # top-level entity (stored in _gpg_entity), return it directly. Envelope headers have
72 # already been merged by _wrap_in_mail().
73 80 ▶ return( $self->{_gpg_entity} ) if( defined( $self->{_gpg_entity} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_gpg_entity"} 0 80 80
74  
75 # S/MIME: entity pre-assembled by Mail::Make::SMIME::_build_from_smime_output().
76 # Headers are already embedded in the parsed entity; return it directly.
77 80 ▶ return( $self->{_smime_entity} ) if( defined( $self->{_smime_entity} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_smime_entity"} 0 80 80
78  
79 # Partition accumulated parts by role
80 80 my( @plain, @html, @inline, @attachment );
81 80 foreach my $part ( @{$self->{_parts}} )
82 {
83 132 ▶ my $type = lc( $part->effective_type // '' );
Condition50%1/2
$part->effective_type // ""
l!l
1320
MC/DC0%0/1
$part->effective_type // ""
$part->effective_type
Truth table50%1/2
A
A= $part->effective_type
Aresult
11
00
84 # Use get() for the raw string value; content_disposition() returns a typed
85 # object which stringifies to '' when uninitialised, making // unreliable.
86 132 ▶ my $cd = lc( $part->headers->get( 'Content-Disposition' ) // '' );
Condition100%2/2
$part->headers->get("Content-Disposition") // ""
l!l
4092
MC/DC100%1/1
$part->headers->get("Content-Disposition") // ""
$part->headers->get("Content-Disposition")
Truth table100%2/2
A
A= $part->headers->get("Content-Disposition")
Aresult
11
00
87 132 ▶ if( $type eq 'text/plain' && $cd !~ /attachment/ )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'text/plain' and not $cd =~ /attachment/) { } 58 74 132
elsif ($type eq 'text/html' and not $cd =~ /attachment/) { } 35 39 74
elsif ($cd =~ /inline/ or $part->headers->get('Content-ID')) { } 28 11 39
Condition66%2/3
$type eq "text/plain" and not $cd =~ /attachment/
!ll&&!rl&&r
74058
MC/DC50%1/2
$type eq "text/plain" and not $cd =~ /attachment/
$type eq "text/plain" not $cd =~ /attachment/
Truth table66%2/3
A and not(B)
A= $type eq "text/plain"B= not $cd =~ /attachment/
ABresult
0X0
100
111
88 {
89 58 push( @plain, $part );
90 }
91 ▶ elsif( $type eq 'text/html' && $cd !~ /attachment/ )
Condition66%2/3
$type eq "text/html" and not $cd =~ /attachment/
!ll&&!rl&&r
39035
MC/DC50%1/2
$type eq "text/html" and not $cd =~ /attachment/
$type eq "text/html" not $cd =~ /attachment/
Truth table66%2/3
A and not(B)
A= $type eq "text/html"B= not $cd =~ /attachment/
ABresult
0X0
100
111
92 {
93 35 push( @html, $part );
94 }
95 ▶ elsif( $cd =~ /inline/ || $part->headers->get( 'Content-ID' ) )
Condition66%2/3
$cd =~ /inline/ or $part->headers->get("Content-ID")
l!l&&r!l&&!r
28011
MC/DC50%1/2
$cd =~ /inline/ or $part->headers->get("Content-ID")
$cd =~ /inline/ $part->headers->get("Content-ID")
Truth table66%2/3
A or B
A= $cd =~ /inline/B= $part->headers->get("Content-ID")
ABresult
1X1
011
000
96 {
97 # A part is classified as inline when it carries Content-Disposition:
98 # inline OR a Content-ID (or both). Either signal is sufficient: a
99 # Content-ID alone means the HTML references it via cid:, and
100 # Content-Disposition: inline without a Content-ID is caught by the
101 # guard below, which returns an error.
102 28 push( @inline, $part );
103 }
104 else
105 {
106 11 push( @attachment, $part );
107 }
108 }
109  
110 # NOTE: Step 1 & 2: assemble body, wrapping html+inline in multipart/related
111 # when applicable. The resulting structure depends on what parts are present:
112 #
113 # plain only -> text/plain
114 # html only -> text/html
115 # html + inline -> multipart/related( text/html, image... )
116 # plain + html -> multipart/alternative( text/plain, text/html )
117 # plain + html + inline -> multipart/alternative(
118 # text/plain,
119 # multipart/related( text/html, image... )
120 # )
121 #
122 # Inline parts without a Content-ID are rejected: the HTML cannot reference
123 # them via cid: and the message would be broken.
124 80 ▶ if( @inline )
Branch: 1 branch
BranchTrueFalseTotal
if (@inline) 27 53 80
125 {
126 27 my @missing_cid = grep { !$_->headers->get( 'Content-ID' ) } @inline;
127 27 ▶ if( @missing_cid )
Branch: 1 branch
BranchTrueFalseTotal
if (@missing_cid) 1 26 27
128 {
129 1 return( $self->error( scalar( @missing_cid ), " inline part(s) are missing a Content-ID. Each inline part must have a 'cid' or 'id' so the HTML can reference it via cid:UUID. Use attach_inline( ..., id => 'your-uuid.ext' )." ) );
130 }
131 }
132  
133 # Build the html entity, then optionally wrap it with its inline parts
134 79 ▶ my $html_entity = @html ? $html[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@html ? : 34 45 79
135 79 my $related_entity;
136 79 ▶ if( $html_entity && @inline )
Branch: 1 branch
BranchTrueFalseTotal
if ($html_entity and @inline) { } 26 53 79
Condition100%3/3
$html_entity and @inline
!ll&&!rl&&r
45826
MC/DC100%2/2
$html_entity and @inline
$html_entity @inline
Truth table100%3/3
A and B
A= $html_entityB= @inline
ABresult
0X0
100
111
137 {
138 26 ▶ $related_entity = Mail::Make::Entity->build( type => 'multipart/related' ) ||
Condition50%1/2
'Mail::Make::Entity'->build('type', 'multipart/related') || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
260
MC/DC0%0/1
'Mail::Make::Entity'->build('type', 'multipart/related') || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build('type', 'multipart/related')
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build('type', 'multipart/related')
Aresult
11
00
139 return( $self->pass_error( Mail::Make::Entity->error ) );
140 26 $related_entity->add_part( $html_entity );
141 26 $related_entity->add_part( $_ ) for( @inline );
142 }
143 else
144 {
145 53 $related_entity = $html_entity;
146 }
147  
148 79 my $body_entity;
149 79 ▶ if( @plain && $related_entity )
Branch: 3 branches
BranchTrueFalseTotal
if (@plain and $related_entity) { } 14 65 79
elsif ($related_entity) { } 20 45 65
elsif (@plain) { } 44 1 45
Condition100%3/3
@plain and $related_entity
!ll&&!rl&&r
214414
MC/DC100%2/2
@plain and $related_entity
@plain $related_entity
Truth table100%3/3
A and B
A= @plainB= $related_entity
ABresult
0X0
100
111
150 {
151 # plain + html (with or without inline): multipart/alternative
152 14 ▶ $body_entity = Mail::Make::Entity->build( type => 'multipart/alternative' ) ||
Condition50%1/2
'Mail::Make::Entity'->build('type', 'multipart/alternative') || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
140
MC/DC0%0/1
'Mail::Make::Entity'->build('type', 'multipart/alternative') || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build('type', 'multipart/alternative')
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build('type', 'multipart/alternative')
Aresult
11
00
153 return( $self->pass_error( Mail::Make::Entity->error ) );
154 14 $body_entity->add_part( $_ ) for( @plain );
155 14 $body_entity->add_part( $related_entity );
156 }
157 elsif( $related_entity )
158 {
159 20 $body_entity = $related_entity;
160 }
161 elsif( @plain )
162 {
163 44 $body_entity = $plain[0];
164 }
165 else
166 {
167 1 return( $self->error( "No body parts have been added." ) );
168 }
169  
170 # NOTE: Step 3: wrap in multipart/mixed if there are attachments
171 78 my $top_entity = $body_entity;
172 78 ▶ if( @attachment )
Branch: 1 branch
BranchTrueFalseTotal
if (@attachment) 8 70 78
173 {
174 8 ▶ $top_entity = Mail::Make::Entity->build( type => 'multipart/mixed' ) ||
Condition50%1/2
'Mail::Make::Entity'->build('type', 'multipart/mixed') || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
80
MC/DC0%0/1
'Mail::Make::Entity'->build('type', 'multipart/mixed') || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build('type', 'multipart/mixed')
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build('type', 'multipart/mixed')
Aresult
11
00
175 return( $self->pass_error( Mail::Make::Entity->error ) );
176 8 $top_entity->add_part( $body_entity );
177 8 $top_entity->add_part( $_ ) for( @attachment );
178 }
179  
180 # NOTE: Step 4: transfer envelope headers to the top-level entity
181 # We merge our own _headers into the entity's headers object so that MIME-specific
182 # headers already set on the entity (Content-Type, CTE, etc.) take precedence, while
183 # envelope headers come from _headers.
184 # Any header already present in the entity headers is left untouched.
185 78 my $ent_headers = $top_entity->headers;
186  
187 # Auto-generate Date if not set
188 $self->{_headers}->init_header(
189 78 'Date' => $self->_format_date()
190 );
191  
192 # Auto-generate Message-ID if not set
193 78 ▶ unless( $self->{_headers}->exists( 'Message-ID' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_headers"}->exists("Message-ID")) 65 13 78
194 {
195 $self->{_headers}->message_id( { generate => 1, domain => $self->_default_domain } ) ||
196 65 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->message_id({"generate", 1, "domain", $self->_default_domain}) or return $self->pass_error($self->{"_headers"}->error) 65 0 65
197 }
198  
199 # MIME-Version is always added to the entity's own headers (not the envelope), since
200 # it belongs at the top of the MIME structure.
201 78 $ent_headers->init_header( 'MIME-Version' => '1.0' );
202  
203 # Merge envelope headers into the entity: each field from _headers that is not already
204 # present in ent_headers is copied over.
205 $self->{_headers}->scan( sub
206 392 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
207 392 my( $name, $value ) = @_;
208 392 $ent_headers->init_header( $name => $value );
209 392 return(1);
210 78 });
211  
212 78 return( $top_entity );
213 }
214  
215 # as_string()
216 # Assembles the message and returns it as a plain string, consistent with
217 # MIME::Entity::stringify. Use print($fh) to avoid loading the whole message into memory,
218 # or as_string_ref() to avoid a string copy.
219 sub as_string
220 26 ▶{
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
221 26 my $self = shift( @_ );
222 26 ▶ my $entity = $self->as_entity || return( $self->pass_error );
Condition100%2/2
$self->as_entity || (return $self->pass_error)
l!l
251
MC/DC100%1/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table100%2/2
A
A= $self->as_entity
Aresult
11
00
223 25 return( $entity->as_string( @_ ) );
224 }
225  
226 # as_string_ref()
227 # Returns the assembled message as a scalar reference (no string copy).
228 # When use_temp_file is true, or the serialised entity size exceeds max_body_in_memory_size,
229 # the message is written to a Module::Generic::Scalar buffer, thus keeping peak RAM use
230 # to a single copy rather than two overlapping buffers (the serialisation buffer plus the
231 # returned string).
232 sub as_string_ref
233 0 ▶{
Subroutine as_string_ref: not called CC=8 SCAR=42.8
Pod documented
234 0 my $self = shift( @_ );
235 0 ▶ my $entity = $self->as_entity || return( $self->pass_error );
Condition0%0/2
$self->as_entity || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table0%0/2
A
A= $self->as_entity
Aresult
11
00
236 0 my $threshold = $self->{max_body_in_memory_size};
237 0 my $force_file = $self->{use_temp_file};
238  
239 # Fast path: build directly in memory when neither condition applies
240 0 ▶ unless( $force_file || ( defined( $threshold ) && $threshold > 0 && $entity->length > $threshold ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($force_file or defined $threshold and $threshold > 0 and $entity->length > $threshold) 0 0 0
Condition0%0/9
$force_file or defined $threshold and $threshold > 0 and $entity->length > $threshold
l!l&&r!l&&!r
000
defined $threshold and $threshold > 0 and $entity->length > $threshold
!ll&&!rl&&r
000
defined $threshold and $threshold > 0
!ll&&!rl&&r
000
MC/DC0%0/4
$force_file or defined $threshold and $threshold > 0 and $entity->length > $threshold
$force_file defined $threshold $threshold > 0 $entity->length > $threshold
Truth table0%0/5
A or B and C and D
A= $force_fileB= defined $thresholdC= $threshold > 0D= $entity->length > $threshold
ABCDresult
1XXX1
01111
00XX0
010X0
01100
241 {
242 0 return( $entity->as_string_ref );
243 }
244  
245 # new_scalar() is inherited from Module::Generic, and returns a Module::Generic::Scalar object
246 0 my $buf = $self->new_scalar;
247 # In-memory fielhandle; returns a Module::Generic::Scalar::IO object
248 0 ▶ my $fh = $buf->open( '>', { binmode => ':raw', autoflush => 1 } ) || return( $buf->error );
Condition0%0/2
$buf->open('>', {'binmode', ':raw', 'autoflush', 1}) || (return $buf->error)
l!l
00
MC/DC0%0/1
$buf->open('>', {'binmode', ':raw', 'autoflush', 1}) || (return $buf->error)
$buf->open('>', {'binmode', ':raw', 'autoflush', 1})
Truth table0%0/2
A
A= $buf->open('>', {'binmode', ':raw', 'autoflush', 1})
Aresult
11
00
249 0 ▶ $entity->print( $fh ) || return( $self->pass_error( $entity->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$entity->print($fh) or return $self->pass_error($entity->error) 0 0 0
250 # The scalar object stringifies as necessary.
251 0 return( $buf );
252 }
253  
254 # attach( %opts )
255 # Adds a standard (downloadable) attachment.
256 # Recognised keys: path, data, type, filename, charset, encoding, description
257 sub attach
258 12 ▶{
Subroutine attach: called CC=10 SCAR=23.8
Pod documented
259 12 my $self = shift( @_ );
260 # Detect positional shorthand: attach( '/path/to/file.pdf' ) or
261 # attach( '/path/to/file.pdf', encoding => 'base64', ... )
262 # Triggered when argument count is odd and the first argument is a plain scalar
263 # (not a reference), contains no newline, and resolves to an existing file.
264 12 ▶ if( ( scalar( @_ ) % 2 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and index("$_[0]", "\n") == -1) 5 7 12
Condition66%6/9
scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and index("$_[0]", "\n") == -1
!ll&&!rl&&r
705
scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"")
!ll&&!rl&&r
705
not ref $_[0] or $self->_can_overload($_[0], "\"\"")
l!l&&r!l&&!r
140
MC/DC25%1/4
scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and index("$_[0]", "\n") == -1
scalar(@_) % 2 not ref $_[0] $self->_can_overload($_[0], "\"\"") index("$_[0]", "\n") == -1
Truth table50%3/6
A and not(B) or C and D
A= scalar(@_) % 2B= not ref $_[0]C= $self->_can_overload($_[0], "\"\"")D= index("$_[0]", "\n") == -1
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
265 ( !ref( $_[0] ) || $self->_can_overload( $_[0] => '""' ) ) &&
266 index( "$_[0]", "\n" ) == -1 )
267 {
268 # shift() first to avoid $_[0] being altered by new_file() resolution
269 5 my $f = $self->new_file( shift( @_ ) ); # Module::Generic::File will trigger stringification
270 5 ▶ if( $f->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($f->exists) 5 0 5
271 {
272 # then, we pass it back here:
273 5 unshift( @_, path => $f );
274 }
275 }
276 12 my $opts = $self->_get_args_as_hash( @_ );
277 12 ▶ unless( defined( $opts->{data} ) || defined( $opts->{path} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"data"} or defined $opts->{"path"}) 1 11 12
Condition66%2/3
defined $opts->{"data"} or defined $opts->{"path"}
l!l&&r!l&&!r
0111
MC/DC50%1/2
defined $opts->{"data"} or defined $opts->{"path"}
defined $opts->{"data"} defined $opts->{"path"}
Truth table66%2/3
A or B
A= defined $opts->{"data"}B= defined $opts->{"path"}
ABresult
1X1
011
000
278 {
279 1 return( $self->error( "The option 'data' or 'path' is required." ) );
280 }
281 11 ▶ $opts->{disposition} //= 'attachment';
Condition50%1/2
$opts->{"disposition"} //= "attachment"
l!l
011
MC/DC0%0/1
$opts->{"disposition"} //= "attachment"
$opts->{"disposition"}
Truth table50%1/2
A
A= $opts->{"disposition"}
Aresult
11
00
282 11 ▶ my $entity = Mail::Make::Entity->build( %$opts ) ||
Condition50%1/2
'Mail::Make::Entity'->build(%$opts) || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
110
MC/DC0%0/1
'Mail::Make::Entity'->build(%$opts) || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build(%$opts)
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build(%$opts)
Aresult
11
00
283 return( $self->pass_error( Mail::Make::Entity->error ) );
284 11 push( @{$self->{_parts}}, $entity );
285 11 return( $self );
286 }
287  
288 # attach_inline( %opts )
289 # Adds an inline part (e.g. an image referenced via cid: in HTML).
290 # 'id' or 'cid' is required.
291 sub attach_inline
292 26 ▶{
Subroutine attach_inline: called CC=8 SCAR=21.5
Pod documented
293 26 my $self = shift( @_ );
294 26 my $opts = $self->_get_args_as_hash( @_ );
295 26 ▶ unless( defined( $opts->{data} ) || defined( $opts->{path} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"data"} or defined $opts->{"path"}) 0 26 26
Condition66%2/3
defined $opts->{"data"} or defined $opts->{"path"}
l!l&&r!l&&!r
16100
MC/DC0%0/2
defined $opts->{"data"} or defined $opts->{"path"}
defined $opts->{"data"} defined $opts->{"path"}
Truth table66%2/3
A or B
A= defined $opts->{"data"}B= defined $opts->{"path"}
ABresult
1X1
011
000
296 {
297 0 return( $self->error( "The option 'data' or 'path' is required." ) );
298 }
299 26 ▶ unless( defined( $opts->{id} ) || defined( $opts->{cid} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"id"} or defined $opts->{"cid"}) 1 25 26
Condition100%3/3
defined $opts->{"id"} or defined $opts->{"cid"}
l!l&&r!l&&!r
3221
MC/DC100%2/2
defined $opts->{"id"} or defined $opts->{"cid"}
defined $opts->{"id"} defined $opts->{"cid"}
Truth table100%3/3
A or B
A= defined $opts->{"id"}B= defined $opts->{"cid"}
ABresult
1X1
011
000
300 {
301 1 return( $self->error( "The option 'id' or 'cid' is required for inline parts." ) );
302 }
303 # Normalise: Entity->build() expects 'cid'
304 25 ▶ $opts->{cid} //= delete( $opts->{id} );
Condition66%2/3
$opts->{"cid"} //= delete $opts->{"id"}
l!l&&r!l&&!r
2230
MC/DC0%0/2
$opts->{"cid"} //= delete $opts->{"id"}
$opts->{"cid"} delete $opts->{"id"}
Truth table66%2/3
A //= B
A= $opts->{"cid"}B= delete $opts->{"id"}
ABresult
1X1
011
000
305 25 ▶ $opts->{disposition} //= 'inline';
Condition50%1/2
$opts->{"disposition"} //= "inline"
l!l
025
MC/DC0%0/1
$opts->{"disposition"} //= "inline"
$opts->{"disposition"}
Truth table50%1/2
A
A= $opts->{"disposition"}
Aresult
11
00
306 25 ▶ my $entity = Mail::Make::Entity->build( %$opts ) ||
Condition50%1/2
'Mail::Make::Entity'->build(%$opts) || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
250
MC/DC0%0/1
'Mail::Make::Entity'->build(%$opts) || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build(%$opts)
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build(%$opts)
Aresult
11
00
307 return( $self->pass_error( Mail::Make::Entity->error ) );
308 25 push( @{$self->{_parts}}, $entity );
309 25 return( $self );
310 }
311  
312 # bcc( @addresses )
313 # Accumulates BCC recipients (may be called multiple times).
314 sub bcc
315 2 ▶{
Subroutine bcc: called CC=4 SCAR=15.5
Pod documented
316 2 my $self = shift( @_ );
317 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
318 {
319 0 ▶ my @encoded = map { $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 2 2
320 $self->{_headers}->push_header( 'Bcc' => join( ', ', @encoded ) ) ||
321 2 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->push_header("Bcc", join(", ", @encoded)) or return $self->pass_error($self->{"_headers"}->error) 2 0 2
322 2 return( $self );
323 }
324 0 return( $self->{_headers}->header( 'Bcc' ) );
325 }
326  
327 # build( %params ) is an alternate hash-based constructor/factory
328 # Returns a Mail::Make object with all parameters applied.
329 sub build
330 11 ▶{
Subroutine build: called CC=45 SCAR=47.9
Pod documented
331 11 my $class = shift( @_ );
332 11 my $params = $class->_get_args_as_hash( @_ );
333 11 ▶ my $self = $class->new || return( $class->pass_error );
Condition50%1/2
$class->new || (return $class->pass_error)
l!l
110
MC/DC0%0/1
$class->new || (return $class->pass_error)
$class->new
Truth table50%1/2
A
A= $class->new
Aresult
11
00
334  
335 # Scalar envelope fields
336 11 foreach my $field ( qw( date from in_reply_to message_id reply_to return_path sender subject ) )
337 {
338 $self->$field( $params->{ $field } ) || return( $self->pass_error )
339 88 ▶ if( exists( $params->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->{$field} 23 65 88
Condition60%3/5
exists $params->{$field} && ($self->$field($params->{$field}) || (return $self->pass_error))
!ll&&!rl&&r
65230
$self->$field($params->{$field}) or return $self->pass_error
l!l
230
MC/DC0%0/2
exists $params->{$field} && ($self->$field($params->{$field}) || (return $self->pass_error))
exists $params->{$field} $self->$field($params->{$field})
Truth table33%1/3
A && B
A= exists $params->{$field}B= $self->$field($params->{$field})
ABresult
0X0
100
111
340 }
341 # List fields
342 11 foreach my $field ( qw( bcc cc references to ) )
343 {
344 44 ▶ if( exists( $params->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{$field}) 11 33 44
345 {
346 11 my $v = $params->{ $field };
347 11 ▶ $self->$field( ref( $v ) eq 'ARRAY' ? @$v : $v ) || return( $self->pass_error );
Branch: 2 branches
BranchTrueFalseTotal
$self->$field(ref $v eq "ARRAY" ? @$v : $v) or return $self->pass_error 11 0 11
ref $v eq 'ARRAY' ? : 1 10 11
348 }
349 }
350 # Body convenience shorthands
351 11 ▶ if( exists( $params->{plain} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"plain"}) 10 1 11
352 {
353 10 ▶ if( exists( $params->{plain_opts} ) && ref( $params->{plain_opts} ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"plain_opts"} and ref $params->{"plain_opts"} ne "HASH") 0 10 10
Condition33%1/3
exists $params->{"plain_opts"} and ref $params->{"plain_opts"} ne "HASH"
!ll&&!rl&&r
1000
MC/DC0%0/2
exists $params->{"plain_opts"} and ref $params->{"plain_opts"} ne "HASH"
exists $params->{"plain_opts"} ref $params->{"plain_opts"} ne "HASH"
Truth table33%1/3
A and B
A= exists $params->{"plain_opts"}B= ref $params->{"plain_opts"} ne "HASH"
ABresult
0X0
100
111
354 {
355 0 ▶ return( $self->error( "The parameter 'plain_opts' must be a hash reference. You provided '", $self->_str_val( $params->{plain_opts} // 'undef' ), "'." ) );
Condition0%0/2
$params->{"plain_opts"} // "undef"
l!l
00
MC/DC0%0/1
$params->{"plain_opts"} // "undef"
$params->{"plain_opts"}
Truth table0%0/2
A
A= $params->{"plain_opts"}
Aresult
11
00
356 }
357 10 ▶ my %opts = %{$params->{plain_opts} // {}};
Condition50%1/2
$params->{"plain_opts"} // {}
l!l
010
MC/DC0%0/1
$params->{"plain_opts"} // {}
$params->{"plain_opts"}
Truth table50%1/2
A
A= $params->{"plain_opts"}
Aresult
11
00
358 10 ▶ $self->plain( $params->{plain}, %opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->plain($params->{"plain"}, %opts) or return $self->pass_error 10 0 10
359 }
360 11 ▶ if( exists( $params->{html} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"html"}) 0 11 11
361 {
362 0 ▶ if( exists( $params->{html_opts} ) && ref( $params->{html_opts} ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"html_opts"} and ref $params->{"html_opts"} ne "HASH") 0 0 0
Condition0%0/3
exists $params->{"html_opts"} and ref $params->{"html_opts"} ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"html_opts"} and ref $params->{"html_opts"} ne "HASH"
exists $params->{"html_opts"} ref $params->{"html_opts"} ne "HASH"
Truth table0%0/3
A and B
A= exists $params->{"html_opts"}B= ref $params->{"html_opts"} ne "HASH"
ABresult
0X0
100
111
363 {
364 0 ▶ return( $self->error( "The parameter 'html_opts' must be a hash reference. You provided '", $self->_str_val( $params->{html_opts} // 'undef' ), "'." ) );
Condition0%0/2
$params->{"html_opts"} // "undef"
l!l
00
MC/DC0%0/1
$params->{"html_opts"} // "undef"
$params->{"html_opts"}
Truth table0%0/2
A
A= $params->{"html_opts"}
Aresult
11
00
365 }
366 0 ▶ my %opts = %{$params->{html_opts} // {}};
Condition0%0/2
$params->{"html_opts"} // {}
l!l
00
MC/DC0%0/1
$params->{"html_opts"} // {}
$params->{"html_opts"}
Truth table0%0/2
A
A= $params->{"html_opts"}
Aresult
11
00
367 0 ▶ $self->html( $params->{html}, %opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->html($params->{"html"}, %opts) or return $self->pass_error 0 0 0
368 }
369 # Attachments: scalar, arrayref of scalars, or arrayref of hashrefs
370 11 ▶ if( exists( $params->{attach} ) && defined( $params->{attach} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"attach"} and defined $params->{"attach"}) 4 7 11
Condition66%2/3
exists $params->{"attach"} and defined $params->{"attach"}
!ll&&!rl&&r
704
MC/DC50%1/2
exists $params->{"attach"} and defined $params->{"attach"}
exists $params->{"attach"} defined $params->{"attach"}
Truth table66%2/3
A and B
A= exists $params->{"attach"}B= defined $params->{"attach"}
ABresult
0X0
100
111
371 {
372 4 my $attach = $params->{attach};
373 # Accepts vanilla array reference or array objects like Module::Generic::Array
374 4 ▶ my @items = $self->_is_array( $attach ) ? @$attach : ( $attach );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($attach) ? : 3 1 4
375 4 foreach my $item ( @items )
376 {
377 7 ▶ next unless( defined( $item ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 7 7
378 # Such as:
379 # { path => '/some/where/file.pdf', filename => '04 report.pdf', type => 'application/pdf' }
380 # { data => $attachment_data, filename => '04 report.pdf', type => 'application/pdf' }
381 7 ▶ if( ref( $item ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'HASH') { } 3 4 7
382 {
383 3 ▶ $self->attach( %$item ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->attach(%$item) or return $self->pass_error 3 0 3
384 }
385 else
386 {
387 # Plain scalar or stringifiable object that delegates to attach() which
388 # already handles the positional shorthand.
389 # So, this can be an attachment data, or a file path, or a file object
390 # like Module::Generic::File (as long as it stringifies) and does not
391 # contain a "\n"
392 4 ▶ $self->attach( $item ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->attach($item) or return $self->pass_error 4 0 4
393 }
394 }
395 }
396 # url_to_inline: fetch an HTML page and embed its assets as inline parts
397 11 ▶ if( exists( $params->{url_to_inline} ) && defined( $params->{url_to_inline} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"url_to_inline"} and defined $params->{"url_to_inline"}) 1 10 11
Condition66%2/3
exists $params->{"url_to_inline"} and defined $params->{"url_to_inline"}
!ll&&!rl&&r
1001
MC/DC50%1/2
exists $params->{"url_to_inline"} and defined $params->{"url_to_inline"}
exists $params->{"url_to_inline"} defined $params->{"url_to_inline"}
Truth table66%2/3
A and B
A= exists $params->{"url_to_inline"}B= defined $params->{"url_to_inline"}
ABresult
0X0
100
111
398 {
399 1 ▶ unless( ref( $params->{url_to_inline} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $params->{"url_to_inline"} eq "HASH") 0 1 1
400 {
401 0 return( $self->error( "The parameter 'url_to_inline' must be a hash reference with at least a 'url' key." ) );
402 }
403 1 ▶ $self->url_to_inline( %{$params->{url_to_inline}} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->url_to_inline(%{$$params{"url_to_inline"};}) or return $self->pass_error 1 0 1
404 }
405 # html_to_inline: fetch external assets and embed them as inline parts
406 11 ▶ if( exists( $params->{html_to_inline} ) && defined( $params->{html_to_inline} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"html_to_inline"} and defined $params->{"html_to_inline"}) 1 10 11
Condition66%2/3
exists $params->{"html_to_inline"} and defined $params->{"html_to_inline"}
!ll&&!rl&&r
1001
MC/DC50%1/2
exists $params->{"html_to_inline"} and defined $params->{"html_to_inline"}
exists $params->{"html_to_inline"} defined $params->{"html_to_inline"}
Truth table66%2/3
A and B
A= exists $params->{"html_to_inline"}B= defined $params->{"html_to_inline"}
ABresult
0X0
100
111
407 {
408 1 ▶ unless( ref( $params->{html_to_inline} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $params->{"html_to_inline"} eq "HASH") 0 1 1
409 {
410 0 return( $self->error( "The parameter 'html_to_inline' must be a hash reference with at least 'html' and 'base_url'." ) );
411 }
412 1 ▶ $self->html_to_inline( %{$params->{html_to_inline}} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->html_to_inline(%{$$params{"html_to_inline"};}) or return $self->pass_error 1 0 1
413 }
414 # related: html + inline parts in one block
415 # Accepts a hash reference: { html => $html, inline => [ ... ], html_opts => { ... } }
416 11 ▶ if( exists( $params->{related} ) && defined( $params->{related} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"related"} and defined $params->{"related"}) 1 10 11
Condition66%2/3
exists $params->{"related"} and defined $params->{"related"}
!ll&&!rl&&r
1001
MC/DC50%1/2
exists $params->{"related"} and defined $params->{"related"}
exists $params->{"related"} defined $params->{"related"}
Truth table66%2/3
A and B
A= exists $params->{"related"}B= defined $params->{"related"}
ABresult
0X0
100
111
417 {
418 1 ▶ unless( ref( $params->{related} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $params->{"related"} eq "HASH") 0 1 1
419 {
420 0 return( $self->error( "The parameter 'related' must be a hash reference with at least a 'html' key." ) );
421 }
422 1 ▶ $self->related( %{$params->{related}} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->related(%{$$params{"related"};}) or return $self->pass_error 1 0 1
423 }
424 # Extra arbitrary headers
425 11 ▶ if( exists( $params->{headers} ) && ref( $params->{headers} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"headers"} and ref $params->{"headers"} eq "HASH") 1 10 11
Condition66%2/3
exists $params->{"headers"} and ref $params->{"headers"} eq "HASH"
!ll&&!rl&&r
1001
MC/DC50%1/2
exists $params->{"headers"} and ref $params->{"headers"} eq "HASH"
exists $params->{"headers"} ref $params->{"headers"} eq "HASH"
Truth table66%2/3
A and B
A= exists $params->{"headers"}B= ref $params->{"headers"} eq "HASH"
ABresult
0X0
100
111
426 {
427 1 ▶ while( my( $n, $v ) = each( %{$params->{headers}} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$params{"headers"};}) 1 1 2
428 {
429 1 ▶ $self->header( $n, $v ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->header($n, $v) or return $self->pass_error 1 0 1
430 }
431 }
432 11 return( $self );
433 }
434  
435 # cc( @addresses )
436 # Accumulates CC recipients.
437 sub cc
438 3 ▶{
Subroutine cc: called CC=4 SCAR=15.5
Pod documented
439 3 my $self = shift( @_ );
440 3 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 0 3
441 {
442 0 ▶ my @encoded = map { $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 3 3
443 $self->{_headers}->push_header( 'Cc' => join( ', ', @encoded ) ) ||
444 3 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->push_header("Cc", join(", ", @encoded)) or return $self->pass_error($self->{"_headers"}->error) 3 0 3
445 3 return( $self );
446 }
447 0 return( $self->{_headers}->header( 'Cc' ) );
448 }
449  
450 # date( [$date_string_or_epoch] )
451 # Delegates to Mail::Make::Headers::date(), which handles epoch integers, string validation,
452 # and RFC 5322 formatting.
453 sub date
454 0 ▶{
Subroutine date: not called CC=3 SCAR=24.8
Pod documented
455 0 my $self = shift( @_ );
456 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
457 {
458 $self->{_headers}->date( @_ ) ||
459 0 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->date(@_) or return $self->pass_error($self->{"_headers"}->error) 0 0 0
460 0 return( $self );
461 }
462 0 return( $self->{_headers}->date );
463 }
464  
465 # from( [$address] )
466 sub from
467 68 ▶{
Subroutine from: called CC=3 SCAR=11.8
Pod documented
468 68 my $self = shift( @_ );
469 68 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 68 0 68
470 {
471 68 my $addr = $self->_encode_address( shift( @_ ) );
472 $self->{_headers}->set( 'From' => $addr ) ||
473 68 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("From", $addr) or return $self->pass_error($self->{"_headers"}->error) 68 0 68
474 68 return( $self );
475 }
476 0 return( $self->{_headers}->header( 'From' ) );
477 }
478  
479 # header( $name, $value )
480 # Appends an arbitrary extra header to the envelope (push_header semantics: does not
481 # replace, allows multiple values for the same field).
482 sub header
483 2 ▶{
Subroutine header: called CC=6 SCAR=22.3
Pod documented
484 2 my $self = shift( @_ );
485 2 ▶ if( @_ == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 2 2
486 {
487 # Getter shortcut
488 0 return( $self->{_headers}->header( $_[0] ) );
489 }
490 2 my( $name, $value ) = @_;
491 2 ▶ unless( defined( $name ) && length( $name ) && defined( $value ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and length $name and defined $value) 0 2 2
Condition33%2/6
defined $name and length $name and defined $value
!ll&&!rl&&r
002
defined $name and length $name
!ll&&!rl&&r
002
MC/DC0%0/3
defined $name and length $name and defined $value
defined $name length $name defined $value
Truth table25%1/4
A and B and C
A= defined $nameB= length $nameC= defined $value
ABCresult
0XX0
10X0
1100
1111
492 {
493 0 return( $self->error( "Name and value are required." ) );
494 }
495 $self->{_headers}->push_header( $name => $value ) ||
496 2 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->push_header($name, $value) or return $self->pass_error($self->{"_headers"}->error) 2 0 2
497 2 return( $self );
498 }
499  
500 # headers()
501 # Returns the Mail::Make::Headers object that holds the envelope headers.
502 # Read-only: the object is created in init() and is not replaceable from outside, to
503 # prevent accidental aliasing.
504 0 ▶sub headers { return( $_[0]->{_headers} ); }
Subroutine headers: not called CC=1 SCAR=6.9
Pod documented
505  
506 # html( $content [, %opts] )
507 # Adds a text/html body part.
508 sub html
509 30 ▶{
Subroutine html: called CC=5 SCAR=17.3
Pod documented
510 30 my $self = shift( @_ );
511 30 my $text = shift( @_ );
512 30 my $opts = $self->_get_args_as_hash( @_ );
513 30 ▶ unless( defined( $text ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 30 30
514 {
515 0 return( $self->error( "Text content is required." ) );
516 }
517 my $part = Mail::Make::Entity->build(
518 type => 'text/html',
519 charset => ( $opts->{charset} // 'utf-8' ),
520 30 ▶ encoding => ( $opts->{encoding} // 'quoted-printable' ),
Condition50%3/6
'Mail::Make::Entity'->build('type', 'text/html', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text) || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
300
$opts->{"charset"} // "utf-8"
l!l
030
$opts->{"encoding"} // "quoted-printable"
l!l
030
MC/DC0%0/1
'Mail::Make::Entity'->build('type', 'text/html', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text) || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build('type', 'text/html', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text)
MC/DC0%0/1
$opts->{"charset"} // "utf-8"
$opts->{"charset"}
MC/DC0%0/1
$opts->{"encoding"} // "quoted-printable"
$opts->{"encoding"}
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build('type', 'text/html', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text)
Aresult
11
00
Truth table50%1/2
A
A= $opts->{"charset"}
Aresult
11
00
Truth table50%1/2
A
A= $opts->{"encoding"}
Aresult
11
00
521 data => $text,
522 ) || return( $self->pass_error( Mail::Make::Entity->error ) );
523 30 push( @{$self->{_parts}}, $part );
524 30 return( $self );
525 }
526  
527 # html_to_inline( %opts )
528 # Parses an HTML document, fetches all external assets (images, optionally CSS),
529 # replaces their URLs with cid: references, sets the HTML body part, and attaches
530 # each asset as an inline part. Returns $self for chaining.
531 #
532 # Required options:
533 # html Scalar string containing the raw HTML
534 # base_url Base URL used to resolve relative and absolute-path URLs.
535 # Required unless every src/href in the HTML is already absolute.
536 # A file:///path URI is also accepted.
537 #
538 # Optional options:
539 # embed_css Boolean. When true, <link rel="stylesheet"> assets are also fetched and
540 # embedded. Default: 0.
541 # cache_dir Path to a directory for persistent caching. Each resource is stored as
542 # MD5(url).ext with a sidecar MD5(url).ext.json holding the ETag and
543 # Last-Modified values for conditional requests.
544 # charset Charset for the HTML part. Default: utf-8.
545 # encoding CTE for the HTML part. Default: quoted-printable.
546 sub html_to_inline
547 14 ▶{
Subroutine html_to_inline: called CC=3 SCAR=11.0
Pod documented
548 14 my $self = shift( @_ );
549 14 my $opts = $self->_get_args_as_hash( @_ );
550 14 my $raw_html = $opts->{html};
551 14 ▶ unless( defined( $raw_html ) && length( $raw_html ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $raw_html and length $raw_html) 1 13 14
Condition66%2/3
defined $raw_html and length $raw_html
!ll&&!rl&&r
1013
MC/DC50%1/2
defined $raw_html and length $raw_html
defined $raw_html length $raw_html
Truth table66%2/3
A and B
A= defined $raw_htmlB= length $raw_html
ABresult
0X0
100
111
552 {
553 1 return( $self->error( "The option 'html' is required." ) );
554 }
555 13 return( $self->_hti_process_assets( $raw_html, $opts ) );
556 }
557  
558 # in_reply_to( [$mid] )
559 sub in_reply_to
560 0 ▶{
Subroutine in_reply_to: not called CC=3 SCAR=24.8
Pod documented
561 0 my $self = shift( @_ );
562 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
563 {
564 $self->{_headers}->set( 'In-Reply-To' => shift( @_ ) ) ||
565 0 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("In-Reply-To", shift @_) or return $self->pass_error($self->{"_headers"}->error) 0 0 0
566 0 return( $self );
567 }
568 0 return( $self->{_headers}->header( 'In-Reply-To' ) );
569 }
570  
571 # max_body_in_memory_size( [$bytes] )
572 # Gets or sets the byte threshold above which as_string_ref() spools to a temporary file.
573 # Set to 0 to disable the threshold (always use memory).
574 # Default: $Mail::Make::MAX_BODY_IN_MEMORY_SIZE (1 MiB).
575 0 ▶sub max_body_in_memory_size { return( shift->_set_get_number( 'max_body_in_memory_size', @_ ) ); }
Subroutine max_body_in_memory_size: not called CC=1 SCAR=6.9
Pod documented
576  
577 # message_id( [$mid | \%opts] )
578 # Delegates fully to Mail::Make::Headers::message_id(), which handles generation,
579 # validation, and removal.
580 sub message_id
581 0 ▶{
Subroutine message_id: not called CC=3 SCAR=24.8
Pod documented
582 0 my $self = shift( @_ );
583 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
584 {
585 $self->{_headers}->message_id( @_ ) ||
586 0 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->message_id(@_) or return $self->pass_error($self->{"_headers"}->error) 0 0 0
587 0 return( $self );
588 }
589 0 return( $self->{_headers}->message_id );
590 }
591  
592 # plain( $content [, %opts] )
593 # Adds a text/plain body part.
594 sub plain
595 49 ▶{
Subroutine plain: called CC=5 SCAR=17.3
Pod documented
596 49 my $self = shift( @_ );
597 49 my $text = shift( @_ );
598 49 my $opts = $self->_get_args_as_hash( @_ );
599 49 ▶ unless( defined( $text ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 49 49
600 {
601 0 return( $self->error( "The option text content is required." ) );
602 }
603 my $part = Mail::Make::Entity->build(
604 type => 'text/plain',
605 charset => ( $opts->{charset} // 'utf-8' ),
606 49 ▶ encoding => ( $opts->{encoding} // 'quoted-printable' ),
Condition50%3/6
'Mail::Make::Entity'->build('type', 'text/plain', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text) || (return $self->pass_error('Mail::Make::Entity'->error))
l!l
490
$opts->{"charset"} // "utf-8"
l!l
049
$opts->{"encoding"} // "quoted-printable"
l!l
049
MC/DC0%0/1
'Mail::Make::Entity'->build('type', 'text/plain', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text) || (return $self->pass_error('Mail::Make::Entity'->error))
'Mail::Make::Entity'->build('type', 'text/plain', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text)
MC/DC0%0/1
$opts->{"charset"} // "utf-8"
$opts->{"charset"}
MC/DC0%0/1
$opts->{"encoding"} // "quoted-printable"
$opts->{"encoding"}
Truth table50%1/2
A
A= 'Mail::Make::Entity'->build('type', 'text/plain', 'charset', $opts->{'charset'} // 'utf-8', 'encoding', $opts->{'encoding'} // 'quoted-printable', 'data', $text)
Aresult
11
00
Truth table50%1/2
A
A= $opts->{"charset"}
Aresult
11
00
Truth table50%1/2
A
A= $opts->{"encoding"}
Aresult
11
00
607 data => $text,
608 ) || return( $self->pass_error( Mail::Make::Entity->error ) );
609 49 push( @{$self->{_parts}}, $part );
610 49 return( $self );
611 }
612  
613 # print( $fh )
614 # Serialises the assembled message to a filehandle.
615 sub print
616 0 ▶{
Subroutine print: not called CC=6 SCAR=37.4
Pod documented
617 0 my $self = shift( @_ );
618 0 ▶ my $fh = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No file handle was provided to print the mail entity.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No file handle was provided to print the mail entity.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
619 return( $self->error( "No file handle was provided to print the mail entity." ) );
620 0 ▶ unless( $self->_is_glob( $fh ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_glob($fh)) 0 0 0
621 {
622 0 ▶ return( $self->error( "Value provided (", $self->_str_val( $fh // 'undef' ), ") is not a file handle." ) );
Condition0%0/2
$fh // "undef"
l!l
00
MC/DC0%0/1
$fh // "undef"
$fh
Truth table0%0/2
A
A= $fh
Aresult
11
00
623 }
624 0 ▶ my $entity = $self->as_entity || return( $self->pass_error );
Condition0%0/2
$self->as_entity || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table0%0/2
A
A= $self->as_entity
Aresult
11
00
625 0 ▶ $entity->print( $fh ) || return( $self->pass_error( $entity->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$entity->print($fh) or return $self->pass_error($entity->error) 0 0 0
626 0 return( $self );
627 }
628  
629 # related( html => $html, inline => [ { path|data, id, type, ... }, ... ] )
630 # Convenience method: sets the HTML body part and attaches all inline parts in one call.
631 # The HTML must already contain cid:ID references matching the 'id' values supplied in
632 # the inline list. Each inline item is passed to attach_inline() and must supply at
633 # least 'id' (or 'cid') and one of 'path' or 'data'. Returns $self for chaining.
634 sub related
635 2 ▶{
Subroutine related: called CC=11 SCAR=27.6
Pod documented
636 2 my $self = shift( @_ );
637 2 my $opts = $self->_get_args_as_hash( @_ );
638  
639 2 ▶ unless( defined( $opts->{html} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"html"}) 0 2 2
640 {
641 0 return( $self->error( "The option 'html' is required." ) );
642 }
643  
644 # Apply html_opts if provided
645 2 ▶ my %html_opts = %{ $opts->{html_opts} // {} };
Condition50%1/2
$opts->{"html_opts"} // {}
l!l
02
MC/DC0%0/1
$opts->{"html_opts"} // {}
$opts->{"html_opts"}
Truth table50%1/2
A
A= $opts->{"html_opts"}
Aresult
11
00
646 2 ▶ $self->html( $opts->{html}, %html_opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->html($opts->{"html"}, %html_opts) or return $self->pass_error 2 0 2
647  
648 # Process inline parts
649 2 ▶ if( exists( $opts->{inline} ) && defined( $opts->{inline} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"inline"} and defined $opts->{"inline"}) 2 0 2
Condition33%1/3
exists $opts->{"inline"} and defined $opts->{"inline"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $opts->{"inline"} and defined $opts->{"inline"}
exists $opts->{"inline"} defined $opts->{"inline"}
Truth table33%1/3
A and B
A= exists $opts->{"inline"}B= defined $opts->{"inline"}
ABresult
0X0
100
111
650 {
651 2 ▶ my @items = $self->_is_array( $opts->{inline} ) ? @{$opts->{inline}} : ( $opts->{inline} );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($opts->{'inline'}) ? : 2 0 2
652 2 foreach my $item ( @items )
653 {
654 2 ▶ next unless( defined( $item ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 2 2
655 2 ▶ unless( ref( $item ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $item eq "HASH") 0 2 2
656 {
657 0 return( $self->error( "Each 'inline' item must be a hash reference with at least 'id' (or 'cid') and 'path' or 'data'." ) );
658 }
659 2 ▶ $self->attach_inline( %$item ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->attach_inline(%$item) or return $self->pass_error 2 0 2
660 }
661 }
662 2 return( $self );
663 }
664  
665 # references( @mids )
666 # Accumulates Message-ID references.
667 sub references
668 0 ▶{
Subroutine references: not called CC=5 SCAR=34.0
Pod documented
669 0 my $self = shift( @_ );
670 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
671 {
672 0 ▶ my @mids = ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
673 # References is a single folded header: accumulate by appending.
674 0 ▶ my $existing = $self->{_headers}->header( 'References' ) // '';
Condition0%0/2
$self->{"_headers"}->header("References") // ""
l!l
00
MC/DC0%0/1
$self->{"_headers"}->header("References") // ""
$self->{"_headers"}->header("References")
Truth table0%0/2
A
A= $self->{"_headers"}->header("References")
Aresult
11
00
675 0 my $new = join( ' ', grep{ length( $_ ) } $existing, @mids );
676 $self->{_headers}->set( 'References' => $new ) ||
677 0 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("References", $new) or return $self->pass_error($self->{"_headers"}->error) 0 0 0
678 0 return( $self );
679 }
680 0 return( $self->{_headers}->header( 'References' ) );
681 }
682  
683 # reply_to( [$address] )
684 sub reply_to
685 1 ▶{
Subroutine reply_to: called CC=3 SCAR=11.8
Pod documented
686 1 my $self = shift( @_ );
687 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
688 {
689 1 my $addr = $self->_encode_address( shift( @_ ) );
690 $self->{_headers}->set( 'Reply-To' => $addr ) ||
691 1 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("Reply-To", $addr) or return $self->pass_error($self->{"_headers"}->error) 1 0 1
692 1 return( $self );
693 }
694 0 return( $self->{_headers}->header( 'Reply-To' ) );
695 }
696  
697 # return_path( [$address] )
698 sub return_path
699 0 ▶{
Subroutine return_path: not called CC=3 SCAR=24.8
Pod documented
700 0 my $self = shift( @_ );
701 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
702 {
703 0 my $addr = $self->_encode_address( shift( @_ ) );
704 $self->{_headers}->set( 'Return-Path' => $addr ) ||
705 0 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("Return-Path", $addr) or return $self->pass_error($self->{"_headers"}->error) 0 0 0
706 0 return( $self );
707 }
708 0 return( $self->{_headers}->header( 'Return-Path' ) );
709 }
710  
711 # sender( [$address] )
712 sub sender
713 1 ▶{
Subroutine sender: called CC=3 SCAR=11.8
Pod documented
714 1 my $self = shift( @_ );
715 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
716 {
717 1 my $addr = $self->_encode_address( shift( @_ ) );
718 $self->{_headers}->set( 'Sender' => $addr ) ||
719 1 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("Sender", $addr) or return $self->pass_error($self->{"_headers"}->error) 1 0 1
720 1 return( $self );
721 }
722 0 return( $self->{_headers}->header( 'Sender' ) );
723 }
724  
725 # smtpsend( %opts )
726 # Assembles the message and submits it via SMTP using Net::SMTP.
727 #
728 # Recognised options:
729 # Host => $hostname_or_Net_SMTP_object
730 # Defaults to trying $ENV{SMTPHOSTS} (colon-separated),
731 # 'mailhost', then 'localhost'.
732 # MailFrom => $envelope_sender (MAIL FROM)
733 # Defaults to the From: header address-spec.
734 # To => \@recipients Override the To header for RCPT TO.
735 # Cc => \@recipients Additional CC addresses for RCPT TO.
736 # Bcc => \@recipients Additional BCC addresses for RCPT TO.
737 # Note: Bcc is stripped from the outgoing headers per RFC 2822 §3.6.3.
738 # Hello => $fqdn EHLO/HELO hostname.
739 # Port => $port SMTP port (default 25).
740 # Debug => $bool Enable Net::SMTP debug output.
741 #
742 # Returns the list of recipients successfully handed to the MTA on success, or undef and
743 # sets error() on failure.
744 sub smtpsend
745 12 ▶{
Subroutine smtpsend: called CC=63 SCAR=57.1
Pod documented
746 12 my $self = shift( @_ );
747 12 my $opts = $self->_get_args_as_hash( @_ );
748  
749 12 ▶ $self->_load_class( 'Net::SMTP' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Net::SMTP") or return $self->pass_error 12 0 12
750  
751 # Build the entity first so we can inspect its headers
752 12 ▶ my $entity = $self->as_entity || return( $self->pass_error );
Condition50%1/2
$self->as_entity || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table50%1/2
A
A= $self->as_entity
Aresult
11
00
753  
754 # Determine envelope sender (MAIL FROM)
755 12 my $mail_from = $opts->{MailFrom};
756 12 ▶ unless( defined( $mail_from ) && length( $mail_from ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mail_from and length $mail_from) 11 1 12
Condition66%2/3
defined $mail_from and length $mail_from
!ll&&!rl&&r
1101
MC/DC50%1/2
defined $mail_from and length $mail_from
defined $mail_from length $mail_from
Truth table66%2/3
A and B
A= defined $mail_fromB= length $mail_from
ABresult
0X0
100
111
757 {
758 11 ▶ my $from_hdr = $self->{_headers}->header( 'From' ) // '';
Condition50%1/2
$self->{"_headers"}->header("From") // ""
l!l
110
MC/DC0%0/1
$self->{"_headers"}->header("From") // ""
$self->{"_headers"}->header("From")
Truth table50%1/2
A
A= $self->{"_headers"}->header("From")
Aresult
11
00
759 11 ▶ if( $from_hdr =~ /<([^>]+)>/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($from_hdr =~ /<([^>]+)>/) { } 1 10 11
760 {
761 1 $mail_from = $1;
762 }
763 else
764 {
765 10 ( $mail_from = $from_hdr ) =~ s/\s+//g;
766 }
767 }
768  
769 12 ▶ unless( defined( $mail_from ) && length( $mail_from ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mail_from and length $mail_from) 0 12 12
Condition33%1/3
defined $mail_from and length $mail_from
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $mail_from and length $mail_from
defined $mail_from length $mail_from
Truth table33%1/3
A and B
A= defined $mail_fromB= length $mail_from
ABresult
0X0
100
111
770 {
771 0 return( $self->error( "Cannot determine envelope sender (MAIL FROM). Set MailFrom or From header." ) );
772 }
773  
774 # Validate auth credentials before touching the network
775 # Password may be a plain string or a CODE ref (resolved later).
776 12 my $username = $opts->{Username};
777 12 my $password = $opts->{Password};
778  
779 12 ▶ if( defined( $username ) && length( $username ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $username and length $username) 2 10 12
Condition66%2/3
defined $username and length $username
!ll&&!rl&&r
1002
MC/DC50%1/2
defined $username and length $username
defined $username length $username
Truth table66%2/3
A and B
A= defined $usernameB= length $username
ABresult
0X0
100
111
780 {
781 2 ▶ unless( defined( $password ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $password) 1 1 2
782 {
783 1 return( $self->error( "Username supplied but Password is missing." ) );
784 }
785  
786 # Authen::SASL and MIME::Base64 are required for SMTP AUTH.
787 # Check early so the error is clear rather than a cryptic auth failure.
788 1 foreach my $mod ( qw( MIME::Base64 Authen::SASL ) )
789 {
790 2 ▶ $self->_load_class( $mod ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($mod) or return $self->error("SMTP authentication requires $mod, which is not installed. Install it with: cpan $mod") 2 0 2
791 return( $self->error( "SMTP authentication requires $mod, which is not installed. Install it with: cpan $mod" ) );
792 }
793 }
794  
795 # Determine RCPT TO addresses before connecting, so we can bail early.
796 # Honour explicit override lists first; fall back to message headers.
797 11 my @rcpt_raw;
798 11 foreach my $field ( qw( To Cc Bcc ) )
799 {
800 33 my $v = $opts->{ $field };
801 33 ▶ if( defined( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 1 32 33
802 {
803 1 ▶ push( @rcpt_raw, ref( $v ) eq 'ARRAY' ? @$v : $v );
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 1 1
804 }
805 else
806 {
807 32 ▶ my $hv = $self->{_headers}->header( $field ) // '';
Condition100%2/2
$self->{"_headers"}->header($field) // ""
l!l
1319
MC/DC100%1/1
$self->{"_headers"}->header($field) // ""
$self->{"_headers"}->header($field)
Truth table100%2/2
A
A= $self->{"_headers"}->header($field)
Aresult
11
00
808 32 ▶ push( @rcpt_raw, $hv ) if( length( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $hv 13 19 32
809 }
810 }
811  
812 # Parse each raw value into bare addr-specs
813 11 my @addr;
814 11 foreach my $raw ( @rcpt_raw )
815 {
816 14 my @found_angle;
817 14 ▶ while( $raw =~ /<([^>]+)>/g )
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /<([^>]+)>/g) 0 14 14
818 {
819 0 push( @found_angle, $1 );
820 }
821 14 ▶ if( @found_angle )
Branch: 1 branch
BranchTrueFalseTotal
if (@found_angle) { } 0 14 14
822 {
823 0 push( @addr, @found_angle );
824 }
825 else
826 {
827 # Bare comma-separated list (no angle brackets)
828 14 push( @addr, grep{ /\@/ } map{ s/^\s+|\s+$//gr } split( /,/, $raw ) );
829 }
830 }
831 # Deduplicate while preserving order
832 11 my %seen;
833 11 @addr = grep{ !$seen{ $_ }++ } @addr;
834  
835 11 ▶ unless( @addr )
Branch: 1 branch
BranchTrueFalseTotal
unless (@addr) 1 10 11
836 {
837 1 return( $self->error( "No recipients found." ) );
838 }
839  
840 # Build Net::SMTP connection options
841 # SSL => 1 : direct SSL/TLS (e.g. port 465, aka SMTPS)
842 10 my @smtp_opts;
843 10 ▶ push( @smtp_opts, Hello => $opts->{Hello} ) if( defined( $opts->{Hello} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"Hello"} 9 1 10
844 10 ▶ push( @smtp_opts, Port => $opts->{Port} ) if( defined( $opts->{Port} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"Port"} 9 1 10
845 10 ▶ push( @smtp_opts, Debug => $opts->{Debug} ) if( defined( $opts->{Debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"Debug"} 0 10 10
846 10 ▶ push( @smtp_opts, Timeout => $opts->{Timeout} ) if( defined( $opts->{Timeout} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"Timeout"} 1 9 10
847 10 ▶ if( $opts->{SSL} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"SSL"}) 0 10 10
848 {
849 0 push( @smtp_opts, SSL => 1 );
850 0 ▶ if( ref( $opts->{SSL_opts} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{"SSL_opts"} eq "HASH") 0 0 0
851 {
852 0 push( @smtp_opts, %{$opts->{SSL_opts}} );
853 }
854 }
855  
856 # NOTE: SMTP connect
857 10 my $smtp;
858 10 my $quit = 1;
859 10 my $host = $opts->{Host};
860  
861 10 ▶ if( !defined( $host ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $host) { } 0 10 10
elsif ($self->_is_a($host, 'Net::SMTP')) { } 1 9 10
862 {
863 0 my @hosts = qw( mailhost localhost );
864 0 ▶ if( defined( $ENV{SMTPHOSTS} ) && length( $ENV{SMTPHOSTS} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"SMTPHOSTS"} and length $ENV{"SMTPHOSTS"}) 0 0 0
Condition0%0/3
defined $ENV{"SMTPHOSTS"} and length $ENV{"SMTPHOSTS"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"SMTPHOSTS"} and length $ENV{"SMTPHOSTS"}
defined $ENV{"SMTPHOSTS"} length $ENV{"SMTPHOSTS"}
Truth table0%0/3
A and B
A= defined $ENV{"SMTPHOSTS"}B= length $ENV{"SMTPHOSTS"}
ABresult
0X0
100
111
865 {
866 0 unshift( @hosts, split( /:/, $ENV{SMTPHOSTS} ) );
867 }
868  
869 0 foreach my $h ( @hosts )
870 {
871 0 local $@;
872 0 $smtp = eval{ Net::SMTP->new( $h, @smtp_opts ) };
873 0 ▶ last if( defined( $smtp ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $smtp 0 0 0
874 }
875 }
876 elsif( $self->_is_a( $host => 'Net::SMTP' ) )
877 {
878 # Caller passes an already-connected object; we must not quit it.
879 1 $smtp = $host;
880 1 $quit = 0;
881 }
882 else
883 {
884 9 local $@;
885 9 $smtp = eval{ Net::SMTP->new( $host, @smtp_opts ) };
886 }
887  
888 10 ▶ unless( defined( $smtp ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $smtp) 1 9 10
889 {
890 1 return( $self->error( "Could not connect to any SMTP server." ) );
891 }
892  
893 # STARTTLS upgrade (ignored when caller supplied a pre-built object or SSL)
894 9 ▶ if( $opts->{StartTLS} && $quit )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"StartTLS"} and $quit) 0 9 9
Condition33%1/3
$opts->{"StartTLS"} and $quit
!ll&&!rl&&r
900
MC/DC0%0/2
$opts->{"StartTLS"} and $quit
$opts->{"StartTLS"} $quit
Truth table33%1/3
A and B
A= $opts->{"StartTLS"}B= $quit
ABresult
0X0
100
111
895 {
896 0 my %tls_opts;
897 0 ▶ if( ref( $opts->{SSL_opts} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{"SSL_opts"} eq "HASH") 0 0 0
898 {
899 0 %tls_opts = %{$opts->{SSL_opts}};
900 }
901 0 ▶ unless( $smtp->starttls( %tls_opts ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->starttls(%tls_opts)) 0 0 0
902 {
903 0 my $smtp_msg = join( ' ', $smtp->message );
904 0 $smtp->quit;
905 0 ▶ return( $self->error( "STARTTLS negotiation failed" . ( length( $smtp_msg ) ? ": $smtp_msg" : '.' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
length $smtp_msg ? : 0 0 0
906 }
907 }
908  
909 # -------------------------------------------------------------------------
910 # SMTP Authentication (SASL via Authen::SASL + Net::SMTP::auth)
911 # Password is resolved here so the CODE ref is called as late as possible.
912 #
913 # We build an explicit Authen::SASL object rather than letting Net::SMTP
914 # pick the mechanism freely. Left to itself, Authen::SASL prefers
915 # DIGEST-MD5 and CRAM-MD5, which are both deprecated (RFC 6331, RFC 8314) and
916 # routinely disabled on modern Postfix/Dovecot servers. Over an already
917 # encrypted STARTTLS or SSL channel, PLAIN and LOGIN are both safe and
918 # universally supported.
919 #
920 # Mechanism selection:
921 # 1. Caller may supply an explicit list via AuthMechanisms option.
922 # 2. Otherwise we use our preferred order: PLAIN LOGIN.
923 # 3. We intersect with what the server actually advertises (supports AUTH).
924 # -------------------------------------------------------------------------
925 9 ▶ if( defined( $username ) && length( $username ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $username and length $username) 1 8 9
Condition66%2/3
defined $username and length $username
!ll&&!rl&&r
801
MC/DC50%1/2
defined $username and length $username
defined $username length $username
Truth table66%2/3
A and B
A= defined $usernameB= length $username
ABresult
0X0
100
111
926 {
927 1 ▶ if( ref( $password ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $password eq "CODE") 1 0 1
928 {
929 1 local $@;
930 1 $password = eval{ $password->() };
931 1 ▶ if( $@ || !defined( $password ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $password) 0 1 1
Condition33%1/3
$@ or not defined $password
l!l&&r!l&&!r
001
MC/DC0%0/2
$@ or not defined $password
$@ not defined $password
Truth table33%1/3
A or not(B)
A= $@B= not defined $password
ABresult
1X1
011
000
932 {
933 0 ▶ $smtp->quit if( $quit );
Branch: 1 branch
BranchTrueFalseTotal
if $quit 0 0 0
934 0 ▶ return( $self->error( "Password callback failed: " . ( $@ // 'returned undef' ) ) );
Condition0%0/2
$@ // "returned undef"
l!l
00
MC/DC0%0/1
$@ // "returned undef"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
935 }
936 }
937  
938 # Determine which mechanisms the server advertises
939 1 ▶ my $server_mechs = $smtp->supports( 'AUTH' ) // '';
Condition50%1/2
$smtp->supports("AUTH") // ""
l!l
01
MC/DC0%0/1
$smtp->supports("AUTH") // ""
$smtp->supports("AUTH")
Truth table50%1/2
A
A= $smtp->supports("AUTH")
Aresult
11
00
940  
941 # Build the preferred mechanism list
942 1 ▶ my $preferred = $opts->{AuthMechanisms} // 'PLAIN LOGIN';
Condition50%1/2
$opts->{"AuthMechanisms"} // "PLAIN LOGIN"
l!l
01
MC/DC0%0/1
$opts->{"AuthMechanisms"} // "PLAIN LOGIN"
$opts->{"AuthMechanisms"}
Truth table50%1/2
A
A= $opts->{"AuthMechanisms"}
Aresult
11
00
943  
944 # Intersect: keep only those the server supports, preserving our order
945 0 my %server_set = map{ uc( $_ ) => 1 } split( /\s+/, $server_mechs );
946 1 my @agreed = grep{ $server_set{ uc( $_ ) } } split( /\s+/, $preferred );
947  
948 1 ▶ if( !@agreed )
Branch: 1 branch
BranchTrueFalseTotal
unless (@agreed) 1 0 1
949 {
950 # No intersection -- fall back to whatever the server offers,
951 # excluding the deprecated challenge-response mechanisms.
952 0 @agreed = grep{ !/^(?:DIGEST-MD5|CRAM-MD5|GSSAPI)$/i }
953 split( /\s+/, $server_mechs );
954 }
955  
956 1 my $sasl = Authen::SASL->new(
957 mechanism => join( ' ', @agreed ),
958 callback => {
959 user => $username,
960 pass => $password,
961 authname => $username,
962 },
963 );
964  
965 1 ▶ unless( $smtp->auth( $sasl ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->auth($sasl)) 1 0 1
966 {
967 # Capture the server's error message for a more useful diagnostic
968 1 my $smtp_msg = join( ' ', $smtp->message );
969 1 ▶ $smtp->quit if( $quit );
Branch: 1 branch
BranchTrueFalseTotal
if $quit 1 0 1
970 1 ▶ return( $self->error( "SMTP authentication failed for user '$username'" . ( length( $smtp_msg ) ? ": $smtp_msg" : '.' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
length $smtp_msg ? : 1 0 1
971 }
972 }
973  
974 # Serialise message, stripping Bcc from transmitted copy
975 my $send_entity = $self->as_entity || do
976 8 ▶ {
Condition33%1/3
$self->as_entity || do { $smtp->quit if $quit; return $self->pass_error }
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->as_entity || do { $smtp->quit if $quit; return $self->pass_error }
$self->as_entity do { $smtp->quit if $quit; return $self->pass_error }
Truth table33%1/3
A || B
A= $self->as_entityB= do { $smtp->quit if $quit; return $self->pass_error }
ABresult
1X1
011
000
977 0 ▶ $smtp->quit if( $quit );
Branch: 1 branch
BranchTrueFalseTotal
if $quit 0 0 0
978 0 return( $self->pass_error );
979 };
980 8 $send_entity->headers->remove( 'Bcc' );
981 my $msg = $send_entity->as_string || do
982 8 ▶ {
Condition33%1/3
$send_entity->as_string || do { $smtp->quit if $quit; return $self->pass_error($send_entity->error) }
l!l&&r!l&&!r
800
MC/DC0%0/2
$send_entity->as_string || do { $smtp->quit if $quit; return $self->pass_error($send_entity->error) }
$send_entity->as_string do { $smtp->quit if $quit; return $self->pass_error($send_entity->error) }
Truth table33%1/3
A || B
A= $send_entity->as_stringB= do { $smtp->quit if $quit; return $self->pass_error($send_entity->error) }
ABresult
1X1
011
000
983 0 ▶ $smtp->quit if( $quit );
Branch: 1 branch
BranchTrueFalseTotal
if $quit 0 0 0
984 0 return( $self->pass_error( $send_entity->error ) );
985 };
986  
987 # Submit
988 8 ▶ my $ok = $smtp->mail( $mail_from )
Condition33%2/6
$smtp->mail($mail_from) && $smtp->to(@addr) && $smtp->data($msg)
!ll&&!rl&&r
008
$smtp->mail($mail_from) and $smtp->to(@addr)
!ll&&!rl&&r
008
MC/DC0%0/3
$smtp->mail($mail_from) && $smtp->to(@addr) && $smtp->data($msg)
$smtp->mail($mail_from) $smtp->to(@addr) $smtp->data($msg)
Truth table25%1/4
A and B && C
A= $smtp->mail($mail_from)B= $smtp->to(@addr)C= $smtp->data($msg)
ABCresult
0XX0
10X0
1100
1111
989 && $smtp->to( @addr )
990 && $smtp->data( $msg );
991  
992 8 ▶ $smtp->quit if( $quit );
Branch: 1 branch
BranchTrueFalseTotal
if $quit 7 1 8
993  
994 8 ▶ unless( $ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 8 8
995 {
996 0 return( $self->error( "SMTP transaction failed." ) );
997 }
998  
999 8 ▶ return( wantarray() ? @addr : \@addr );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
1000 }
1001  
1002 # subject( [$string] )
1003 # RFC 2047-encodes non-ASCII subjects before storing.
1004 sub subject
1005 57 ▶{
Subroutine subject: called CC=3 SCAR=11.8
Pod documented
1006 57 my $self = shift( @_ );
1007 57 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 0 57
1008 {
1009 57 my $enc = $self->_encode_header( shift( @_ ) );
1010 $self->{_headers}->set( 'Subject' => $enc ) ||
1011 57 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("Subject", $enc) or return $self->pass_error($self->{"_headers"}->error) 57 0 57
1012 57 return( $self );
1013 }
1014 0 return( $self->{_headers}->header( 'Subject' ) );
1015 }
1016  
1017 # to( @addresses )
1018 # Accumulates To recipients.
1019 sub to
1020 69 ▶{
Subroutine to: called CC=5 SCAR=17.4
Pod documented
1021 69 my $self = shift( @_ );
1022 69 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 69 0 69
1023 {
1024 0 ▶ my @encoded = map{ $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 69 69
1025 # Merge into a single To: header (RFC 5322 §3.6.3 allows only one To field)
1026 69 my $existing = $self->{_headers}->header( 'To' );
1027 69 ▶ my $new_val = join( ', ', grep{ defined( $_ ) && length( $_ ) } $existing, @encoded );
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
67072
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1028 $self->{_headers}->set( 'To' => $new_val ) ||
1029 69 ▶ return( $self->pass_error( $self->{_headers}->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_headers"}->set("To", $new_val) or return $self->pass_error($self->{"_headers"}->error) 69 0 69
1030 69 return( $self );
1031 }
1032 0 return( $self->{_headers}->header( 'To' ) );
1033 }
1034  
1035 # url_to_inline( %opts )
1036 # Fetches an HTML page from a URL, then processes it exactly like html_to_inline():
1037 # external assets are fetched, their URLs rewritten to cid: references, and each
1038 # asset is attached as an inline part. The base_url defaults to the directory
1039 # portion of the page URL, but can be overridden via the base_url option.
1040 #
1041 # Required options:
1042 # url The URL of the HTML page to fetch and process.
1043 #
1044 # Optional options: same as html_to_inline() except 'html' (embed_css, cache_dir,
1045 # charset, encoding, base_url).
1046 sub url_to_inline
1047 6 ▶{
Subroutine url_to_inline: called CC=14 SCAR=29.5
Pod documented
1048 6 my $self = shift( @_ );
1049 6 my $opts = $self->_get_args_as_hash( @_ );
1050  
1051 6 my $url = $opts->{url};
1052 6 ▶ unless( defined( $url ) && length( $url ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url and length $url) 1 5 6
Condition66%2/3
defined $url and length $url
!ll&&!rl&&r
105
MC/DC50%1/2
defined $url and length $url
defined $url length $url
Truth table66%2/3
A and B
A= defined $urlB= length $url
ABresult
0X0
100
111
1053 {
1054 1 return( $self->error( "The option 'url' is required." ) );
1055 }
1056  
1057 # Initialise the per-instance URL cache
1058 5 ▶ $self->{_hti_cache} //= {};
Condition50%1/2
$self->{"_hti_cache"} //= {}
l!l
05
MC/DC0%0/1
$self->{"_hti_cache"} //= {}
$self->{"_hti_cache"}
Truth table50%1/2
A
A= $self->{"_hti_cache"}
Aresult
11
00
1059  
1060 # Fetch the HTML page itself
1061 5 my $result = $self->_hti_fetch( $url, cache_dir => $opts->{cache_dir} );
1062 5 ▶ unless( defined( $result ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 5 5
1063 {
1064 0 ▶ return( $self->error( "Could not fetch '$url': " . ( $self->error // 'unknown error' ) ) );
Condition0%0/2
$self->error // "unknown error"
l!l
00
MC/DC0%0/1
$self->error // "unknown error"
$self->error
Truth table0%0/2
A
A= $self->error
Aresult
11
00
1065 }
1066  
1067 0 ▶ my $raw_html = ref( $result->{data} ) ? "${\$result->{data}}" : $result->{data};
Branch: 1 branch
BranchTrueFalseTotal
ref $result->{'data'} ? : 0 5 5
1068 5 ▶ unless( defined( $raw_html ) && length( $raw_html ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $raw_html and length $raw_html) 0 5 5
Condition33%1/3
defined $raw_html and length $raw_html
!ll&&!rl&&r
005
MC/DC0%0/2
defined $raw_html and length $raw_html
defined $raw_html length $raw_html
Truth table33%1/3
A and B
A= defined $raw_htmlB= length $raw_html
ABresult
0X0
100
111
1069 {
1070 0 return( $self->error( "Fetched page at '$url' is empty." ) );
1071 }
1072  
1073 # Derive base_url from the page URL if not provided explicitly.
1074 # Strip the filename part so relative asset URLs resolve correctly:
1075 # https://www.example.com/newsletter/confirm.html
1076 # -> https://www.example.com/newsletter/
1077 5 ▶ unless( defined( $opts->{base_url} ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"base_url"} and length $opts->{"base_url"}) 4 1 5
Condition66%2/3
defined $opts->{"base_url"} and length $opts->{"base_url"}
!ll&&!rl&&r
401
MC/DC50%1/2
defined $opts->{"base_url"} and length $opts->{"base_url"}
defined $opts->{"base_url"} length $opts->{"base_url"}
Truth table66%2/3
A and B
A= defined $opts->{"base_url"}B= length $opts->{"base_url"}
ABresult
0X0
100
111
1078 length( $opts->{base_url} ) )
1079 {
1080 4 ▶ $self->_load_class( 'URI' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("URI") or return $self->pass_error 4 0 4
1081 4 local $@;
1082 my $base = eval
1083 4 {
1084 4 my $u = URI->new( $url );
1085 4 my $path = $u->path;
1086 4 $path =~ s{[^/]+$}{};
1087 4 $u->path( $path );
1088 4 $u->as_string;
1089 };
1090 4 ▶ return( $self->error( "An error occurred while trying to instanciate a URI object with the base URL provided '$url': $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
1091 4 ▶ $opts->{base_url} = defined( $base ) ? $base : $url;
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 4 0 4
1092 }
1093  
1094 5 return( $self->_hti_process_assets( $raw_html, $opts ) );
1095 }
1096  
1097 # use_temp_file( [$bool] )
1098 # When true, as_string_ref() always spools to a temporary file regardless of message size.
1099 # This is used when we know the message will be large, or when we want to bound peak
1100 # memory use unconditionally.
1101 # Default: false.
1102 0 ▶sub use_temp_file { return( shift->_set_get_boolean( 'use_temp_file', @_ ) ); }
Subroutine use_temp_file: not called CC=1 SCAR=6.9
Pod documented
1103  
1104 # gpg_encrypt( %opts )
1105 # Encrypts this message for one or more recipients and returns a new Mail::Make object
1106 # whose body is a RFC 3156 multipart/encrypted structure.
1107 #
1108 # Required options:
1109 # Recipients => [ 'alice@example.com', ... ]
1110 #
1111 # Optional options:
1112 # GpgBin => '/usr/bin/gpg2'
1113 # KeyServer => 'keys.openpgp.org'
1114 # AutoFetch => 1
1115 # Digest => 'SHA256'
1116 sub gpg_encrypt
1117 0 ▶{
Subroutine gpg_encrypt: not called CC=9 SCAR=45.0
Pod documented
1118 0 my $self = shift( @_ );
1119 0 my $opts = $self->_get_args_as_hash( @_ );
1120 0 require Mail::Make::GPG;
1121 my $gpg = Mail::Make::GPG->new(
1122 ( defined( $opts->{GpgBin} ) ? ( gpg_bin => $opts->{GpgBin} ) : () ),
1123 ( defined( $opts->{Digest} ) ? ( digest => $opts->{Digest} ) : () ),
1124 ( defined( $opts->{KeyServer} ) ? ( keyserver => $opts->{KeyServer} ) : () ),
1125 0 ▶ ( defined( $opts->{AutoFetch} ) ? ( auto_fetch => $opts->{AutoFetch} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $opts->{'GpgBin'} ? : 0 0 0
defined $opts->{'Digest'} ? : 0 0 0
defined $opts->{'KeyServer'} ? : 0 0 0
defined $opts->{'AutoFetch'} ? : 0 0 0
Condition0%0/2
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ())
Aresult
11
00
1126 ) || return( $self->pass_error( Mail::Make::GPG->error ) );
1127  
1128 my $recipients = $opts->{Recipients} ||
1129 0 ▶ return( $self->error( 'Recipients option is required.' ) );
Condition0%0/2
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
l!l
00
MC/DC0%0/1
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
$opts->{'Recipients'}
Truth table0%0/2
A
A= $opts->{'Recipients'}
Aresult
11
00
1130 0 ▶ $recipients = [ $recipients ] unless( ref( $recipients ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $recipients eq "ARRAY" 0 0 0
1131  
1132 0 ▶ return( $gpg->encrypt(
Condition0%0/3
$gpg->encrypt('entity', $self, 'recipients', $recipients) || $self->pass_error($gpg->error)
l!l&&r!l&&!r
000
MC/DC0%0/2
$gpg->encrypt('entity', $self, 'recipients', $recipients) || $self->pass_error($gpg->error)
$gpg->encrypt('entity', $self, 'recipients', $recipients) $self->pass_error($gpg->error)
Truth table0%0/3
A || B
A= $gpg->encrypt('entity', $self, 'recipients', $recipients)B= $self->pass_error($gpg->error)
ABresult
1X1
011
000
1133 entity => $self,
1134 recipients => $recipients,
1135 ) || $self->pass_error( $gpg->error ) );
1136 }
1137  
1138 # gpg_sign( %opts )
1139 # Signs this message and returns a new Mail::Make object whose body is a
1140 # RFC 3156 multipart/signed structure with a detached ASCII-armoured signature.
1141 #
1142 # Required options:
1143 # KeyId => '35ADBC3AF8355E845139D8965F3C0261CDB2E752'
1144 #
1145 # Optional options:
1146 # Passphrase => 'secret' # or CODE ref; omit to use gpg-agent
1147 # Digest => 'SHA256'
1148 # GpgBin => '/usr/bin/gpg2'
1149 sub gpg_sign
1150 0 ▶{
Subroutine gpg_sign: not called CC=8 SCAR=42.8
Pod documented
1151 0 my $self = shift( @_ );
1152 0 my $opts = $self->_get_args_as_hash( @_ );
1153 0 require Mail::Make::GPG;
1154 my $gpg = Mail::Make::GPG->new(
1155 ( defined( $opts->{GpgBin} ) ? ( gpg_bin => $opts->{GpgBin} ) : () ),
1156 0 ▶ ( defined( $opts->{Digest} ) ? ( digest => $opts->{Digest} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $opts->{'GpgBin'} ? : 0 0 0
defined $opts->{'Digest'} ? : 0 0 0
Condition0%0/2
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ())
Aresult
11
00
1157 ) || return( $self->pass_error( Mail::Make::GPG->error ) );
1158  
1159 return( $gpg->sign(
1160 entity => $self,
1161 key_id => ( $opts->{KeyId} // '' ),
1162 passphrase => ( $opts->{Passphrase} // undef ),
1163 0 ▶ ( defined( $opts->{Digest} ) ? ( digest => $opts->{Digest} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'Digest'} ? : 0 0 0
Condition0%0/7
$gpg->sign('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || $self->pass_error($gpg->error)
l!l&&r!l&&!r
000
$opts->{"KeyId"} // ""
l!l
00
$opts->{"Passphrase"} // undef
l!l
00
MC/DC0%0/2
$gpg->sign('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || $self->pass_error($gpg->error)
$gpg->sign('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) $self->pass_error($gpg->error)
MC/DC0%0/1
$opts->{"KeyId"} // ""
$opts->{"KeyId"}
MC/DC0%0/1
$opts->{"Passphrase"} // undef
$opts->{"Passphrase"}
Truth table0%0/3
A || B
A= $gpg->sign('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ())B= $self->pass_error($gpg->error)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts->{"KeyId"}
Aresult
11
00
Truth table0%0/2
A
A= $opts->{"Passphrase"}
Aresult
11
00
1164 ) || $self->pass_error( $gpg->error ) );
1165 }
1166  
1167 # gpg_sign_encrypt( %opts )
1168 # Signs then encrypts this message. Returns a new Mail::Make object whose body is a
1169 # RFC 3156 multipart/encrypted structure containing a signed and encrypted payload.
1170 #
1171 # Required options:
1172 # KeyId => '35ADBC3AF8355E845139D8965F3C0261CDB2E752'
1173 # Recipients => [ 'alice@example.com', ... ]
1174 #
1175 # Optional options:
1176 # Passphrase => 'secret' # or CODE ref
1177 # Digest => 'SHA256'
1178 # GpgBin => '/usr/bin/gpg2'
1179 # KeyServer => 'keys.openpgp.org'
1180 # AutoFetch => 1
1181 sub gpg_sign_encrypt
1182 0 ▶{
Subroutine gpg_sign_encrypt: not called CC=12 SCAR=50.5
Pod documented
1183 0 my $self = shift( @_ );
1184 0 my $opts = $self->_get_args_as_hash( @_ );
1185 0 require Mail::Make::GPG;
1186 my $gpg = Mail::Make::GPG->new(
1187 ( defined( $opts->{GpgBin} ) ? ( gpg_bin => $opts->{GpgBin} ) : () ),
1188 ( defined( $opts->{Digest} ) ? ( digest => $opts->{Digest} ) : () ),
1189 ( defined( $opts->{KeyServer} ) ? ( keyserver => $opts->{KeyServer} ) : () ),
1190 0 ▶ ( defined( $opts->{AutoFetch} ) ? ( auto_fetch => $opts->{AutoFetch} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $opts->{'GpgBin'} ? : 0 0 0
defined $opts->{'Digest'} ? : 0 0 0
defined $opts->{'KeyServer'} ? : 0 0 0
defined $opts->{'AutoFetch'} ? : 0 0 0
Condition0%0/2
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ()) || (return $self->pass_error('Mail::Make::GPG'->error))
'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::GPG'->new(defined $opts->{'GpgBin'} ? ('gpg_bin', $opts->{'GpgBin'}) : (), defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : (), defined $opts->{'KeyServer'} ? ('keyserver', $opts->{'KeyServer'}) : (), defined $opts->{'AutoFetch'} ? ('auto_fetch', $opts->{'AutoFetch'}) : ())
Aresult
11
00
1191 ) || return( $self->pass_error( Mail::Make::GPG->error ) );
1192  
1193 my $recipients = $opts->{Recipients} ||
1194 0 ▶ return( $self->error( 'Recipients option is required.' ) );
Condition0%0/2
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
l!l
00
MC/DC0%0/1
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
$opts->{'Recipients'}
Truth table0%0/2
A
A= $opts->{'Recipients'}
Aresult
11
00
1195 0 ▶ $recipients = [ $recipients ] unless( ref( $recipients ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $recipients eq "ARRAY" 0 0 0
1196  
1197 return( $gpg->sign_encrypt(
1198 entity => $self,
1199 key_id => ( $opts->{KeyId} // '' ),
1200 passphrase => ( $opts->{Passphrase} // undef ),
1201 recipients => $recipients,
1202 0 ▶ ( defined( $opts->{Digest} ) ? ( digest => $opts->{Digest} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'Digest'} ? : 0 0 0
Condition0%0/7
$gpg->sign_encrypt('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, 'recipients', $recipients, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || $self->pass_error($gpg->error)
l!l&&r!l&&!r
000
$opts->{"KeyId"} // ""
l!l
00
$opts->{"Passphrase"} // undef
l!l
00
MC/DC0%0/2
$gpg->sign_encrypt('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, 'recipients', $recipients, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) || $self->pass_error($gpg->error)
$gpg->sign_encrypt('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, 'recipients', $recipients, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ()) $self->pass_error($gpg->error)
MC/DC0%0/1
$opts->{"KeyId"} // ""
$opts->{"KeyId"}
MC/DC0%0/1
$opts->{"Passphrase"} // undef
$opts->{"Passphrase"}
Truth table0%0/3
A || B
A= $gpg->sign_encrypt('entity', $self, 'key_id', $opts->{'KeyId'} // '', 'passphrase', $opts->{'Passphrase'} // undef, 'recipients', $recipients, defined $opts->{'Digest'} ? ('digest', $opts->{'Digest'}) : ())B= $self->pass_error($gpg->error)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts->{"KeyId"}
Aresult
11
00
Truth table0%0/2
A
A= $opts->{"Passphrase"}
Aresult
11
00
1203 ) || $self->pass_error( $gpg->error ) );
1204 }
1205  
1206  
1207 # smime_encrypt( %opts )
1208 # Encrypts this message for one or more recipients. Returns a new Mail::Make object whose
1209 # entity is a RFC 5751 application/pkcs7-mime enveloped message.
1210 #
1211 # Required options:
1212 # RecipientCert => $pem_string_or_path (or arrayref of either)
1213 #
1214 # Optional options:
1215 # CACert => $pem_string_or_path
1216 sub smime_encrypt
1217 0 ▶{
Subroutine smime_encrypt: not called CC=5 SCAR=34.0
Pod documented
1218 0 my $self = shift( @_ );
1219 0 my $opts = $self->_get_args_as_hash( @_ );
1220 0 require Mail::Make::SMIME;
1221 my $smime = Mail::Make::SMIME->new(
1222 0 ▶ ( defined( $opts->{CACert} ) ? ( ca_cert => $opts->{CACert} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'CACert'} ? : 0 0 0
Condition0%0/2
'Mail::Make::SMIME'->new(defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::SMIME'->new(defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
'Mail::Make::SMIME'->new(defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::SMIME'->new(defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Aresult
11
00
1223 ) || return( $self->pass_error( Mail::Make::SMIME->error ) );
1224  
1225 return( $smime->encrypt(
1226 entity => $self,
1227 RecipientCert => ( $opts->{RecipientCert} ||
1228 0 ▶ return( $self->error( 'RecipientCert option is required.' ) ) ),
Condition0%0/5
$smime->encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) || $self->pass_error($smime->error)
l!l&&r!l&&!r
000
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
l!l
00
MC/DC0%0/2
$smime->encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) || $self->pass_error($smime->error)
$smime->encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) $self->pass_error($smime->error)
MC/DC0%0/1
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
$opts->{'RecipientCert'}
Truth table0%0/3
A || B
A= $smime->encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.')))B= $self->pass_error($smime->error)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts->{'RecipientCert'}
Aresult
11
00
1229 ) || $self->pass_error( $smime->error ) );
1230 }
1231  
1232 # smime_sign( %opts )
1233 # Signs this message and returns a new Mail::Make object whose entity is a RFC 5751
1234 # multipart/signed structure with a detached S/MIME signature.
1235 #
1236 # Required options:
1237 # Cert => $pem_string_or_path
1238 # Key => $pem_string_or_path
1239 #
1240 # Optional options:
1241 # KeyPassword => $string_or_coderef
1242 # CACert => $pem_string_or_path
1243 sub smime_sign
1244 0 ▶{
Subroutine smime_sign: not called CC=7 SCAR=40.3
Pod documented
1245 0 my $self = shift( @_ );
1246 0 my $opts = $self->_get_args_as_hash( @_ );
1247 0 require Mail::Make::SMIME;
1248 my $smime = Mail::Make::SMIME->new(
1249 ( defined( $opts->{Cert} ) ? ( cert => $opts->{Cert} ) : () ),
1250 ( defined( $opts->{Key} ) ? ( key => $opts->{Key} ) : () ),
1251 ( defined( $opts->{KeyPassword} ) ? ( key_password => $opts->{KeyPassword} ) : () ),
1252 0 ▶ ( defined( $opts->{CACert} ) ? ( ca_cert => $opts->{CACert} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $opts->{'Cert'} ? : 0 0 0
defined $opts->{'Key'} ? : 0 0 0
defined $opts->{'KeyPassword'} ? : 0 0 0
defined $opts->{'CACert'} ? : 0 0 0
Condition0%0/2
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Aresult
11
00
1253 ) || return( $self->pass_error( Mail::Make::SMIME->error ) );
1254  
1255 0 ▶ return( $smime->sign(
Condition0%0/3
$smime->sign('entity', $self) || $self->pass_error($smime->error)
l!l&&r!l&&!r
000
MC/DC0%0/2
$smime->sign('entity', $self) || $self->pass_error($smime->error)
$smime->sign('entity', $self) $self->pass_error($smime->error)
Truth table0%0/3
A || B
A= $smime->sign('entity', $self)B= $self->pass_error($smime->error)
ABresult
1X1
011
000
1256 entity => $self,
1257 ) || $self->pass_error( $smime->error ) );
1258 }
1259  
1260 # smime_sign_encrypt( %opts )
1261 # Signs then encrypts this message. Returns a new Mail::Make object whose entity is a
1262 # RFC 5751 enveloped message containing a signed payload.
1263 #
1264 # Required options:
1265 # Cert => $pem_string_or_path
1266 # Key => $pem_string_or_path
1267 # RecipientCert => $pem_string_or_path (or arrayref of either)
1268 #
1269 # Optional options:
1270 # KeyPassword => $string_or_coderef
1271 # CACert => $pem_string_or_path
1272 sub smime_sign_encrypt
1273 0 ▶{
Subroutine smime_sign_encrypt: not called CC=8 SCAR=42.8
Pod documented
1274 0 my $self = shift( @_ );
1275 0 my $opts = $self->_get_args_as_hash( @_ );
1276 0 require Mail::Make::SMIME;
1277 my $smime = Mail::Make::SMIME->new(
1278 ( defined( $opts->{Cert} ) ? ( cert => $opts->{Cert} ) : () ),
1279 ( defined( $opts->{Key} ) ? ( key => $opts->{Key} ) : () ),
1280 ( defined( $opts->{KeyPassword} ) ? ( key_password => $opts->{KeyPassword} ) : () ),
1281 0 ▶ ( defined( $opts->{CACert} ) ? ( ca_cert => $opts->{CACert} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $opts->{'Cert'} ? : 0 0 0
defined $opts->{'Key'} ? : 0 0 0
defined $opts->{'KeyPassword'} ? : 0 0 0
defined $opts->{'CACert'} ? : 0 0 0
Condition0%0/2
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
l!l
00
MC/DC0%0/1
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Truth table0%0/2
A
A= 'Mail::Make::SMIME'->new(defined $opts->{'Cert'} ? ('cert', $opts->{'Cert'}) : (), defined $opts->{'Key'} ? ('key', $opts->{'Key'}) : (), defined $opts->{'KeyPassword'} ? ('key_password', $opts->{'KeyPassword'}) : (), defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ())
Aresult
11
00
1282 ) || return( $self->pass_error( Mail::Make::SMIME->error ) );
1283  
1284 return( $smime->sign_encrypt(
1285 entity => $self,
1286 RecipientCert => ( $opts->{RecipientCert} ||
1287 0 ▶ return( $self->error( 'RecipientCert option is required.' ) ) ),
Condition0%0/5
$smime->sign_encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) || $self->pass_error($smime->error)
l!l&&r!l&&!r
000
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
l!l
00
MC/DC0%0/2
$smime->sign_encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) || $self->pass_error($smime->error)
$smime->sign_encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))) $self->pass_error($smime->error)
MC/DC0%0/1
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
$opts->{'RecipientCert'}
Truth table0%0/3
A || B
A= $smime->sign_encrypt('entity', $self, 'RecipientCert', $opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.')))B= $self->pass_error($smime->error)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts->{'RecipientCert'}
Aresult
11
00
1288 ) || $self->pass_error( $smime->error ) );
1289 }
1290  
1291 # _default_domain()
1292 # Returns a reasonable FQDN for auto-generating Message-IDs.
1293 # Uses Sys::Hostname (core) and falls back to 'mail.make.local'.
1294 sub _default_domain
1295 83 ▶{
Subroutine _default_domain: called CC=5 SCAR=17.8
1296 83 my $self = shift( @_ );
1297 83 local $@;
1298 my $host = eval
1299 83 {
1300 83 require Sys::Hostname;
1301 83 Sys::Hostname::hostname();
1302 };
1303 83 ▶ return( 'mail.make.local' ) if( $@ || !defined( $host ) || !length( $host ) );
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not defined $host or not length $host 0 83 83
Condition33%2/6
$@ or not defined $host or not length $host
l!l&&r!l&&!r
0083
$@ or not defined $host
l!l&&r!l&&!r
0083
MC/DC0%0/3
$@ or not defined $host or not length $host
$@ not defined $host not length $host
Truth table25%1/4
A or not(B) or not(C)
A= $@B= not defined $hostC= not length $host
ABCresult
1XX1
01X1
0011
0000
1304 # If it is not a FQDN (no dot), append .local to avoid rejection by
1305 # Mail::Make::Headers::_generate_message_id
1306 83 ▶ $host .= '.local' if( index( $host, '.' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($host, ".") == -1) 83 0 83
1307 83 return( $host );
1308 }
1309  
1310 # _encode_address( $addr_string )
1311 # Encodes the display name portion of an RFC 2822 address using RFC 2047 when it contains
1312 # non-ASCII characters. The addr-spec (the part inside angle brackets) is never altered.
1313 #
1314 # Recognised forms:
1315 # "Display Name" <local@domain>
1316 # Display Name <local@domain>
1317 # local@domain (bare addr-spec, passed through unchanged)
1318 #
1319 # Returns the wire-safe string.
1320 sub _encode_address
1321 145 ▶{
Subroutine _encode_address: called CC=5 SCAR=16.4
1322 145 my( $self, $addr ) = @_;
1323 145 ▶ return( $addr ) unless( defined( $addr ) && length( $addr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr and length $addr 0 145 145
Condition33%1/3
defined $addr and length $addr
!ll&&!rl&&r
00145
MC/DC0%0/2
defined $addr and length $addr
defined $addr length $addr
Truth table33%1/3
A and B
A= defined $addrB= length $addr
ABresult
0X0
100
111
1324 145 ▶ if( $addr =~ /^("?)([^<"]+)\1\s*<([^>]+)>\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($addr =~ /^("?)([^<"]+)\1\s*<([^>]+)>\s*$/) 7 138 145
1325 {
1326 7 my( $name, $spec ) = ( $2, $3 );
1327 7 $name =~ s/^\s+|\s+$//g;
1328 7 my $enc = $self->_encode_header( $name );
1329 # If the name was encoded (contains non-ASCII), the encoded-word is
1330 # self-quoting and must NOT be surrounded by double-quotes.
1331 # If it is plain ASCII, keep surrounding quotes for correct parsing.
1332 7 ▶ return( $enc ne $name
Branch: 1 branch
BranchTrueFalseTotal
$enc ne $name ? : 3 4 7
1333 ? "${enc} <${spec}>"
1334 : qq{"${name}" <${spec}>} );
1335 }
1336 # Bare addr-spec; nothing to encode
1337 138 return( $addr );
1338 }
1339  
1340 # _encode_header( $string )
1341 # Encodes a header value for the wire using RFC 2047 if necessary.
1342 # Delegates to Mail::Make::Headers::Subject which handles fragmentation, fold points,
1343 # and UTF-8 boundary safety.
1344 sub _encode_header
1345 64 ▶{
Subroutine _encode_header: called CC=2 SCAR=7.0
1346 64 my( $self, $str ) = @_;
1347 64 ▶ return( $str ) unless( defined( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 64 64
1348 64 my $s = Mail::Make::Headers::Subject->new;
1349 64 $s->value( $str );
1350 64 return( $s->as_string );
1351 }
1352  
1353 # _format_date()
1354 # Returns the current date/time in RFC 2822 format.
1355 sub _format_date
1356 78 ▶{
Subroutine _format_date: called CC=8 SCAR=23.9
1357 78 my @t = localtime( time );
1358 78 my @day = qw( Sun Mon Tue Wed Thu Fri Sat );
1359 78 my @mon = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
1360 my $tz = do
1361 78 {
1362 78 my @lt = localtime( time );
1363 78 my @gt = gmtime( time );
1364 78 my $diff = ( $lt[2] - $gt[2] ) * 60 + ( $lt[1] - $gt[1] );
1365 78 ▶ $diff += 1440 if( $lt[5] > $gt[5] || ( $lt[5] == $gt[5] && $lt[7] > $gt[7] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $lt[5] > $gt[5] or $lt[5] == $gt[5] and $lt[7] > $gt[7] 0 78 78
Condition33%2/6
$lt[5] > $gt[5] or $lt[5] == $gt[5] and $lt[7] > $gt[7]
l!l&&r!l&&!r
0078
$lt[5] == $gt[5] and $lt[7] > $gt[7]
!ll&&!rl&&r
0780
MC/DC0%0/3
$lt[5] > $gt[5] or $lt[5] == $gt[5] and $lt[7] > $gt[7]
$lt[5] > $gt[5] $lt[5] == $gt[5] $lt[7] > $gt[7]
Truth table25%1/4
A or B and C
A= $lt[5] > $gt[5]B= $lt[5] == $gt[5]C= $lt[7] > $gt[7]
ABCresult
1XX1
0111
00X0
0100
1366 78 ▶ $diff -= 1440 if( $lt[5] < $gt[5] || ( $lt[5] == $gt[5] && $lt[7] < $gt[7] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $lt[5] < $gt[5] or $lt[5] == $gt[5] and $lt[7] < $gt[7] 0 78 78
Condition33%2/6
$lt[5] < $gt[5] or $lt[5] == $gt[5] and $lt[7] < $gt[7]
l!l&&r!l&&!r
0078
$lt[5] == $gt[5] and $lt[7] < $gt[7]
!ll&&!rl&&r
0780
MC/DC0%0/3
$lt[5] < $gt[5] or $lt[5] == $gt[5] and $lt[7] < $gt[7]
$lt[5] < $gt[5] $lt[5] == $gt[5] $lt[7] < $gt[7]
Truth table25%1/4
A or B and C
A= $lt[5] < $gt[5]B= $lt[5] == $gt[5]C= $lt[7] < $gt[7]
ABCresult
1XX1
0111
00X0
0100
1367 78 ▶ my $sign = $diff >= 0 ? '+' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$diff >= 0 ? : 78 0 78
1368 78 $diff = abs( $diff );
1369 78 sprintf( '%s%02d%02d', $sign, int( $diff / 60 ), $diff % 60 );
1370 };
1371 78 return( sprintf( '%s, %02d %s %04d %02d:%02d:%02d %s',
1372 $day[ $t[6] ], $t[3], $mon[ $t[4] ], $t[5] + 1900,
1373 $t[2], $t[1], $t[0], $tz ) );
1374 }
1375  
1376 # _hti_attr( $node, $attr )
1377 # Gets an attribute value from a DOM node, compatible with both parsers.
1378 sub _hti_attr
1379 37 ▶{
Subroutine _hti_attr: called CC=3 SCAR=13.3
1380 37 my( $self, $node, $attr ) = @_;
1381 # HTML::Object::DOM
1382 37 ▶ if( $node->can( 'getAttribute' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($node->can('getAttribute')) { } 0 37 37
elsif ($node->can('attr')) { } 37 0 37
1383 {
1384 0 return( $node->getAttribute( $attr ) );
1385 }
1386 # HTML::Object::DOM and HTML::TreeBuilder both support attr()
1387 elsif( $node->can( 'attr' ) )
1388 {
1389 37 return( $node->attr( $attr ) );
1390 }
1391 0 return;
1392 }
1393  
1394 # _hti_ext_for( $url, $mime_type )
1395 # Derives a lowercase file extension from the URL path or, failing that, from the MIME
1396 # type string.
1397 sub _hti_ext_for
1398 16 ▶{
Subroutine _hti_ext_for: called CC=4 SCAR=22.3
1399 16 my( $self, $url, $mime_type ) = @_;
1400 # Try the URL path first
1401 16 ▶ if( $url =~ /\.([a-zA-Z0-9]+)(?:[?#]|$)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /\.([a-zA-Z0-9]+)(?:[?#]|$)/) 16 0 16
1402 {
1403 16 return( lc( $1 ) );
1404 }
1405 # Fall back to the subtype portion of the MIME type (e.g. 'png' from 'image/png')
1406 0 ▶ if( defined( $mime_type ) && $mime_type =~ m{/([a-zA-Z0-9]+)$} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mime_type and $mime_type =~ m[/([a-zA-Z0-9]+)$]) 0 0 0
Condition0%0/3
defined $mime_type and $mime_type =~ m[/([a-zA-Z0-9]+)$]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $mime_type and $mime_type =~ m[/([a-zA-Z0-9]+)$]
defined $mime_type $mime_type =~ m[/([a-zA-Z0-9]+)$]
Truth table0%0/3
A and B
A= defined $mime_typeB= $mime_type =~ m[/([a-zA-Z0-9]+)$]
ABresult
0X0
100
111
1407 {
1408 0 return( lc( $1 ) );
1409 }
1410 0 return( '' );
1411 }
1412  
1413 # _hti_fetch( $url, %opts )
1414 # Fetches a URL and returns a hashref { data => $bytes, mime_type => $str }, or sets an
1415 # error and returns undef on failure.
1416 #
1417 # Supports:
1418 # file:///path/to/file read directly from disk
1419 # http:// / https:// HTTP::Promise preferred, LWP::UserAgent as fallback
1420 #
1421 # When cache_dir is provided, caches the response body on disk using MD5(url).ext as the
1422 # filename, with a sidecar .json for ETag / Last-Modified used in conditional requests.
1423 sub _hti_fetch
1424 22 ▶{
Subroutine _hti_fetch: called CC=53 SCAR=75.2
1425 22 my $self = shift( @_ );
1426 22 my $url = shift( @_ );
1427 22 my $opts = $self->_get_args_as_hash( @_ );
1428 22 my $cache_dir = $opts->{cache_dir};
1429  
1430 # Per-instance cache lookup
1431 22 ▶ return( $self->{_hti_cache}->{ $url } ) if( exists( $self->{_hti_cache}->{ $url } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_hti_cache"}{$url} 0 22 22
1432  
1433 22 my( $data, $mime_type );
1434  
1435 # file:// URI -> read directly from disk
1436 22 ▶ if( lc( substr( $url, 0, 7 ) ) eq 'file://' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc substr($url, 0, 7) eq 'file://') { } 22 0 22
1437 {
1438 22 my $f = $self->new_file( $url );
1439 22 ▶ unless( $f->exists )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->exists) 1 21 22
1440 {
1441 1 return( $self->error( "File '$url' does not exist." ) );
1442 }
1443 # Use binmode => 'raw' to read binary assets (PNG, GIF, JPEG...) without
1444 # any newline translation or encoding layer.
1445 21 my $raw = $f->load( binmode => 'raw' );
1446 21 ▶ if( !defined( $raw ) && $f->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $raw and $f->error) 0 21 21
Condition33%1/3
not defined $raw and $f->error
!ll&&!rl&&r
2100
MC/DC0%0/2
not defined $raw and $f->error
not defined $raw $f->error
Truth table33%1/3
not(A) and B
A= not defined $rawB= $f->error
ABresult
0X0
100
111
1447 {
1448 0 return( $self->error( "Could not read file '$url': " . $f->error ) );
1449 }
1450 21 ▶ $data = ref( $raw ) ? "$raw" : $raw;
Branch: 1 branch
BranchTrueFalseTotal
ref $raw ? : 0 21 21
1451 21 ▶ $mime_type = eval{ $f->finfo->mime_type } // 'application/octet-stream';
Condition50%1/2
eval { do { $f->finfo->mime_type } } // "application/octet-stream"
l!l
210
MC/DC0%0/1
eval { do { $f->finfo->mime_type } } // "application/octet-stream"
eval { do { $f->finfo->mime_type } }
Truth table50%1/2
A
A= eval { do { $f->finfo->mime_type } }
Aresult
11
00
1452 21 ▶ $mime_type = "$mime_type" if( ref( $mime_type ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $mime_type 21 0 21
1453 }
1454 else
1455 {
1456 # Persistent cache support
1457 0 my( $cache_file, $sidecar, $cache_meta );
1458 0 ▶ if( defined( $cache_dir ) && length( $cache_dir ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache_dir and length $cache_dir) 0 0 0
Condition0%0/3
defined $cache_dir and length $cache_dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_dir and length $cache_dir
defined $cache_dir length $cache_dir
Truth table0%0/3
A and B
A= defined $cache_dirB= length $cache_dir
ABresult
0X0
100
111
1459 {
1460 # Core module
1461 0 require Digest::MD5;
1462 0 my $ext = $self->_hti_ext_for( $url, undef );
1463 0 my $hash = Digest::MD5::md5_hex( $url );
1464 0 ▶ my $base = defined( $ext ) && length( $ext )
Branch: 1 branch
BranchTrueFalseTotal
defined $ext && length $ext ? : 0 0 0
Condition0%0/3
defined $ext and length $ext
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ext and length $ext
defined $ext length $ext
Truth table0%0/3
A and B
A= defined $extB= length $ext
ABresult
0X0
100
111
1465 ? "${hash}.${ext}"
1466 : $hash;
1467 0 my $dir = $self->new_file( $cache_dir );
1468 0 $cache_file = $dir->child( $base );
1469 0 $sidecar = $dir->child( "${base}.json" );
1470 0 ▶ if( $sidecar->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($sidecar->exists) 0 0 0
1471 {
1472 0 ▶ $cache_meta = $sidecar->load_json // {};
Condition0%0/2
$sidecar->load_json // {}
l!l
00
MC/DC0%0/1
$sidecar->load_json // {}
$sidecar->load_json
Truth table0%0/2
A
A= $sidecar->load_json
Aresult
11
00
1473 }
1474 0 ▶ $cache_meta //= {};
Condition0%0/2
$cache_meta //= {}
l!l
00
MC/DC0%0/1
$cache_meta //= {}
$cache_meta
Truth table0%0/2
A
A= $cache_meta
Aresult
11
00
1475 }
1476  
1477 # Try HTTP::Promise first, then LWP::UserAgent
1478 # $resp is declared here so it is in scope for the cache-update block below.
1479 0 my $resp;
1480 0 ▶ if( $self->_load_class( 'HTTP::Promise' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_load_class('HTTP::Promise')) { } 0 0 0
elsif ($self->_load_class('LWP::UserAgent')) { } 0 0 0
1481 {
1482 0 my $ua = HTTP::Promise->new(
1483 use_promise => 0,
1484 ext_vary => 1,
1485 );
1486 0 my %cond_headers;
1487 0 ▶ if( defined( $cache_file ) && $cache_file->exists )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache_file and $cache_file->exists) 0 0 0
Condition0%0/3
defined $cache_file and $cache_file->exists
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_file and $cache_file->exists
defined $cache_file $cache_file->exists
Truth table0%0/3
A and B
A= defined $cache_fileB= $cache_file->exists
ABresult
0X0
100
111
1488 {
1489 0 ▶ if( defined( $cache_meta->{etag} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cache_meta->{'etag'} and length $cache_meta->{'etag'}) { } 0 0 0
elsif (not exists $cond_headers{'If-None-Match'} and defined $cache_meta->{'last_modified'} and length $cache_meta->{'last_modified'}) { } 0 0 0
Condition0%0/3
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
defined $cache_meta->{"etag"} length $cache_meta->{"etag"}
Truth table0%0/3
A and B
A= defined $cache_meta->{"etag"}B= length $cache_meta->{"etag"}
ABresult
0X0
100
111
1490 length( $cache_meta->{etag} ) )
1491 {
1492 0 $cond_headers{'If-None-Match'} = $cache_meta->{etag};
1493 }
1494 ▶ elsif( !exists( $cond_headers{'If-None-Match'} ) &&
Condition0%0/6
not exists $cond_headers{"If-None-Match"} and defined $cache_meta->{"last_modified"} and length $cache_meta->{"last_modified"}
!ll&&!rl&&r
000
not exists $cond_headers{"If-None-Match"} and defined $cache_meta->{"last_modified"}
!ll&&!rl&&r
000
MC/DC0%0/3
not exists $cond_headers{"If-None-Match"} and defined $cache_meta->{"last_modified"} and length $cache_meta->{"last_modified"}
not exists $cond_headers{"If-None-Match"} defined $cache_meta->{"last_modified"} length $cache_meta->{"last_modified"}
Truth table0%0/4
not(A) and B and C
A= not exists $cond_headers{"If-None-Match"}B= defined $cache_meta->{"last_modified"}C= length $cache_meta->{"last_modified"}
ABCresult
0XX0
10X0
1100
1111
1495 defined( $cache_meta->{last_modified} ) &&
1496 length( $cache_meta->{last_modified} ) )
1497 {
1498 0 $cond_headers{'If-Modified-Since'} = $cache_meta->{last_modified};
1499 }
1500 }
1501 0 $resp = $ua->get( $url, %cond_headers );
1502 0 ▶ unless( defined( $resp ) && $resp->is_success )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp and $resp->is_success) { } 0 0 0
Condition0%0/3
defined $resp and $resp->is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resp and $resp->is_success
defined $resp $resp->is_success
Truth table0%0/3
A and B
A= defined $respB= $resp->is_success
ABresult
0X0
100
111
1503 {
1504 # 304 Not Modified; use the cached copy
1505 0 ▶ if( defined( $resp ) && $resp->status_code == 304 &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp and $resp->status_code == 304 and defined $cache_file and $cache_file->exists) { } 0 0 0
Condition0%0/9
defined $resp and $resp->status_code == 304 and defined $cache_file and $cache_file->exists
!ll&&!rl&&r
000
defined $resp and $resp->status_code == 304 and defined $cache_file
!ll&&!rl&&r
000
defined $resp and $resp->status_code == 304
!ll&&!rl&&r
000
MC/DC0%0/4
defined $resp and $resp->status_code == 304 and defined $cache_file and $cache_file->exists
defined $resp $resp->status_code == 304 defined $cache_file $cache_file->exists
Truth table0%0/5
A and B and C and D
A= defined $respB= $resp->status_code == 304C= defined $cache_fileD= $cache_file->exists
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1506 defined( $cache_file ) && $cache_file->exists )
1507 {
1508 0 $data = $cache_file->load;
1509 0 ▶ $mime_type = $cache_meta->{mime_type} // 'application/octet-stream';
Condition0%0/2
$cache_meta->{"mime_type"} // "application/octet-stream"
l!l
00
MC/DC0%0/1
$cache_meta->{"mime_type"} // "application/octet-stream"
$cache_meta->{"mime_type"}
Truth table0%0/2
A
A= $cache_meta->{"mime_type"}
Aresult
11
00
1510 }
1511 else
1512 {
1513 0 ▶ return( $self->error( "GET $url failed: " . ( defined( $resp ) ? $resp->status_line : $ua->error ) ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $resp ? : 0 0 0
1514 }
1515 }
1516 else
1517 {
1518 0 $data = $resp->decoded_content( charset => 'none' );
1519 $mime_type = do
1520 0 {
1521 0 my $ct = $resp->content_type;
1522 0 $ct =~ s/;.*//;
1523 0 $ct;
1524 };
1525 }
1526 }
1527 elsif( $self->_load_class( 'LWP::UserAgent' ) )
1528 {
1529 0 my $ua = LWP::UserAgent->new( timeout => 30 );
1530 0 my $req = HTTP::Request->new( GET => $url );
1531 0 ▶ if( defined( $cache_file ) && $cache_file->exists )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache_file and $cache_file->exists) 0 0 0
Condition0%0/3
defined $cache_file and $cache_file->exists
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_file and $cache_file->exists
defined $cache_file $cache_file->exists
Truth table0%0/3
A and B
A= defined $cache_fileB= $cache_file->exists
ABresult
0X0
100
111
1532 {
1533 0 ▶ if( defined( $cache_meta->{etag} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cache_meta->{'etag'} and length $cache_meta->{'etag'}) { } 0 0 0
elsif (not $req->header('If-None-Match') and defined $cache_meta->{'last_modified'} and length $cache_meta->{'last_modified'}) { } 0 0 0
Condition0%0/3
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
defined $cache_meta->{"etag"} length $cache_meta->{"etag"}
Truth table0%0/3
A and B
A= defined $cache_meta->{"etag"}B= length $cache_meta->{"etag"}
ABresult
0X0
100
111
1534 length( $cache_meta->{etag} ) )
1535 {
1536 0 $req->header( 'If-None-Match' => $cache_meta->{etag} );
1537 }
1538 ▶ elsif( !$req->header( 'If-None-Match' ) &&
Condition0%0/6
not $req->header("If-None-Match") and defined $cache_meta->{"last_modified"} and length $cache_meta->{"last_modified"}
!ll&&!rl&&r
000
not $req->header("If-None-Match") and defined $cache_meta->{"last_modified"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $req->header("If-None-Match") and defined $cache_meta->{"last_modified"} and length $cache_meta->{"last_modified"}
not $req->header("If-None-Match") defined $cache_meta->{"last_modified"} length $cache_meta->{"last_modified"}
Truth table0%0/4
not(A) and B and C
A= not $req->header("If-None-Match")B= defined $cache_meta->{"last_modified"}C= length $cache_meta->{"last_modified"}
ABCresult
0XX0
10X0
1100
1111
1539 defined( $cache_meta->{last_modified} ) &&
1540 length( $cache_meta->{last_modified} ) )
1541 {
1542 0 $req->header( 'If-Modified-Since' => $cache_meta->{last_modified} );
1543 }
1544 }
1545 0 $resp = $ua->request( $req );
1546 0 ▶ unless( $resp->is_success )
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->is_success) { } 0 0 0
1547 {
1548 0 ▶ if( $resp->code == 304 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->code == 304 and defined $cache_file and $cache_file->exists) { } 0 0 0
Condition0%0/6
$resp->code == 304 and defined $cache_file and $cache_file->exists
!ll&&!rl&&r
000
$resp->code == 304 and defined $cache_file
!ll&&!rl&&r
000
MC/DC0%0/3
$resp->code == 304 and defined $cache_file and $cache_file->exists
$resp->code == 304 defined $cache_file $cache_file->exists
Truth table0%0/4
A and B and C
A= $resp->code == 304B= defined $cache_fileC= $cache_file->exists
ABCresult
0XX0
10X0
1100
1111
1549 defined( $cache_file ) && $cache_file->exists )
1550 {
1551 0 $data = $cache_file->load;
1552 0 ▶ $mime_type = $cache_meta->{mime_type} // 'application/octet-stream';
Condition0%0/2
$cache_meta->{"mime_type"} // "application/octet-stream"
l!l
00
MC/DC0%0/1
$cache_meta->{"mime_type"} // "application/octet-stream"
$cache_meta->{"mime_type"}
Truth table0%0/2
A
A= $cache_meta->{"mime_type"}
Aresult
11
00
1553 }
1554 else
1555 {
1556 0 return( $self->error( "GET $url failed: " . $resp->status_line ) );
1557 }
1558 }
1559 else
1560 {
1561 0 $data = $resp->content;
1562 $mime_type = do
1563 0 {
1564 0 my $ct = $resp->content_type;
1565 0 $ct =~ s/;.*//;
1566 0 $ct;
1567 };
1568 }
1569 }
1570 else
1571 {
1572 0 return( $self->error( "Neither HTTP::Promise nor LWP::UserAgent is available." ) );
1573 }
1574  
1575 # Update the persistent cache if cache_dir was provided.
1576 # $resp is the last HTTP response object; it is defined when we got a 200
1577 # (data freshly downloaded) but not when we served from cache (304).
1578 0 ▶ if( defined( $cache_file ) && defined( $data ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache_file and defined $data) 0 0 0
Condition0%0/3
defined $cache_file and defined $data
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_file and defined $data
defined $cache_file defined $data
Truth table0%0/3
A and B
A= defined $cache_fileB= defined $data
ABresult
0X0
100
111
1579 {
1580 0 $cache_file->save( $data );
1581 0 $cache_meta->{mime_type} = $mime_type;
1582 0 ▶ if( defined( $resp ) && $resp->can( 'header' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp and $resp->can("header")) 0 0 0
Condition0%0/3
defined $resp and $resp->can("header")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resp and $resp->can("header")
defined $resp $resp->can("header")
Truth table0%0/3
A and B
A= defined $respB= $resp->can("header")
ABresult
0X0
100
111
1583 {
1584 0 my $etag = $resp->header( 'ETag' );
1585 0 my $lm = $resp->header( 'Last-Modified' );
1586 0 ▶ $cache_meta->{etag} = $etag if( defined( $etag ) && length( $etag ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $etag and length $etag 0 0 0
Condition0%0/3
defined $etag and length $etag
!ll&&!rl&&r
000
MC/DC0%0/2
defined $etag and length $etag
defined $etag length $etag
Truth table0%0/3
A and B
A= defined $etagB= length $etag
ABresult
0X0
100
111
1587 0 ▶ $cache_meta->{last_modified} = $lm if( defined( $lm ) && length( $lm ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $lm and length $lm 0 0 0
Condition0%0/3
defined $lm and length $lm
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lm and length $lm
defined $lm length $lm
Truth table0%0/3
A and B
A= defined $lmB= length $lm
ABresult
0X0
100
111
1588 }
1589 0 $sidecar->save_json( $cache_meta );
1590 }
1591 }
1592  
1593 21 my $result = { data => $data, mime_type => $mime_type };
1594 # Store in the per-instance cache to avoid re-fetching within this message
1595 21 $self->{_hti_cache}->{ $url } = $result;
1596 21 return( $result );
1597 }
1598  
1599 # _hti_find_nodes( $dom, $tag )
1600 # Returns an arrayref of nodes matching the given tag name.
1601 # Works with both HTML::Object::DOM and HTML::TreeBuilder.
1602 sub _hti_find_nodes
1603 37 ▶{
Subroutine _hti_find_nodes: called CC=20 SCAR=48.0
1604 37 my( $self, $dom, $tag ) = @_;
1605 # HTML::Object::DOM for now, but could be other classes in the future.
1606 37 ▶ if( ref( $dom ) && $dom->can( 'getElementsByTagName' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $dom and $dom->can('getElementsByTagName')) { } 0 37 37
elsif (ref $dom and $dom->can('find_by_tag_name')) { } 37 0 37
Condition33%1/3
ref $dom and $dom->can("getElementsByTagName")
!ll&&!rl&&r
0370
MC/DC0%0/2
ref $dom and $dom->can("getElementsByTagName")
ref $dom $dom->can("getElementsByTagName")
Truth table33%1/3
A and B
A= ref $domB= $dom->can("getElementsByTagName")
ABresult
0X0
100
111
1607 {
1608 0 my $list = $dom->getElementsByTagName( $tag );
1609 # If we had an error, we pass it along.
1610 0 ▶ return( $dom->pass_error ) if( !defined( $list ) && $dom->can( 'error' ) && $dom->can( 'pass_error' ) && $dom->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $list and $dom->can("error") and $dom->can("pass_error") and $dom->error 0 0 0
Condition0%0/9
not defined $list and $dom->can("error") and $dom->can("pass_error") and $dom->error
!ll&&!rl&&r
000
not defined $list and $dom->can("error") and $dom->can("pass_error")
!ll&&!rl&&r
000
not defined $list and $dom->can("error")
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $list and $dom->can("error") and $dom->can("pass_error") and $dom->error
not defined $list $dom->can("error") $dom->can("pass_error") $dom->error
Truth table0%0/5
not(A) and B and C and D
A= not defined $listB= $dom->can("error")C= $dom->can("pass_error")D= $dom->error
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1611 0 ▶ return( defined( $list ) ? [ $list->list ] : [] );
Branch: 1 branch
BranchTrueFalseTotal
defined $list ? : 0 0 0
1612 }
1613 # HTML::Object::Element and HTML::TreeBuilder both expose find_by_tag_name(), which
1614 # returns a Module::Generic::Array-like object with a list() method.
1615 ▶ elsif( ref( $dom ) && $dom->can( 'find_by_tag_name' ) )
Condition33%1/3
ref $dom and $dom->can("find_by_tag_name")
!ll&&!rl&&r
0037
MC/DC0%0/2
ref $dom and $dom->can("find_by_tag_name")
ref $dom $dom->can("find_by_tag_name")
Truth table33%1/3
A and B
A= ref $domB= $dom->can("find_by_tag_name")
ABresult
0X0
100
111
1616 {
1617 # Because HTML::TreeBuilder returns an array while HTML::Object::Element returns
1618 # an array object.
1619 37 my @list = $dom->find_by_tag_name( $tag );
1620 37 ▶ return( $dom->pass_error ) if( !scalar( @list ) && $dom->can( 'error' ) && $dom->can( 'pass_error' ) && $dom->error );
Branch: 1 branch
BranchTrueFalseTotal
if not scalar @list and $dom->can("error") and $dom->can("pass_error") and $dom->error 0 37 37
Condition44%4/9
not scalar @list and $dom->can("error") and $dom->can("pass_error") and $dom->error
!ll&&!rl&&r
3700
not scalar @list and $dom->can("error") and $dom->can("pass_error")
!ll&&!rl&&r
3700
not scalar @list and $dom->can("error")
!ll&&!rl&&r
3430
MC/DC0%0/4
not scalar @list and $dom->can("error") and $dom->can("pass_error") and $dom->error
not scalar @list $dom->can("error") $dom->can("pass_error") $dom->error
Truth table40%2/5
not(A) and B and C and D
A= not scalar @listB= $dom->can("error")C= $dom->can("pass_error")D= $dom->error
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1621 my $list = scalar( @list )
1622 ? ( scalar( @list ) == 1 && defined( $list[0] ) && Scalar::Util::reftype( $list[0] ) eq 'ARRAY' )
1623 ? ( Scalar::Util::blessed( $list[0] ) && $list[0]->can( 'list' ) )
1624 ? [ $list[0]->list ]
1625 0 ▶ : [ @{$list[0]} ]
Branch: 3 branches
BranchTrueFalseTotal
scalar @list ? : 34 3 37
scalar @list == 1 && defined $list[0] && builtin::reftype($list[0]) eq 'ARRAY' ? : 0 34 34
builtin::blessed($list[0]) && $list[0]->can('list') ? : 0 0 0
Condition44%4/9
scalar @list == 1 and defined $list[0] and builtin::reftype($list[0]) eq "ARRAY"
!ll&&!rl&&r
2320
scalar @list == 1 and defined $list[0]
!ll&&!rl&&r
2032
builtin::blessed($list[0]) and $list[0]->can("list")
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @list == 1 and defined $list[0] and builtin::reftype($list[0]) eq "ARRAY"
scalar @list == 1 defined $list[0] builtin::reftype($list[0]) eq "ARRAY"
MC/DC0%0/2
builtin::blessed($list[0]) and $list[0]->can("list")
builtin::blessed($list[0]) $list[0]->can("list")
Truth table50%2/4
A and B and C
A= scalar @list == 1B= defined $list[0]C= builtin::reftype($list[0]) eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= builtin::blessed($list[0])B= $list[0]->can("list")
ABresult
0X0
100
111
1626 : \@list
1627 : [];
1628 37 return( $list );
1629 }
1630 0 return( [] );
1631 }
1632  
1633 # _hti_parse_html( $html )
1634 # Parses an HTML string and returns a DOM object.
1635 # Tries HTML::Object::DOM first, then HTML::TreeBuilder.
1636 sub _hti_parse_html
1637 18 ▶{
Subroutine _hti_parse_html: called CC=4 SCAR=19.4
1638 18 my( $self, $html ) = @_;
1639 18 ▶ if( $self->_load_class( 'HTML::Object::DOM', { no_warning => 1 } ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_load_class('HTML::Object::DOM', {'no_warning', 1})) { } 0 18 18
elsif ($self->_load_class('HTML::TreeBuilder')) { } 18 0 18
1640 {
1641 0 my $parser = HTML::Object::DOM->new( debug => $self->debug );
1642 0 ▶ my $dom = $parser->parse( $html ) ||
Condition0%0/2
$parser->parse($html) || (return $self->error('HTML::Object::DOM parse failed: ' . $parser->error))
l!l
00
MC/DC0%0/1
$parser->parse($html) || (return $self->error('HTML::Object::DOM parse failed: ' . $parser->error))
$parser->parse($html)
Truth table0%0/2
A
A= $parser->parse($html)
Aresult
11
00
1643 return( $self->error( "HTML::Object::DOM parse failed: " . $parser->error ) );
1644 0 return( $dom );
1645 }
1646 elsif( $self->_load_class( 'HTML::TreeBuilder' ) )
1647 {
1648 18 my $tree = HTML::TreeBuilder->new_from_content( $html );
1649 18 return( $tree );
1650 }
1651 0 return( $self->error( "Neither HTML::Object::DOM nor HTML::TreeBuilder is available." ) );
1652 }
1653  
1654 # _hti_attr( $node, $attr )
1655 # Gets an attribute value from a DOM node, compatible with both parsers.
1656 # _hti_process_assets( $raw_html, $opts )
1657 # Core of html_to_inline() and url_to_inline(): parses $raw_html, fetches all external
1658 # assets, rewrites their URLs to cid: references, calls html() with the modified HTML,
1659 # and attaches each asset via attach_inline(). Returns $self.
1660 sub _hti_process_assets
1661 18 ▶{
Subroutine _hti_process_assets: called CC=31 SCAR=36.4
1662 18 my( $self, $raw_html, $opts ) = @_;
1663  
1664 18 my $base_url = $opts->{base_url};
1665 # By default, this is off, because mail readers ignore CSS anyway.
1666 18 ▶ my $embed_css = $opts->{embed_css} // 0;
Condition100%2/2
$opts->{"embed_css"} // 0
l!l
117
MC/DC100%1/1
$opts->{"embed_css"} // 0
$opts->{"embed_css"}
Truth table100%2/2
A
A= $opts->{"embed_css"}
Aresult
11
00
1667 18 my $cache_dir = $opts->{cache_dir};
1668  
1669 # Initialise the per-instance URL cache (avoids fetching the same URL twice within
1670 # one message assembly pass).
1671 18 ▶ $self->{_hti_cache} //= {};
Condition100%2/2
$self->{"_hti_cache"} //= {}
l!l
513
MC/DC100%1/1
$self->{"_hti_cache"} //= {}
$self->{"_hti_cache"}
Truth table100%2/2
A
A= $self->{"_hti_cache"}
Aresult
11
00
1672  
1673 # NOTE: Parse the HTML
1674 18 ▶ my $dom = $self->_hti_parse_html( $raw_html ) ||
Condition50%1/2
$self->_hti_parse_html($raw_html) || (return $self->pass_error)
l!l
180
MC/DC0%0/1
$self->_hti_parse_html($raw_html) || (return $self->pass_error)
$self->_hti_parse_html($raw_html)
Truth table50%1/2
A
A= $self->_hti_parse_html($raw_html)
Aresult
11
00
1675 return( $self->pass_error );
1676  
1677 # NOTE: Collect assets to embed
1678 # Each entry: { node => $node, attr => 'src'|'href', url => $abs_url }
1679 18 my @assets;
1680 my %seen_url;
1681  
1682 # <img src="...">
1683 18 my $imgs = $self->_hti_find_nodes( $dom, 'img' );
1684 18 foreach my $node ( @$imgs )
1685 {
1686 17 ▶ my $src = $self->_hti_attr( $node, 'src' ) // '';
Condition50%1/2
$self->_hti_attr($node, "src") // ""
l!l
170
MC/DC0%0/1
$self->_hti_attr($node, "src") // ""
$self->_hti_attr($node, "src")
Truth table50%1/2
A
A= $self->_hti_attr($node, "src")
Aresult
11
00
1687 17 ▶ next unless( length( $src ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $src 0 17 17
1688 17 ▶ my $abs = $self->_hti_resolve_url( $src, $base_url ) || next;
Condition100%2/2
$self->_hti_resolve_url($src, $base_url) || (next)
l!l
161
MC/DC100%1/1
$self->_hti_resolve_url($src, $base_url) || (next)
$self->_hti_resolve_url($src, $base_url)
Truth table100%2/2
A
A= $self->_hti_resolve_url($src, $base_url)
Aresult
11
00
1689 16 push( @assets, { node => $node, attr => 'src', url => "$abs" } );
1690 }
1691  
1692 # <body background="...">
1693 18 my $bodies = $self->_hti_find_nodes( $dom, 'body' );
1694 18 foreach my $node ( @$bodies )
1695 {
1696 18 ▶ my $bg = $self->_hti_attr( $node, 'background' ) // '';
Condition100%2/2
$self->_hti_attr($node, "background") // ""
l!l
117
MC/DC100%1/1
$self->_hti_attr($node, "background") // ""
$self->_hti_attr($node, "background")
Truth table100%2/2
A
A= $self->_hti_attr($node, "background")
Aresult
11
00
1697 18 ▶ next unless( length( $bg ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $bg 17 1 18
1698 1 ▶ my $abs = $self->_hti_resolve_url( $bg, $base_url ) || next;
Condition50%1/2
$self->_hti_resolve_url($bg, $base_url) || (next)
l!l
10
MC/DC0%0/1
$self->_hti_resolve_url($bg, $base_url) || (next)
$self->_hti_resolve_url($bg, $base_url)
Truth table50%1/2
A
A= $self->_hti_resolve_url($bg, $base_url)
Aresult
11
00
1699 1 push( @assets, { node => $node, attr => 'background', url => "$abs" } );
1700 }
1701  
1702 # <link rel="stylesheet" href="..."> : only when embed_css is true
1703 18 ▶ if( $embed_css )
Branch: 1 branch
BranchTrueFalseTotal
if ($embed_css) 1 17 18
1704 {
1705 1 my $links = $self->_hti_find_nodes( $dom, 'link' );
1706 1 foreach my $node ( @$links )
1707 {
1708 1 ▶ my $rel = lc( $self->_hti_attr( $node, 'rel' ) // '' );
Condition50%1/2
$self->_hti_attr($node, "rel") // ""
l!l
10
MC/DC0%0/1
$self->_hti_attr($node, "rel") // ""
$self->_hti_attr($node, "rel")
Truth table50%1/2
A
A= $self->_hti_attr($node, "rel")
Aresult
11
00
1709 1 ▶ my $href = $self->_hti_attr( $node, 'href' ) // '';
Condition50%1/2
$self->_hti_attr($node, "href") // ""
l!l
10
MC/DC0%0/1
$self->_hti_attr($node, "href") // ""
$self->_hti_attr($node, "href")
Truth table50%1/2
A
A= $self->_hti_attr($node, "href")
Aresult
11
00
1710 1 ▶ next unless( $rel eq 'stylesheet' && length( $href ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "stylesheet" and length $href 0 1 1
Condition33%1/3
$rel eq "stylesheet" and length $href
!ll&&!rl&&r
001
MC/DC0%0/2
$rel eq "stylesheet" and length $href
$rel eq "stylesheet" length $href
Truth table33%1/3
A and B
A= $rel eq "stylesheet"B= length $href
ABresult
0X0
100
111
1711 1 ▶ my $abs = $self->_hti_resolve_url( $href, $base_url ) || next;
Condition50%1/2
$self->_hti_resolve_url($href, $base_url) || (next)
l!l
10
MC/DC0%0/1
$self->_hti_resolve_url($href, $base_url) || (next)
$self->_hti_resolve_url($href, $base_url)
Truth table50%1/2
A
A= $self->_hti_resolve_url($href, $base_url)
Aresult
11
00
1712 1 push( @assets, { node => $node, attr => 'href', url => "$abs" } );
1713 }
1714 }
1715  
1716 # NOTE: Fetch each asset, assign a Content-ID, rewrite the HTML attribute
1717 18 require Data::UUID;
1718 18 my $ug = Data::UUID->new;
1719 18 my $hostname = $self->_default_domain;
1720  
1721 18 foreach my $asset ( @assets )
1722 {
1723 18 my $url = $asset->{url};
1724  
1725 # Reuse Content-ID if the same URL appears more than once
1726 18 my $cid;
1727 18 ▶ if( exists( $seen_url{ $url } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_url{$url}) 1 17 18
1728 {
1729 1 $cid = $seen_url{ $url };
1730 1 $self->_hti_set_attr( $asset->{node}, $asset->{attr}, "cid:${cid}" );
1731 1 next;
1732 }
1733  
1734 17 my $result = $self->_hti_fetch( $url, cache_dir => $cache_dir );
1735 17 ▶ unless( defined( $result ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 1 16 17
1736 {
1737 # Non-fatal: leave the URL unchanged and log a warning
1738 1 ▶ warn( "Could not fetch '$url': " . ( $self->error // 'unknown error' ) ) if( $self->_is_warnings_enabled( 'Mail::Make' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Mail::Make") 0 1 1
Condition0%0/2
$self->error // "unknown error"
l!l
00
MC/DC0%0/1
$self->error // "unknown error"
$self->error
Truth table0%0/2
A
A= $self->error
Aresult
11
00
1739 1 next;
1740 }
1741  
1742 0 ▶ my $data = ref( $result->{data} ) ? "${\$result->{data}}" : $result->{data};
Branch: 1 branch
BranchTrueFalseTotal
ref $result->{'data'} ? : 0 16 16
1743 16 ▶ my $mime_type = $result->{mime_type} // 'application/octet-stream';
Condition50%1/2
$result->{"mime_type"} // "application/octet-stream"
l!l
160
MC/DC0%0/1
$result->{"mime_type"} // "application/octet-stream"
$result->{"mime_type"}
Truth table50%1/2
A
A= $result->{"mime_type"}
Aresult
11
00
1744  
1745 # Derive extension from mime type or URL
1746 16 my $ext = $self->_hti_ext_for( $url, $mime_type );
1747  
1748 16 ▶ $cid = lc( $ug->create_str ) . ( length( $ext ) ? ".${ext}" : '' ) . '@' . $hostname;
Branch: 1 branch
BranchTrueFalseTotal
length $ext ? : 16 0 16
1749 16 $seen_url{ $url } = $cid;
1750  
1751 # Rewrite the src/href attribute to cid:...
1752 16 $self->_hti_set_attr( $asset->{node}, $asset->{attr}, "cid:${cid}" );
1753  
1754 # Attach the asset as an inline part
1755 16 ▶ $self->attach_inline(
Branch: 1 branch
BranchTrueFalseTotal
$self->attach_inline("data", $data, "type", $mime_type, "cid", $cid) or return $self->pass_error 16 0 16
1756 data => $data,
1757 type => $mime_type,
1758 cid => $cid,
1759 ) || return( $self->pass_error );
1760 }
1761  
1762 # Serialise the modified DOM back to HTML
1763 18 my $modified_html = $self->_hti_serialise( $dom );
1764  
1765 # Set the HTML body part
1766 18 my %html_opts;
1767 18 ▶ $html_opts{charset} = $opts->{charset} if( exists( $opts->{charset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"charset"} 0 18 18
1768 18 ▶ $html_opts{encoding} = $opts->{encoding} if( exists( $opts->{encoding} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"encoding"} 0 18 18
1769 18 ▶ $self->html( $modified_html, %html_opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->html($modified_html, %html_opts) or return $self->pass_error 18 0 18
1770  
1771 18 return( $self );
1772 }
1773  
1774 # _hti_resolve_url( $url, $base_url )
1775 # Resolves a potentially relative URL against base_url.
1776 # Accepts file:// URIs. Returns the absolute URL string, or undef on error.
1777 sub _hti_resolve_url
1778 19 ▶{
Subroutine _hti_resolve_url: called CC=8 SCAR=22.2
1779 19 my( $self, $url, $base_url ) = @_;
1780 19 ▶ return unless( defined( $url ) && length( $url ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and length $url 0 19 19
Condition33%1/3
defined $url and length $url
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $url and length $url
defined $url length $url
Truth table33%1/3
A and B
A= defined $urlB= length $url
ABresult
0X0
100
111
1781 # Already absolute (http://, https://, file://)
1782 19 ▶ if( $url =~ m{^(?:https?|file)://}i )
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^(?:https?|file)://]i) 2 17 19
1783 {
1784 2 return( $url );
1785 }
1786 17 ▶ unless( defined( $base_url ) && length( $base_url ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url and length $base_url) 1 16 17
Condition66%2/3
defined $base_url and length $base_url
!ll&&!rl&&r
1016
MC/DC50%1/2
defined $base_url and length $base_url
defined $base_url length $base_url
Truth table66%2/3
A and B
A= defined $base_urlB= length $base_url
ABresult
0X0
100
111
1787 {
1788 1 return( $self->error( "'base_url' is required to resolve relative URL '$url'." ) );
1789 }
1790 16 local $@;
1791 my $abs = eval
1792 16 {
1793 16 require URI;
1794 16 URI->new_abs( $url, $base_url )->as_string;
1795 };
1796 16 ▶ if( $@ || !defined( $abs ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $abs) 0 16 16
Condition33%1/3
$@ or not defined $abs
l!l&&r!l&&!r
0016
MC/DC0%0/2
$@ or not defined $abs
$@ not defined $abs
Truth table33%1/3
A or not(B)
A= $@B= not defined $abs
ABresult
1X1
011
000
1797 {
1798 0 return( $self->error( "Could not resolve '$url' against '$base_url': $@" ) );
1799 }
1800 16 return( $abs );
1801 }
1802  
1803 # _hti_serialise( $dom )
1804 # Serialises a DOM object back to an HTML string.
1805 sub _hti_serialise
1806 18 ▶{
Subroutine _hti_serialise: called CC=3 SCAR=12.7
1807 18 my( $self, $dom ) = @_;
1808 # HTML::Object::DOM
1809 18 ▶ if( $dom->can( 'as_string' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($dom->can("as_string")) 0 18 18
1810 {
1811 0 return( $dom->as_string );
1812 }
1813 # HTML::TreeBuilder
1814 18 ▶ if( $dom->can( 'as_HTML' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($dom->can("as_HTML")) 18 0 18
1815 {
1816 18 return( $dom->as_HTML( '', " " ) );
1817 }
1818 0 return( '' );
1819 }
1820  
1821 # _hti_set_attr( $node, $attr, $value )
1822 # Sets an attribute value on a DOM node, compatible with both parsers.
1823 sub _hti_set_attr
1824 17 ▶{
Subroutine _hti_set_attr: called CC=3 SCAR=13.3
1825 17 my( $self, $node, $attr, $value ) = @_;
1826 # Fallback to W3C setAttribute() with HTML::Object::DOM
1827 17 ▶ if( $node->can( 'setAttribute' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($node->can('setAttribute')) { } 0 17 17
elsif ($node->can('attr')) { } 17 0 17
1828 {
1829 0 return( $node->setAttribute( $attr, $value ) );
1830 }
1831 # HTML::Object::DOM and HTML::TreeBuilder both support attr( $name, $value )
1832 elsif( $node->can( 'attr' ) )
1833 {
1834 17 return( $node->attr( $attr, $value ) );
1835 }
1836 0 return;
1837 }
1838  
1839 # NOTE: STORABLE support
1840 0 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
1841  
1842 0 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
1843  
1844 6 1;
1845 # NOTE: POD
1846 __END__
↑ Summary Mail/Make/SMIME.pm »