| 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::Head;{ | ||||||||||||||||||
| 13 | 40 | our $VERSION = '4.05'; | |||||||||||||||||
| 14 | } | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 40 | ▶ | use parent 'Mail::Reporter'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | 40 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 19 | 40 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | 40 | ▶ | use Log::Report 'mail-message', import => [ qw/mistake/ ]; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 40 | ▶ | use Mail::Message::Head::Complete; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 24 | 40 | ▶ | use Mail::Message::Field::Fast; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 40 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | #-------------------- | ||||||||||||||||||
| 29 | |||||||||||||||||||
| 30 | use overload | ||||||||||||||||||
| 31 | 40 | ▶ | qq("") => 'string_unless_carp', | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 32 | 40 | bool => 'isEmpty'; | |||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | # To satisfy overload in static resolving. | ||||||||||||||||||
| 35 | 0 | ▶ | sub toString() { $_[0]->load->toString } | ||||||||||||||||
|
Subroutine
toString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 36 | 0 | ▶ | sub string() { $_[0]->load->string } | ||||||||||||||||
|
Subroutine
string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | sub string_unless_carp() | ||||||||||||||||||
| 39 | 0 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
string_unless_carp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 40 | 0 | ▶ | (caller)[0] eq 'Carp' or return $self->toString; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | 0 | my $class = ref $self =~ s/^Mail::Message/MM/r; | |||||||||||||||||
| 43 | 0 | "$class object"; | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | #-------------------- | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | sub new(@) | ||||||||||||||||||
| 49 | 239 | ▶ | { my $class = shift; | ||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||
| 50 | 239 | ▶ | $class eq __PACKAGE__ ? Mail::Message::Head::Complete->new(@_) : $class->SUPER::new(@_); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 51 | } | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | sub init($) | ||||||||||||||||||
| 54 | 239 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||
| 55 | 239 | $self->SUPER::init($args); | |||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 239 | ▶ | $self->message($args->{message}) if defined $args->{message}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 58 | 239 | ▶ | $self->{MMH_field_type} = $args->{field_type} if $args->{field_type}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 59 | 239 | $self->{MMH_fields} = {}; | |||||||||||||||||
| 60 | 239 | $self->{MMH_order} = []; | |||||||||||||||||
| 61 | 239 | ▶ | $self->{MMH_modified} = $args->{modified} || 0; | ||||||||||||||||
|
Condition50%1/2
$args->{'modified'} || 0
MC/DC0%0/1
$args->{'modified'} || 0
$args->{'modified'}
Truth table50%1/2
A
A= $args->{'modified'}
| |||||||||||||||||||
| 62 | 239 | $self; | |||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | sub build(@) | ||||||||||||||||||
| 67 | 3 | ▶ | { shift; | ||||||||||||||||
|
Subroutine
build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 68 | 3 | Mail::Message::Head::Complete->build(@_); | |||||||||||||||||
| 69 | } | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | #-------------------- | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | 0 | ▶ | sub isDelayed { 1 } | ||||||||||||||||
|
Subroutine
isDelayed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | sub modified(;$) | ||||||||||||||||||
| 77 | 69 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
modified: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||
| 78 | 69 | ▶ | return $self->isModified unless @_; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 79 | 69 | $self->{MMH_modified} = shift; | |||||||||||||||||
| 80 | } | ||||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | 22 | ▶ | sub isModified() { $_[0]->{MMH_modified} } | ||||||||||||||||
|
Subroutine
isModified: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | 226 | ▶ | sub isEmpty { scalar keys %{ $_[0]->{MMH_fields}} } | ||||||||||||||||
|
Subroutine
isEmpty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | sub message(;$) | ||||||||||||||||||
| 90 | 278 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||
| 91 | 278 | ▶ | if(@_) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 92 | 278 | { $self->{MMH_message} = shift; | |||||||||||||||||
| 93 | 278 | weaken($self->{MMH_message}); | |||||||||||||||||
| 94 | } | ||||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | 278 | $self->{MMH_message}; | |||||||||||||||||
| 97 | } | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | |||||||||||||||||||
| 100 | 328 | ▶ | sub orderedFields() { grep defined, @{ $_[0]->{MMH_order}} } | ||||||||||||||||
|
Subroutine
orderedFields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | 34 | ▶ | sub knownNames() { keys %{ $_[0]->{MMH_fields}} } | ||||||||||||||||
|
Subroutine
knownNames: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 104 | |||||||||||||||||||
| 105 | #-------------------- | ||||||||||||||||||
| 106 | |||||||||||||||||||
| 107 | sub get($;$) | ||||||||||||||||||
| 108 | 2773 | ▶ | { my $known = shift->{MMH_fields}; | ||||||||||||||||
|
Subroutine
get: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||
| 109 | 2773 | my $value = $known->{lc(shift)}; | |||||||||||||||||
| 110 | 2773 | my $index = shift; | |||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | 2773 | ▶ | if(defined $index) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 113 | 311 | ▶ | { return ! defined $value ? undef | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 114 | : ref $value eq 'ARRAY' ? $value->[$index] | ||||||||||||||||||
| 115 | : $index == 0 ? $value | ||||||||||||||||||
| 116 | : undef; | ||||||||||||||||||
| 117 | } | ||||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | 2462 | ▶ | if(wantarray) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 120 | 629 | ▶ | { return ! defined $value ? () | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 121 | : ref $value eq 'ARRAY' ? @$value | ||||||||||||||||||
| 122 | : ($value); | ||||||||||||||||||
| 123 | } | ||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | 1833 | ▶ | ! defined $value ? undef | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 126 | : ref $value eq 'ARRAY' ? $value->[-1] | ||||||||||||||||||
| 127 | : $value; | ||||||||||||||||||
| 128 | } | ||||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | 0 | ▶ | sub get_all(@) { my @all = shift->get(@_) } # compatibility, force list | ||||||||||||||||
|
Subroutine
get_all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 131 | 0 | ▶ | sub setField($$) {shift->add(@_)} # compatibility | ||||||||||||||||
|
Subroutine
setField: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | |||||||||||||||||||
| 134 | sub study($;$) | ||||||||||||||||||
| 135 | 2 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
study: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||
| 136 | 2 | ▶ | return map $_->study, $self->get(@_) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 137 | if wantarray; | ||||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | 1 | my $got = $self->get(@_); | |||||||||||||||||
| 140 | 1 | ▶ | defined $got ? $got->study : undef; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 141 | } | ||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | #-------------------- | ||||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | sub isMultipart() | ||||||||||||||||||
| 147 | 132 | ▶ | { my $type = $_[0]->get('Content-Type', 0); | ||||||||||||||||
|
Subroutine
isMultipart: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||
| 148 | 132 | ▶ | $type && scalar $type->body =~ m[^multipart/]i; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 149 | } | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | #-------------------- | ||||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | sub read($) | ||||||||||||||||||
| 154 | 74 | ▶ | { my ($self, $parser) = @_; | ||||||||||||||||
|
Subroutine
read: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||
| 155 | |||||||||||||||||||
| 156 | 74 | my @fields = $parser->readHeader; | |||||||||||||||||
| 157 | 74 | @$self{ qw/MMH_begin MMH_end/ } = (shift @fields, shift @fields); | |||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | 74 | ▶ | my $type = $self->{MMH_field_type} // 'Mail::Message::Field::Fast'; | ||||||||||||||||
|
Condition50%1/2
$self->{"MMH_field_type"} // "Mail::Message::Field::Fast"
MC/DC0%0/1
$self->{"MMH_field_type"} // "Mail::Message::Field::Fast"
$self->{"MMH_field_type"}
Truth table50%1/2
A
A= $self->{"MMH_field_type"}
| |||||||||||||||||||
| 160 | |||||||||||||||||||
| 161 | 74 | $self->addNoRealize( $type->new(@$_) ) for @fields; | |||||||||||||||||
| 162 | 74 | $self; | |||||||||||||||||
| 163 | } | ||||||||||||||||||
| 164 | |||||||||||||||||||
| 165 | |||||||||||||||||||
| 166 | # Warning: fields are added in addResentGroup() as well! | ||||||||||||||||||
| 167 | sub addOrderedFields(@) | ||||||||||||||||||
| 168 | 1367 | ▶ | { my $order = shift->{MMH_order}; | ||||||||||||||||
|
Subroutine
addOrderedFields: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 169 | 1367 | foreach (@_) | |||||||||||||||||
| 170 | 1368 | { push @$order, $_; | |||||||||||||||||
| 171 | 1368 | weaken( $order->[-1] ); | |||||||||||||||||
| 172 | } | ||||||||||||||||||
| 173 | 1367 | @_; | |||||||||||||||||
| 174 | } | ||||||||||||||||||
| 175 | |||||||||||||||||||
| 176 | |||||||||||||||||||
| 177 | 0 | ▶ | sub load($) { $_[0] } | ||||||||||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 178 | |||||||||||||||||||
| 179 | |||||||||||||||||||
| 180 | sub fileLocation() | ||||||||||||||||||
| 181 | 0 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
fileLocation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 182 | 0 | @$self{ qw/MMH_begin MMH_end/ }; | |||||||||||||||||
| 183 | } | ||||||||||||||||||
| 184 | |||||||||||||||||||
| 185 | |||||||||||||||||||
| 186 | sub moveLocation($) | ||||||||||||||||||
| 187 | 0 | ▶ | { my ($self, $dist) = @_; | ||||||||||||||||
|
Subroutine
moveLocation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 188 | 0 | $self->{MMH_begin} -= $dist; | |||||||||||||||||
| 189 | 0 | $self->{MMH_end} -= $dist; | |||||||||||||||||
| 190 | 0 | $self; | |||||||||||||||||
| 191 | } | ||||||||||||||||||
| 192 | |||||||||||||||||||
| 193 | |||||||||||||||||||
| 194 | sub setNoRealize($) | ||||||||||||||||||
| 195 | 0 | ▶ | { my ($self, $field) = @_; | ||||||||||||||||
|
Subroutine
setNoRealize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 196 | |||||||||||||||||||
| 197 | 0 | my $known = $self->{MMH_fields}; | |||||||||||||||||
| 198 | 0 | my $name = $field->name; | |||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | 0 | $self->addOrderedFields($field); | |||||||||||||||||
| 201 | 0 | $known->{$name} = $field; | |||||||||||||||||
| 202 | 0 | $field; | |||||||||||||||||
| 203 | } | ||||||||||||||||||
| 204 | |||||||||||||||||||
| 205 | |||||||||||||||||||
| 206 | sub addNoRealize($) | ||||||||||||||||||
| 207 | 1007 | ▶ | { my ($self, $field) = @_; | ||||||||||||||||
|
Subroutine
addNoRealize: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||
| 208 | |||||||||||||||||||
| 209 | 1007 | my $known = $self->{MMH_fields}; | |||||||||||||||||
| 210 | 1007 | my $name = $field->name; | |||||||||||||||||
| 211 | |||||||||||||||||||
| 212 | 1007 | $self->addOrderedFields($field); | |||||||||||||||||
| 213 | |||||||||||||||||||
| 214 | 1007 | ▶ | if(defined $known->{$name}) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 215 | 72 | ▶ | { if(ref $known->{$name} eq 'ARRAY') { push @{$known->{$name}}, $field } | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 216 | 28 | else { $known->{$name} = [ $known->{$name}, $field ] } | |||||||||||||||||
| 217 | } | ||||||||||||||||||
| 218 | else | ||||||||||||||||||
| 219 | 935 | { $known->{$name} = $field; | |||||||||||||||||
| 220 | } | ||||||||||||||||||
| 221 | |||||||||||||||||||
| 222 | 1007 | $field; | |||||||||||||||||
| 223 | } | ||||||||||||||||||
| 224 | |||||||||||||||||||
| 225 | #-------------------- | ||||||||||||||||||
| 226 | |||||||||||||||||||
| 227 | 40 | 1; | |||||||||||||||||