| 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::Part;{ | ||||||||||||||||||||
| 13 | 37 | our $VERSION = '4.05'; | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 37 | ▶ | use parent 'Mail::Message'; | ||||||||||||||||||
|
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/ ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 37 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub init($) | ||||||||||||||||||||
| 28 | 75 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||
| 29 | 75 | ▶ | $args->{head} ||= Mail::Message::Head::Complete->new; | ||||||||||||||||||
|
Condition66%2/3
$args->{"head"} ||= "Mail::Message::Head::Complete"->new
MC/DC0%0/2
$args->{"head"} ||= "Mail::Message::Head::Complete"->new
$args->{"head"}
"Mail::Message::Head::Complete"->new
Truth table66%2/3
A ||= B
A= $args->{"head"}B= "Mail::Message::Head::Complete"->new
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 75 | $self->SUPER::init($args); | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | exists $args->{container} | ||||||||||||||||||||
| 34 | 75 | ▶ | or error __x"no container specified for part."; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | weaken($self->{MMP_container}) | ||||||||||||||||||||
| 37 | 75 | ▶ | if $self->{MMP_container} = $args->{container}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 75 | $self; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | sub coerce($@) | ||||||||||||||||||||
| 44 | 65 | ▶ | { my ($class, $thing, $container) = (shift, shift, shift); | ||||||||||||||||||
|
Subroutine
coerce: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 45 | 65 | ▶ | if($thing->isa($class)) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 34 | { $thing->container($container); | |||||||||||||||||||
| 47 | 34 | return $thing; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 31 | ▶ | return $class->buildFromBody($thing, $container, @_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | if $thing->isa('Mail::Message::Body'); | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | # Although cloning is a Bad Thing(tm), we must avoid modifying | ||||||||||||||||||||
| 54 | # header fields of messages which reside in a folder. | ||||||||||||||||||||
| 55 | 13 | ▶ | my $message = $thing->isa('Mail::Box::Message') ? $thing->clone : $thing; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 13 | my $part = $class->SUPER::coerce($message); | |||||||||||||||||||
| 58 | 13 | $part->container($container); | |||||||||||||||||||
| 59 | 13 | $part; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | sub buildFromBody($$;@) | ||||||||||||||||||||
| 64 | 18 | ▶ | { my ($class, $body, $container) = (shift, shift, shift); | ||||||||||||||||||
|
Subroutine
buildFromBody: called CC=3 SCAR=13.6
Pod
documented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 18 | my $head = Mail::Message::Head::Complete->new; | |||||||||||||||||||
| 67 | 18 | ▶ | while(@_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | ▶ | { if(ref $_[0]) {$head->add(shift)} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | else {$head->add(shift, shift)} | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 18 | my $part = $class->new(head => $head, container => $container); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 18 | $part->body($body); | |||||||||||||||||||
| 75 | 18 | $part; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | sub container(;$) | ||||||||||||||||||||
| 79 | 83 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
container: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 80 | 83 | ▶ | @_ or return $self->{MMP_container}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 70 | $self->{MMP_container} = shift; | |||||||||||||||||||
| 83 | 70 | weaken($self->{MMP_container}); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub toplevel() | ||||||||||||||||||||
| 87 | 0 | ▶ | { my $body = shift->container or return; | ||||||||||||||||||
|
Subroutine
toplevel: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | ▶ | my $msg = $body->message or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 0 | $msg->toplevel; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | sub isPart() { 1 } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | sub partNumber() | ||||||||||||||||||||
| 95 | 11 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
partNumber: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 96 | 11 | ▶ | my $body = $self->container or panic 'no container'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 11 | $body->partNumberOf($self); | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub readFromParser($;$) | ||||||||||||||||||||
| 101 | 29 | ▶ | { my ($self, $parser, $bodytype) = @_; | ||||||||||||||||||
|
Subroutine
readFromParser: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | my $head = $self->readHead($parser) // | ||||||||||||||||||||
| 104 | 29 | ▶ | Mail::Message::Head::Complete->new(message => $self, field_type => $self->{MM_field_type}); | ||||||||||||||||||
|
Condition33%1/3
$self->readHead($parser) // "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
MC/DC0%0/2
$self->readHead($parser) // "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
$self->readHead($parser)
"Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
Truth table33%1/3
A // B
A= $self->readHead($parser)B= "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 29 | ▶ | my $body = $self->readBody($parser, $head, $bodytype) // | ||||||||||||||||||
|
Condition33%1/3
$self->readBody($parser, $head, $bodytype) // "Mail::Message::Body::Lines"->new("data", [])
MC/DC0%0/2
$self->readBody($parser, $head, $bodytype) // "Mail::Message::Body::Lines"->new("data", [])
$self->readBody($parser, $head, $bodytype)
"Mail::Message::Body::Lines"->new("data", [])
Truth table33%1/3
A // B
A= $self->readBody($parser, $head, $bodytype)B= "Mail::Message::Body::Lines"->new("data", [])
| |||||||||||||||||||||
| 107 | Mail::Message::Body::Lines->new(data => []); | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 29 | $self->head($head); | |||||||||||||||||||
| 110 | 29 | $self->storeBody($body->contentInfoFrom($head)); | |||||||||||||||||||
| 111 | 29 | $self; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | #-------------------- | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | sub printEscapedFrom($) | ||||||||||||||||||||
| 117 | 0 | ▶ | { my ($self, $out) = @_; | ||||||||||||||||||
|
Subroutine
printEscapedFrom: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 118 | 0 | $self->head->print($out); | |||||||||||||||||||
| 119 | 0 | $self->body->printEscapedFrom($out); | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | #-------------------- | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | sub destruct() | ||||||||||||||||||||
| 125 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
destruct: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 126 | 0 | error __x"you cannot destruct message parts, only whole messages."; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 37 | 1; | |||||||||||||||||||