| 1 | # This code is part of Perl distribution Mail-Message version 4.05. | ||||||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | package Mail::Message::Body::Multipart;{ | ||||||||||||||||||||||||||||||||
| 13 | 37 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 37 | ▶ | use parent 'Mail::Message::Body'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 37 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error panic warning/ ]; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 37 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 37 | ▶ | use Mail::Message::Body::Lines (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 37 | ▶ | use Mail::Message::Part (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 37 | ▶ | use Mail::Box::FastScalar (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | #-------------------- | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | sub init($) | ||||||||||||||||||||||||||||||||
| 32 | 49 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=19 SCAR=30.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 33 | 49 | my $based = $args->{based_on}; | |||||||||||||||||||||||||||||||
| 34 | 49 | ▶ | $args->{mime_type} ||= defined $based ? $based->type : 'multipart/mixed'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args->{"mime_type"} ||= defined $based ? $based->type : "multipart/mixed"
MC/DC0%0/2
$args->{"mime_type"} ||= defined $based ? $based->type : "multipart/mixed"
$args->{"mime_type"}
defined $based ? $based->type : "multipart/mixed"
Truth table66%2/3
A ||= B
A= $args->{"mime_type"}B= defined $based ? $based->type : "multipart/mixed"
| |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 49 | $self->SUPER::init($args); | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 49 | my @parts; | |||||||||||||||||||||||||||||||
| 39 | 49 | ▶ | if($args->{parts}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 31 | { foreach my $raw (@{$args->{parts}}) | |||||||||||||||||||||||||||||||
| 41 | 54 | ▶ | { defined $raw or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 54 | my $cooked = Mail::Message::Part->coerce($raw, $self); | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 54 | ▶ | defined $cooked | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | or error __x"data not convertible to a message (type is {class})", class => ref $raw; | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 54 | push @parts, $cooked; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 49 | my $preamble = $args->{preamble}; | |||||||||||||||||||||||||||||||
| 52 | 49 | ▶ | $preamble = Mail::Message::Body->new(data => $preamble) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $preamble and not builtin::blessed($preamble)
MC/DC0%0/2
defined $preamble and not builtin::blessed($preamble)
defined $preamble
not builtin::blessed($preamble)
Truth table66%2/3
A and not(B)
A= defined $preambleB= not builtin::blessed($preamble)
| |||||||||||||||||||||||||||||||||
| 53 | if defined $preamble && ! blessed $preamble; | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 49 | my $epilogue = $args->{epilogue}; | |||||||||||||||||||||||||||||||
| 56 | 49 | ▶ | $epilogue = Mail::Message::Body->new(data => $epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $epilogue and not builtin::blessed($epilogue)
MC/DC0%0/2
defined $epilogue and not builtin::blessed($epilogue)
defined $epilogue
not builtin::blessed($epilogue)
Truth table66%2/3
A and not(B)
A= defined $epilogueB= not builtin::blessed($epilogue)
| |||||||||||||||||||||||||||||||||
| 57 | if defined $epilogue && ! blessed $epilogue; | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 49 | ▶ | if($based) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 23 | ▶ | { $self->boundary($args->{boundary} || $based->boundary); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'boundary'} || $based->boundary
MC/DC0%0/2
$args->{'boundary'} || $based->boundary
$args->{'boundary'}
$based->boundary
Truth table33%1/3
A || B
A= $args->{'boundary'}B= $based->boundary
| |||||||||||||||||||||||||||||||||
| 61 | 23 | ▶ | $self->{MMBM_preamble} = $preamble // $based->preamble; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$preamble // $based->preamble
MC/DC50%1/2
$preamble // $based->preamble
$preamble
$based->preamble
Truth table66%2/3
A // B
A= $preambleB= $based->preamble
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | $self->{MMBM_parts} | ||||||||||||||||||||||||||||||||
| 64 | = @parts ? \@parts | ||||||||||||||||||||||||||||||||
| 65 | 23 | ▶ | : !$args->{parts} && $based->isMultipart ? [ $based->parts('ACTIVE') ] | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not $args->{"parts"} and $based->isMultipart
MC/DC50%1/2
not $args->{"parts"} and $based->isMultipart
not $args->{"parts"}
$based->isMultipart
Truth table66%2/3
not(A) and B
A= not $args->{"parts"}B= $based->isMultipart
| |||||||||||||||||||||||||||||||||
| 66 | : []; | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 23 | ▶ | $self->{MMBM_epilogue} = $epilogue // $based->epilogue; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$epilogue // $based->epilogue
MC/DC50%1/2
$epilogue // $based->epilogue
$epilogue
$based->epilogue
Truth table66%2/3
A // B
A= $epilogueB= $based->epilogue
| |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | else | ||||||||||||||||||||||||||||||||
| 71 | 26 | ▶ | { $self->boundary($args->{boundary} ||$self->type->attribute('boundary')); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{'boundary'} || $self->type->attribute('boundary')
MC/DC50%1/2
$args->{'boundary'} || $self->type->attribute('boundary')
$args->{'boundary'}
$self->type->attribute('boundary')
Truth table66%2/3
A || B
A= $args->{'boundary'}B= $self->type->attribute('boundary')
| |||||||||||||||||||||||||||||||||
| 72 | 26 | $self->{MMBM_preamble} = $preamble; | |||||||||||||||||||||||||||||||
| 73 | 26 | $self->{MMBM_parts} = \@parts; | |||||||||||||||||||||||||||||||
| 74 | 26 | $self->{MMBM_epilogue} = $epilogue; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 49 | $self; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | sub isMultipart() { 1 } | ||||||||||||||||||||||||||||||||
| 81 | sub isBinary() { 0 } # A multipart body is never binary itself. The parts may be. | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | sub clone() | ||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 85 | 3 | my $preamble = $self->preamble; | |||||||||||||||||||||||||||||||
| 86 | 3 | my $epilogue = $self->epilogue; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | my $body = (ref $self)->new( | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 89 | based_on => $self, | ||||||||||||||||||||||||||||||||
| 90 | preamble => ($preamble ? $preamble->clone : undef), | ||||||||||||||||||||||||||||||||
| 91 | epilogue => ($epilogue ? $epilogue->clone : undef), | ||||||||||||||||||||||||||||||||
| 92 | parts => [ map $_->clone, $self->parts('ACTIVE') ], | ||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | sub nrLines() | ||||||||||||||||||||||||||||||||
| 98 | 22 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
nrLines: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 99 | 22 | my $nr = 1; # trailing part-sep | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 22 | ▶ | if(my $preamble = $self->preamble) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 102 | 2 | { $nr += $preamble->nrLines; | |||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | $nr++ if $preamble->endsOnNewline; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 22 | foreach my $part ($self->parts('ACTIVE')) | |||||||||||||||||||||||||||||||
| 107 | 33 | { $nr += 1 + $part->nrLines; | |||||||||||||||||||||||||||||||
| 108 | 33 | ▶ | $nr++ if $part->body->endsOnNewline; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 22 | ▶ | if(my $epilogue = $self->epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | { # nrLines should match mbox counts, which is a bit | ||||||||||||||||||||||||||||||||
| 113 | # unclear w.r.t. the \n after a multipart separator | ||||||||||||||||||||||||||||||||
| 114 | # line. | ||||||||||||||||||||||||||||||||
| 115 | 2 | $nr += $epilogue->nrLines -1; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 22 | $nr; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | sub size() | ||||||||||||||||||||||||||||||||
| 122 | 26 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 123 | 26 | my $bbytes = length($self->boundary) +4; # \n--$b\n | |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 26 | my $bytes = $bbytes +2; # last boundary, \n--$b--\n | |||||||||||||||||||||||||||||||
| 126 | 26 | ▶ | if(my $preamble = $self->preamble) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 127 | 5 | { $bytes += $preamble->size } | |||||||||||||||||||||||||||||||
| 128 | 21 | else { $bytes -= 1 } # no leading \n | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 26 | $bytes += $bbytes + $_->size foreach $self->parts('ACTIVE'); | |||||||||||||||||||||||||||||||
| 131 | 26 | ▶ | if(my $epilogue = $self->epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 6 | { $bytes += $epilogue->size; | |||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | 26 | $bytes; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | sub string() { join '', $_[0]->lines } | ||||||||||||||||||||||||||||||
|
Subroutine
string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | sub lines() | ||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
lines: called CC=9 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 141 | 4 | my $boundary = $self->boundary; | |||||||||||||||||||||||||||||||
| 142 | 4 | my $preamble = $self->preamble; | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 4 | my @lines; | |||||||||||||||||||||||||||||||
| 145 | 4 | ▶ | push @lines, $preamble->lines if $preamble; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 4 | foreach my $part ($self->parts('ACTIVE')) | |||||||||||||||||||||||||||||||
| 148 | { # boundaries start with \n | ||||||||||||||||||||||||||||||||
| 149 | 8 | ▶ | if(!@lines) { ; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 150 | 4 | elsif($lines[-1] =~ m/\n$/) { push @lines, "\n" } | |||||||||||||||||||||||||||||||
| 151 | 0 | else { $lines[-1] .= "\n" } | |||||||||||||||||||||||||||||||
| 152 | 8 | push @lines, "--$boundary\n", $part->lines; | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | if(!@lines) { ; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 156 | 4 | elsif($lines[-1] =~ m/\n$/) { push @lines, "\n" } | |||||||||||||||||||||||||||||||
| 157 | 0 | else { $lines[-1] .= "\n" } | |||||||||||||||||||||||||||||||
| 158 | 4 | push @lines, "--$boundary--"; | |||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | if(my $epilogue = $self->epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | 0 | { $lines[-1] .= "\n"; | |||||||||||||||||||||||||||||||
| 162 | 0 | push @lines, $epilogue->lines; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 4 | ▶ | wantarray ? @lines : \@lines; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | sub file() # It may be possible to speed-improve the next code, which first | ||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | { my $self = shift; # produces a full print of the message in memory... | ||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 170 | 0 | my $dump = Mail::Box::FastScalar->new; | |||||||||||||||||||||||||||||||
| 171 | 0 | $self->print($dump); | |||||||||||||||||||||||||||||||
| 172 | 0 | $dump->seek(0,0); | |||||||||||||||||||||||||||||||
| 173 | 0 | $dump; | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | sub print(;$) | ||||||||||||||||||||||||||||||||
| 177 | 9 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | my $out = shift || select; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table33%1/3
A || B
A= shift()B= select()
| |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 9 | my $boundary = $self->boundary; | |||||||||||||||||||||||||||||||
| 181 | 9 | my $count = 0; | |||||||||||||||||||||||||||||||
| 182 | 9 | ▶ | if(my $preamble = $self->preamble) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 183 | 3 | { $preamble->print($out); | |||||||||||||||||||||||||||||||
| 184 | 3 | $count++; | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 9 | foreach my $part ($self->parts('ACTIVE')) | |||||||||||||||||||||||||||||||
| 188 | 15 | ▶ | { $out->print("\n") if $count++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 189 | 15 | $out->print("--$boundary\n"); | |||||||||||||||||||||||||||||||
| 190 | 15 | $part->print($out); | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | 9 | ▶ | $out->print("\n") if $count++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 193 | 9 | $out->print("--$boundary--"); | |||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 9 | ▶ | if(my $epilogue = $self->epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 196 | 3 | { $out->print("\n"); | |||||||||||||||||||||||||||||||
| 197 | 3 | $epilogue->print($out); | |||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 9 | $self; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | sub endsOnNewline() | ||||||||||||||||||||||||||||||||
| 204 | 9 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
endsOnNewline: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 205 | 9 | ▶ | my $epilogue = $self->epilogue or return 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | 2 | $epilogue =~ m/[\r\n]$/; | |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | sub foreachLine($) | ||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | { my ($self, $code) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
foreachLine: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 212 | 0 | error __x"you cannot use foreachLine on a multipart."; | |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | sub check() | ||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $self->foreachComponent( sub { $_[1]->check } ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | sub encode(@) | ||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | $self->foreachComponent( sub { $_[1]->encode(%args) } ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | sub encoded() | ||||||||||||||||||||||||||||||||
| 226 | 20 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
encoded: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 227 | 20 | ▶ | $self->foreachComponent( sub { $_[1]->encoded } ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | sub read($$$$) | ||||||||||||||||||||||||||||||||
| 231 | 16 | ▶ | { my ($self, $parser, $head, $bodytype) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=16 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 232 | 16 | my $boundary = $self->boundary; | |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 16 | $parser->pushSeparator("--$boundary"); | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 16 | my $te; | |||||||||||||||||||||||||||||||
| 237 | 16 | ▶ | $te = lc $1 if +($head->get('Content-Transfer-Encoding') || '') =~ m/(\w+)/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$head->get('Content-Transfer-Encoding') || ''
MC/DC100%1/1
$head->get('Content-Transfer-Encoding') || ''
$head->get('Content-Transfer-Encoding')
Truth table100%2/2
A
A= $head->get('Content-Transfer-Encoding')
| |||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | 16 | my @sloppyopts = (mime_type => 'text/plain', transfer_encoding => $te); | |||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | # Get preamble. | ||||||||||||||||||||||||||||||||
| 242 | 16 | my $headtype = ref $head; | |||||||||||||||||||||||||||||||
| 243 | 16 | my $begin = $parser->filePosition; | |||||||||||||||||||||||||||||||
| 244 | 16 | my $preamble = Mail::Message::Body::Lines->new(@sloppyopts)->read($parser, $head); | |||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 16 | ▶ | $preamble->nrLines or undef $preamble; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 247 | 16 | ▶ | $self->{MMBM_preamble} = $preamble if defined $preamble; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | # Get the parts. | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 16 | my ($has_epilogue, @parts); | |||||||||||||||||||||||||||||||
| 252 | 16 | ▶ | while(my $sep = $parser->readSeparator) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | 44 | ▶ | { if($sep =~ m/^--\Q$boundary\E--[ \t]*\n?/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 254 | { # Per RFC 2046, a CRLF after the close-delimiter marks the presence | ||||||||||||||||||||||||||||||||
| 255 | # of an epilogue. Preserve the epilogue, even if empty, so that the | ||||||||||||||||||||||||||||||||
| 256 | # printed multipart body will also have the CRLF. | ||||||||||||||||||||||||||||||||
| 257 | # This, however, is complicated w.r.t. mbox folders. | ||||||||||||||||||||||||||||||||
| 258 | 16 | $has_epilogue = $sep =~ /\n/; | |||||||||||||||||||||||||||||||
| 259 | 16 | last; | |||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 28 | my $part = Mail::Message::Part->new(container => $self); | |||||||||||||||||||||||||||||||
| 263 | 28 | ▶ | $part->readFromParser($parser, $bodytype) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | or last; | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | 28 | ▶ | push @parts, $part if $part->head->names || $part->body->size; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$part->head->names or $part->body->size
MC/DC0%0/2
$part->head->names or $part->body->size
$part->head->names
$part->body->size
Truth table33%1/3
A or B
A= $part->head->namesB= $part->body->size
| |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | 16 | $self->{MMBM_parts} = \@parts; | |||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | # Get epilogue | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | 16 | $parser->popSeparator; | |||||||||||||||||||||||||||||||
| 273 | 16 | my $epilogue = Mail::Message::Body::Lines->new(@sloppyopts) | |||||||||||||||||||||||||||||||
| 274 | ->read($parser, $head); | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | 16 | ▶ | my $end | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 277 | = defined $epilogue ? ($epilogue->fileLocation)[1] | ||||||||||||||||||||||||||||||||
| 278 | : @parts ? ($parts[-1]->body->fileLocation)[1] | ||||||||||||||||||||||||||||||||
| 279 | : defined $preamble ? ($preamble->fileLocation)[1] | ||||||||||||||||||||||||||||||||
| 280 | : $begin; | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | 16 | $self->fileLocation($begin, $end); | |||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 16 | ▶ | $has_epilogue || $epilogue->nrLines | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$has_epilogue or $epilogue->nrLines
MC/DC50%1/2
$has_epilogue or $epilogue->nrLines
$has_epilogue
$epilogue->nrLines
Truth table66%2/3
A or B
A= $has_epilogueB= $epilogue->nrLines
| |||||||||||||||||||||||||||||||||
| 285 | or undef $epilogue; | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 16 | ▶ | $self->{MMBM_epilogue} = $epilogue | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 288 | if defined $epilogue; | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | 16 | $self; | |||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | #-------------------- | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | sub foreachComponent($) | ||||||||||||||||||||||||||||||||
| 296 | 20 | ▶ | { my ($self, $code) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
foreachComponent: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 297 | 20 | my $changes = 0; | |||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | 20 | my $new_preamble; | |||||||||||||||||||||||||||||||
| 300 | 20 | ▶ | if(my $preamble = $self->preamble) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 301 | 2 | { $new_preamble = $code->($self, $preamble); | |||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | $changes++ unless $preamble == $new_preamble; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | 20 | my $new_epilogue; | |||||||||||||||||||||||||||||||
| 306 | 20 | ▶ | if(my $epilogue = $self->epilogue) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 307 | 2 | { $new_epilogue = $code->($self, $epilogue); | |||||||||||||||||||||||||||||||
| 308 | 2 | ▶ | $changes++ unless $epilogue == $new_epilogue; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 20 | my @new_bodies; | |||||||||||||||||||||||||||||||
| 312 | 20 | foreach my $part ($self->parts('ACTIVE')) | |||||||||||||||||||||||||||||||
| 313 | 32 | { my $part_body = $part->body; | |||||||||||||||||||||||||||||||
| 314 | 32 | my $new_body = $code->($self, $part_body); | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 32 | ▶ | $changes++ if $new_body != $part_body; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 317 | 32 | push @new_bodies, [$part, $new_body]; | |||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 20 | ▶ | $changes or return $self; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 9 | my @new_parts; | |||||||||||||||||||||||||||||||
| 323 | 9 | foreach (@new_bodies) | |||||||||||||||||||||||||||||||
| 324 | 19 | { my ($part, $body) = @$_; | |||||||||||||||||||||||||||||||
| 325 | 19 | my $new_part = Mail::Message::Part->new(head => $part->head->clone, container => undef); | |||||||||||||||||||||||||||||||
| 326 | 19 | $new_part->body($body); | |||||||||||||||||||||||||||||||
| 327 | 19 | push @new_parts, $new_part; | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 9 | my $constructed = (ref $self)->new( | |||||||||||||||||||||||||||||||
| 331 | preamble => $new_preamble, | ||||||||||||||||||||||||||||||||
| 332 | parts => \@new_parts, | ||||||||||||||||||||||||||||||||
| 333 | epilogue => $new_epilogue, | ||||||||||||||||||||||||||||||||
| 334 | based_on => $self, | ||||||||||||||||||||||||||||||||
| 335 | ); | ||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | $_->container($constructed) | ||||||||||||||||||||||||||||||||
| 338 | 9 | for @new_parts; | |||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | 9 | $constructed; | |||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | sub attach(@) | ||||||||||||||||||||||||||||||||
| 345 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
attach: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 346 | 2 | (ref $self)->new(based_on => $self, parts => [ $self->parts, @_ ]); | |||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | sub stripSignature(@) | ||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
stripSignature: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 1 | my @allparts = $self->parts; | |||||||||||||||||||||||||||||||
| 354 | 1 | my @parts = grep ! $_->body->mimeType->isSignature, @allparts; | |||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | @allparts == @parts ? $self : (ref $self)->new(based_on => $self, parts => \@parts); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | #-------------------- | ||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||
| 361 | 108 | ▶ | sub preamble() { $_[0]->{MMBM_preamble} } | ||||||||||||||||||||||||||||||
|
Subroutine
preamble: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||
| 364 | 119 | ▶ | sub epilogue() { $_[0]->{MMBM_epilogue} } | ||||||||||||||||||||||||||||||
|
Subroutine
epilogue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||
| 367 | sub parts(;$) | ||||||||||||||||||||||||||||||||
| 368 | 161 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
parts: called CC=7 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 369 | 161 | ▶ | return @{$self->{MMBM_parts}} unless @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | 93 | my $what = shift; | |||||||||||||||||||||||||||||||
| 372 | 93 | my @parts = @{$self->{MMBM_parts}}; | |||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | 93 | ▶ | $what eq 'RECURSE' ? (map $_->parts('RECURSE'), @parts) | ||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||
| 375 | : $what eq 'ALL' ? @parts | ||||||||||||||||||||||||||||||||
| 376 | : $what eq 'DELETED' ? (grep $_->isDeleted, @parts) | ||||||||||||||||||||||||||||||||
| 377 | : $what eq 'ACTIVE' ? (grep !$_->isDeleted, @parts) | ||||||||||||||||||||||||||||||||
| 378 | : ref $what eq 'CODE'? (grep $what->($_), @parts) | ||||||||||||||||||||||||||||||||
| 379 | : error __x"unknown criterium {what} to select parts.", what => $what; | ||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 13 | ▶ | sub part($) { $_[0]->{MMBM_parts}[$_[1]] } | ||||||||||||||||||||||||||||||
|
Subroutine
part: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | sub partNumberOf($) | ||||||||||||||||||||||||||||||||
| 386 | 8 | ▶ | { my ($self, $part) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
partNumberOf: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 387 | 8 | ▶ | my $msg = $self->message or panic "multipart is not connected."; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 8 | ▶ | my $base = $msg->isa('Mail::Message::Part') ? $msg->partNumber.'.' : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | 8 | my @parts = $self->parts('ACTIVE'); | |||||||||||||||||||||||||||||||
| 392 | 8 | foreach my $partnr (0..@parts) | |||||||||||||||||||||||||||||||
| 393 | 15 | ▶ | { return $base.($partnr+1) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 394 | if $parts[$partnr] == $part; | ||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | 0 | panic "multipart is not found or not active"; | |||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | sub boundary(;$) | ||||||||||||||||||||||||||||||||
| 401 | 130 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
boundary: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 402 | 130 | my $mime = $self->type; | |||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||
| 404 | 130 | ▶ | unless(@_) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 405 | 80 | { my $boundary = $mime->attribute('boundary'); | |||||||||||||||||||||||||||||||
| 406 | 80 | ▶ | return $boundary if defined $boundary; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||
| 409 | 50 | ▶ | my $boundary = $_[0] // "boundary-".int rand(1000000); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0] // 'boundary-' . int(rand 1000000)
MC/DC100%1/1
$_[0] // 'boundary-' . int(rand 1000000)
$_[0]
Truth table100%2/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||
| 410 | 50 | $self->type->attribute(boundary => $boundary); | |||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub toplevel() { my $msg = $_[0]->message; $msg ? $msg->toplevel : undef} | ||||||||||||||||||||||||||||||
|
Subroutine
toplevel: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | 37 | 1; | |||||||||||||||||||||||||||||||