| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 // ""
MC/DC0%0/1
$part->effective_type // ""
$part->effective_type
Truth table50%1/2
A
A= $part->effective_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 132 | ▶ | if( $type eq 'text/plain' && $cd !~ /attachment/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$type eq "text/plain" and not $cd =~ /attachment/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 27 | my @missing_cid = grep { !$_->headers->get( 'Content-ID' ) } @inline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 27 | ▶ | if( @missing_cid ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 79 | my $related_entity; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 79 | ▶ | if( $html_entity && @inline ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$html_entity and @inline
MC/DC100%2/2
$html_entity and @inline
$html_entity
@inline
Truth table100%3/3
A and B
A= $html_entityB= @inline
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@plain and $related_entity
MC/DC100%2/2
@plain and $related_entity
@plain
$related_entity
Truth table100%3/3
A and B
A= @plainB= $related_entity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | $self->{_headers}->message_id( { generate => 1, domain => $self->_default_domain } ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 65 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC100%1/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table100%2/2
A
A= $self->as_entity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table0%0/2
A
A= $self->as_entity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
$force_file or defined $threshold and $threshold > 0 and $entity->length > $threshold
defined $threshold and $threshold > 0 and $entity->length > $threshold
defined $threshold and $threshold > 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | $entity->print( $fh ) || return( $self->pass_error( $entity->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%6/9
scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and index("$_[0]", "\n") == -1
scalar(@_) % 2 and !ref($_[0]) || $self->_can_overload($_[0], "\"\"")
not ref $_[0] or $self->_can_overload($_[0], "\"\"")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $opts->{"data"} or defined $opts->{"path"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$opts->{"disposition"} //= "attachment"
$opts->{"disposition"}
Truth table50%1/2
A
A= $opts->{"disposition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $opts->{"data"} or defined $opts->{"path"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $opts->{"id"} or defined $opts->{"cid"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 25 | ▶ | $opts->{disposition} //= 'inline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"disposition"} //= "inline"
MC/DC0%0/1
$opts->{"disposition"} //= "inline"
$opts->{"disposition"}
Truth table50%1/2
A
A= $opts->{"disposition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | my @encoded = map { $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | $self->{_headers}->push_header( 'Bcc' => join( ', ', @encoded ) ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$class->new || (return $class->pass_error)
$class->new
Truth table50%1/2
A
A= $class->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition60%3/5
exists $params->{$field} && ($self->$field($params->{$field}) || (return $self->pass_error))
$self->$field($params->{$field}) or return $self->pass_error
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})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # List fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 11 | foreach my $field ( qw( bcc cc references to ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 44 | ▶ | if( exists( $params->{ $field } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 11 | my $v = $params->{ $field }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 11 | ▶ | $self->$field( ref( $v ) eq 'ARRAY' ? @$v : $v ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Body convenience shorthands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 11 | ▶ | if( exists( $params->{plain} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | ▶ | if( exists( $params->{plain_opts} ) && ref( $params->{plain_opts} ) ne 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"plain_opts"} and ref $params->{"plain_opts"} ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$params->{"plain_opts"} // "undef"
$params->{"plain_opts"}
Truth table0%0/2
A
A= $params->{"plain_opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 10 | ▶ | my %opts = %{$params->{plain_opts} // {}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{"plain_opts"} // {}
MC/DC0%0/1
$params->{"plain_opts"} // {}
$params->{"plain_opts"}
Truth table50%1/2
A
A= $params->{"plain_opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 10 | ▶ | $self->plain( $params->{plain}, %opts ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 11 | ▶ | if( exists( $params->{html} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if( exists( $params->{html_opts} ) && ref( $params->{html_opts} ) ne 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params->{"html_opts"} and ref $params->{"html_opts"} ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$params->{"html_opts"} // "undef"
$params->{"html_opts"}
Truth table0%0/2
A
A= $params->{"html_opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | my %opts = %{$params->{html_opts} // {}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"html_opts"} // {}
MC/DC0%0/1
$params->{"html_opts"} // {}
$params->{"html_opts"}
Truth table0%0/2
A
A= $params->{"html_opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $self->html( $params->{html}, %opts ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # Attachments: scalar, arrayref of scalars, or arrayref of hashrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 11 | ▶ | if( exists( $params->{attach} ) && defined( $params->{attach} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"attach"} and defined $params->{"attach"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | foreach my $item ( @items ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 7 | ▶ | next unless( defined( $item ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | ▶ | $self->attach( %$item ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $params->{"url_to_inline"} and defined $params->{"url_to_inline"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | unless( ref( $params->{url_to_inline} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $params->{"html_to_inline"} and defined $params->{"html_to_inline"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | unless( ref( $params->{html_to_inline} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $params->{"related"} and defined $params->{"related"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | unless( ref( $params->{related} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # Extra arbitrary headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 11 | ▶ | if( exists( $params->{headers} ) && ref( $params->{headers} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"headers"} and ref $params->{"headers"} eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | while( my( $n, $v ) = each( %{$params->{headers}} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | ▶ | $self->header( $n, $v ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my @encoded = map { $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | $self->{_headers}->push_header( 'Cc' => join( ', ', @encoded ) ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | $self->{_headers}->date( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $name and length $name and defined $value
defined $name and length $name
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
$opts->{"charset"} // "utf-8"
$opts->{"encoding"} // "quoted-printable"
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)
Truth table50%1/2
A
A= $opts->{"charset"}
Truth table50%1/2
A
A= $opts->{"encoding"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $raw_html and length $raw_html
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | $self->{_headers}->set( 'In-Reply-To' => shift( @_ ) ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | $self->{_headers}->message_id( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
$opts->{"charset"} // "utf-8"
$opts->{"encoding"} // "quoted-printable"
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)
Truth table50%1/2
A
A= $opts->{"charset"}
Truth table50%1/2
A
A= $opts->{"encoding"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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 @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | return( $self->error( "No file handle was provided to print the mail entity." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | unless( $self->_is_glob( $fh ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | return( $self->error( "Value provided (", $self->_str_val( $fh // 'undef' ), ") is not a file handle." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fh // "undef"
MC/DC0%0/1
$fh // "undef"
$fh
Truth table0%0/2
A
A= $fh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | my $entity = $self->as_entity || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->as_entity || (return $self->pass_error)
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table0%0/2
A
A= $self->as_entity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | $entity->print( $fh ) || return( $self->pass_error( $entity->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // {}
MC/DC0%0/1
$opts->{"html_opts"} // {}
$opts->{"html_opts"}
Truth table50%1/2
A
A= $opts->{"html_opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 2 | ▶ | $self->html( $opts->{html}, %html_opts ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # Process inline parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | ▶ | if( exists( $opts->{inline} ) && defined( $opts->{inline} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts->{"inline"} and defined $opts->{"inline"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 2 | ▶ | my @items = $self->_is_array( $opts->{inline} ) ? @{$opts->{inline}} : ( $opts->{inline} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 2 | foreach my $item ( @items ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | ▶ | next unless( defined( $item ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | ▶ | unless( ref( $item ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | my @mids = ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
MC/DC0%0/1
$self->{"_headers"}->header("References") // ""
$self->{"_headers"}->header("References")
Truth table0%0/2
A
A= $self->{"_headers"}->header("References")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$self->as_entity || (return $self->pass_error)
$self->as_entity
Truth table50%1/2
A
A= $self->as_entity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $mail_from and length $mail_from
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 11 | ▶ | my $from_hdr = $self->{_headers}->header( 'From' ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_headers"}->header("From") // ""
MC/DC0%0/1
$self->{"_headers"}->header("From") // ""
$self->{"_headers"}->header("From")
Truth table50%1/2
A
A= $self->{"_headers"}->header("From")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 11 | ▶ | if( $from_hdr =~ /<([^>]+)>/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $mail_from and length $mail_from
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $username and length $username
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 2 | ▶ | unless( defined( $password ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 1 | ▶ | push( @rcpt_raw, ref( $v ) eq 'ARRAY' ? @$v : $v ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 32 | ▶ | my $hv = $self->{_headers}->header( $field ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_headers"}->header($field) // ""
MC/DC100%1/1
$self->{"_headers"}->header($field) // ""
$self->{"_headers"}->header($field)
Truth table100%2/2
A
A= $self->{"_headers"}->header($field)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 32 | ▶ | push( @rcpt_raw, $hv ) if( length( $hv ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | push( @found_angle, $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 14 | ▶ | if( @found_angle ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 10 | ▶ | push( @smtp_opts, Port => $opts->{Port} ) if( defined( $opts->{Port} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 10 | ▶ | push( @smtp_opts, Debug => $opts->{Debug} ) if( defined( $opts->{Debug} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 10 | ▶ | push( @smtp_opts, Timeout => $opts->{Timeout} ) if( defined( $opts->{Timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 10 | ▶ | if( $opts->{SSL} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | push( @smtp_opts, SSL => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | if( ref( $opts->{SSL_opts} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | my @hosts = qw( mailhost localhost ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | if( defined( $ENV{SMTPHOSTS} ) && length( $ENV{SMTPHOSTS} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ENV{"SMTPHOSTS"} and length $ENV{"SMTPHOSTS"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$opts->{"StartTLS"} and $quit
MC/DC0%0/2
$opts->{"StartTLS"} and $quit
$opts->{"StartTLS"}
$quit
Truth table33%1/3
A and B
A= $opts->{"StartTLS"}B= $quit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | my %tls_opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | if( ref( $opts->{SSL_opts} ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | %tls_opts = %{$opts->{SSL_opts}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | unless( $smtp->starttls( %tls_opts ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $username and length $username
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 1 | ▶ | if( ref( $password ) eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 1 | $password = eval{ $password->() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 1 | ▶ | if( $@ || !defined( $password ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not defined $password
MC/DC0%0/2
$@ or not defined $password
$@
not defined $password
Truth table33%1/3
A or not(B)
A= $@B= not defined $password
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | ▶ | $smtp->quit if( $quit ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | ▶ | return( $self->error( "Password callback failed: " . ( $@ // 'returned undef' ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ // "returned undef"
MC/DC0%0/1
$@ // "returned undef"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # Determine which mechanisms the server advertises | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 1 | ▶ | my $server_mechs = $smtp->supports( 'AUTH' ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$smtp->supports("AUTH") // ""
MC/DC0%0/1
$smtp->supports("AUTH") // ""
$smtp->supports("AUTH")
Truth table50%1/2
A
A= $smtp->supports("AUTH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # Build the preferred mechanism list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 1 | ▶ | my $preferred = $opts->{AuthMechanisms} // 'PLAIN LOGIN'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"AuthMechanisms"} // "PLAIN LOGIN"
MC/DC0%0/1
$opts->{"AuthMechanisms"} // "PLAIN LOGIN"
$opts->{"AuthMechanisms"}
Truth table50%1/2
A
A= $opts->{"AuthMechanisms"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 1 | ▶ | return( $self->error( "SMTP authentication failed for user '$username'" . ( length( $smtp_msg ) ? ": $smtp_msg" : '.' ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
}
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
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | $smtp->quit if( $quit ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
}
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)
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | ▶ | $smtp->quit if( $quit ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$smtp->mail($mail_from) and $smtp->to(@addr)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | && $smtp->to( @addr ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | && $smtp->data( $msg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 8 | ▶ | $smtp->quit if( $quit ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 8 | ▶ | unless( $ok ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | return( $self->error( "SMTP transaction failed." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 8 | ▶ | return( wantarray() ? @addr : \@addr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | my @encoded = map{ $self->_encode_address( $_ ) } ( ref( $_[0] ) eq 'ARRAY' ? @{$_[0]} : @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | $self->{_headers}->set( 'To' => $new_val ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 69 | ▶ | return( $self->pass_error( $self->{_headers}->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $url and length $url
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} //= {}
MC/DC0%0/1
$self->{"_hti_cache"} //= {}
$self->{"_hti_cache"}
Truth table50%1/2
A
A= $self->{"_hti_cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | return( $self->error( "Could not fetch '$url': " . ( $self->error // 'unknown error' ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->error // "unknown error"
MC/DC0%0/1
$self->error // "unknown error"
$self->error
Truth table0%0/2
A
A= $self->error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | ▶ | my $raw_html = ref( $result->{data} ) ? "${\$result->{data}}" : $result->{data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 5 | ▶ | unless( defined( $raw_html ) && length( $raw_html ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $raw_html and length $raw_html
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $opts->{"base_url"} and length $opts->{"base_url"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | length( $opts->{base_url} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 4 | ▶ | $self->_load_class( 'URI' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 4 | ▶ | $opts->{base_url} = defined( $base ) ? $base : $url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
$opts->{'Recipients'}
Truth table0%0/2
A
A= $opts->{'Recipients'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | ▶ | $recipients = [ $recipients ] unless( ref( $recipients ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ▶ | return( $gpg->encrypt( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$gpg->encrypt('entity', $self, 'recipients', $recipients) || $self->pass_error($gpg->error)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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)
$opts->{"KeyId"} // ""
$opts->{"Passphrase"} // undef
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)
Truth table0%0/2
A
A= $opts->{"KeyId"}
Truth table0%0/2
A
A= $opts->{"Passphrase"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
$opts->{'Recipients'} || (return $self->error('Recipients option is required.'))
$opts->{'Recipients'}
Truth table0%0/2
A
A= $opts->{'Recipients'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | ▶ | $recipients = [ $recipients ] unless( ref( $recipients ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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)
$opts->{"KeyId"} // ""
$opts->{"Passphrase"} // undef
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)
Truth table0%0/2
A
A= $opts->{"KeyId"}
Truth table0%0/2
A
A= $opts->{"Passphrase"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
'Mail::Make::SMIME'->new(defined $opts->{'CACert'} ? ('ca_cert', $opts->{'CACert'}) : ()) || (return $self->pass_error('Mail::Make::SMIME'->error))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
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)
Truth table0%0/2
A
A= $opts->{'RecipientCert'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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))
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'}) : ())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$opts->{'RecipientCert'} || (return $self->error('RecipientCert option is required.'))
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)
Truth table0%0/2
A
A= $opts->{'RecipientCert'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$@ or not defined $host or not length $host
$@ or not defined $host
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $addr and length $addr
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 145 | ▶ | if( $addr =~ /^("?)([^<"]+)\1\s*<([^>]+)>\s*$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$lt[5] > $gt[5] or $lt[5] == $gt[5] and $lt[7] > $gt[7]
$lt[5] == $gt[5] and $lt[7] > $gt[7]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 78 | ▶ | $diff -= 1440 if( $lt[5] < $gt[5] || ( $lt[5] == $gt[5] && $lt[7] < $gt[7] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$lt[5] < $gt[5] or $lt[5] == $gt[5] and $lt[7] < $gt[7]
$lt[5] == $gt[5] and $lt[7] < $gt[7]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 78 | ▶ | my $sign = $diff >= 0 ? '+' : '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $mime_type and $mime_type =~ m[/([a-zA-Z0-9]+)$]
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]+)$]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 22 | my $f = $self->new_file( $url ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 22 | ▶ | unless( $f->exists ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $raw and $f->error
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 0 | return( $self->error( "Could not read file '$url': " . $f->error ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 21 | ▶ | $data = ref( $raw ) ? "$raw" : $raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 21 | ▶ | $mime_type = eval{ $f->finfo->mime_type } // 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$f->finfo->mime_type
}
} // "application/octet-stream"
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
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 21 | ▶ | $mime_type = "$mime_type" if( ref( $mime_type ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $cache_dir and length $cache_dir
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $ext and length $ext
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 0 | ▶ | $cache_meta = $sidecar->load_json // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sidecar->load_json // {}
MC/DC0%0/1
$sidecar->load_json // {}
$sidecar->load_json
Truth table0%0/2
A
A= $sidecar->load_json
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | 0 | ▶ | $cache_meta //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cache_meta //= {}
MC/DC0%0/1
$cache_meta //= {}
$cache_meta
Truth table0%0/2
A
A= $cache_meta
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $cache_file and $cache_file->exists
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 0 | ▶ | if( defined( $cache_meta->{etag} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
not exists $cond_headers{"If-None-Match"} and defined $cache_meta->{"last_modified"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $resp and $resp->is_success
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | # 304 Not Modified; use the cached copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | 0 | ▶ | if( defined( $resp ) && $resp->status_code == 304 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $resp and $resp->status_code == 304 and defined $cache_file and $cache_file->exists
defined $resp and $resp->status_code == 304 and defined $cache_file
defined $resp and $resp->status_code == 304
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | 0 | ▶ | return( $self->error( "GET $url failed: " . ( defined( $resp ) ? $resp->status_line : $ua->error ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $cache_file and $cache_file->exists
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 0 | ▶ | if( defined( $cache_meta->{etag} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $cache_meta->{"etag"} and length $cache_meta->{"etag"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
not $req->header("If-None-Match") and defined $cache_meta->{"last_modified"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | 0 | ▶ | if( $resp->code == 304 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$resp->code == 304 and defined $cache_file and $cache_file->exists
$resp->code == 304 and defined $cache_file
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $cache_file and defined $data
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $resp and $resp->can("header")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $etag and length $etag
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 0 | ▶ | $cache_meta->{last_modified} = $lm if( defined( $lm ) && length( $lm ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lm and length $lm
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $dom and $dom->can("getElementsByTagName")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
not defined $list and $dom->can("error") and $dom->can("pass_error") and $dom->error
not defined $list and $dom->can("error") and $dom->can("pass_error")
not defined $list and $dom->can("error")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | 0 | ▶ | return( defined( $list ) ? [ $list->list ] : [] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition44%4/9
not scalar @list and $dom->can("error") and $dom->can("pass_error") and $dom->error
not scalar @list and $dom->can("error") and $dom->can("pass_error")
not scalar @list and $dom->can("error")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition44%4/9
scalar @list == 1 and defined $list[0] and builtin::reftype($list[0]) eq "ARRAY"
scalar @list == 1 and defined $list[0]
builtin::blessed($list[0]) and $list[0]->can("list")
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"
Truth table0%0/3
A and B
A= builtin::blessed($list[0])B= $list[0]->can("list")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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))
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$opts->{"embed_css"} // 0
$opts->{"embed_css"}
Truth table100%2/2
A
A= $opts->{"embed_css"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} //= {}
MC/DC100%1/1
$self->{"_hti_cache"} //= {}
$self->{"_hti_cache"}
Truth table100%2/2
A
A= $self->{"_hti_cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | 17 | ▶ | next unless( length( $src ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 17 | ▶ | my $abs = $self->_hti_resolve_url( $src, $base_url ) || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_hti_resolve_url($src, $base_url) || (next)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 18 | ▶ | next unless( length( $bg ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | 1 | ▶ | my $abs = $self->_hti_resolve_url( $bg, $base_url ) || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_hti_resolve_url($bg, $base_url) || (next)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 1 | ▶ | my $href = $self->_hti_attr( $node, 'href' ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_hti_attr($node, "href") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | 1 | ▶ | next unless( $rel eq 'stylesheet' && length( $href ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rel eq "stylesheet" and length $href
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 1 | ▶ | my $abs = $self->_hti_resolve_url( $href, $base_url ) || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_hti_resolve_url($href, $base_url) || (next)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$self->error // "unknown error"
MC/DC0%0/1
$self->error // "unknown error"
$self->error
Truth table0%0/2
A
A= $self->error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | 0 | ▶ | my $data = ref( $result->{data} ) ? "${\$result->{data}}" : $result->{data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | 16 | ▶ | my $mime_type = $result->{mime_type} // 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"mime_type"} // "application/octet-stream"
MC/DC0%0/1
$result->{"mime_type"} // "application/octet-stream"
$result->{"mime_type"}
Truth table50%1/2
A
A= $result->{"mime_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 18 | ▶ | $html_opts{encoding} = $opts->{encoding} if( exists( $opts->{encoding} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | 18 | ▶ | $self->html( $modified_html, %html_opts ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $url and length $url
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | # Already absolute (http://, https://, file://) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | 19 | ▶ | if( $url =~ m{^(?:https?|file)://}i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 2 | return( $url ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | 17 | ▶ | unless( defined( $base_url ) && length( $base_url ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $base_url and length $base_url
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$@ or not defined $abs
MC/DC0%0/2
$@ or not defined $abs
$@
not defined $abs
Truth table33%1/3
A or not(B)
A= $@B= not defined $abs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | 0 | return( $dom->as_string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | # HTML::TreeBuilder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | 18 | ▶ | if( $dom->can( 'as_HTML' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||