| 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;{ | ||||||||||||||||||||||||||||||
| 13 | 7 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error info warning/ ]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use Mail::Message::Head::Complete (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use Mail::Message::Body::Lines (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use Mail::Message::Body::Multipart (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use Mail::Message::Body::Nested (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use Mail::Message::Field (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use Mail::Address (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | #-------------------- | ||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | sub build(@) | ||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||
|
Subroutine
build: called CC=41 SCAR=61.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | ! $class->isa('Mail::Box::Message') | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 37 | or error __x"only build() Mail::Message's; they are not in a folder yet."; | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | my @parts | ||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | = ! blessed $_[0] ? () | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 41 | : $_[0]->isa('Mail::Message') ? shift | ||||||||||||||||||||||||||||||
| 42 | : $_[0]->isa('Mail::Message::Body') ? shift | ||||||||||||||||||||||||||||||
| 43 | : (); | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 2 | my ($head, @headerlines); | |||||||||||||||||||||||||||||
| 46 | 2 | my ($type, $transfenc, $dispose, $descr, $cid, $lang); | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | while(@_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 48 | 9 | { my $key = shift; | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | if(blessed $key && $key->isa('Mail::Message::Field')) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($key) and $key->isa("Mail::Message::Field")
MC/DC0%0/2
builtin::blessed($key) and $key->isa("Mail::Message::Field")
builtin::blessed($key)
$key->isa("Mail::Message::Field")
Truth table33%1/3
A and B
A= builtin::blessed($key)B= $key->isa("Mail::Message::Field")
| |||||||||||||||||||||||||||||||
| 51 | 0 | { my $name = $key->name; | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if($name eq 'content-type') { $type = $key } | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 53 | 0 | elsif($name eq 'content-transfer-encoding') { $transfenc = $key } | |||||||||||||||||||||||||||||
| 54 | 0 | elsif($name eq 'content-disposition') { $dispose = $key } | |||||||||||||||||||||||||||||
| 55 | 0 | elsif($name eq 'content-description') { $descr = $key } | |||||||||||||||||||||||||||||
| 56 | 0 | elsif($name eq 'content-language') { $lang = $key } | |||||||||||||||||||||||||||||
| 57 | 0 | elsif($name eq 'content-id') { $cid = $key } | |||||||||||||||||||||||||||||
| 58 | 0 | else { push @headerlines, $key } | |||||||||||||||||||||||||||||
| 59 | 0 | next; | |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | my $value = shift // next; | ||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // (next)
MC/DC0%0/1
shift() // (next)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | 9 | my @data; | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | if($key eq 'head') | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 67 | 0 | { $head = $value } | |||||||||||||||||||||||||||||
| 68 | elsif($key eq 'data') | ||||||||||||||||||||||||||||||
| 69 | 3 | { @data = Mail::Message::Body->new(data => $value) } | |||||||||||||||||||||||||||||
| 70 | ▶ | elsif($key eq 'file' || $key eq 'files') | |||||||||||||||||||||||||||||
|
Condition33%1/3
$key eq "file" or $key eq "files"
MC/DC0%0/2
$key eq "file" or $key eq "files"
$key eq "file"
$key eq "files"
Truth table33%1/3
A or B
A= $key eq "file"B= $key eq "files"
| |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { @data = map Mail::Message::Body->new(file => $_), ref $value eq 'ARRAY' ? @$value : $value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | elsif($key eq 'attach') | ||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | { foreach my $c (ref $value eq 'ARRAY' ? @$value : $value) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { defined $c or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | push @data, blessed $c && $c->isa('Mail::Message') ? Mail::Message::Body::Nested->new(nested => $c) : $c; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($c) and $c->isa("Mail::Message")
MC/DC0%0/2
builtin::blessed($c) and $c->isa("Mail::Message")
builtin::blessed($c)
$c->isa("Mail::Message")
Truth table0%0/3
A and B
A= builtin::blessed($c)B= $c->isa("Mail::Message")
| |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | elsif($key =~ m/^content\-(type|transfer\-encoding|disposition|language|description|id)$/i ) | ||||||||||||||||||||||||||||||
| 80 | 0 | { my $k = lc $1; | |||||||||||||||||||||||||||||
| 81 | 0 | my $field = Mail::Message::Field->new($key, $value); | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if($k eq 'type') { $type = $field } | ||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||
| 83 | 0 | elsif($k eq 'disposition') { $dispose = $field } | |||||||||||||||||||||||||||||
| 84 | 0 | elsif($k eq 'description') { $descr = $field } | |||||||||||||||||||||||||||||
| 85 | 0 | elsif($k eq 'language') { $lang = $field } | |||||||||||||||||||||||||||||
| 86 | 0 | elsif($k eq 'id') { $cid = $field } | |||||||||||||||||||||||||||||
| 87 | 0 | else { $transfenc = $field } | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | elsif($key =~ m/^[A-Z]/) | ||||||||||||||||||||||||||||||
| 90 | 6 | { push @headerlines, $key, $value } | |||||||||||||||||||||||||||||
| 91 | else | ||||||||||||||||||||||||||||||
| 92 | 0 | { warning __x"skipped unknown key '{key}' in build.", key => $key; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 9 | push @parts, grep defined, @data; | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | my $body | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 99 | = @parts==0 ? Mail::Message::Body::Lines->new | ||||||||||||||||||||||||||||||
| 100 | : @parts==1 ? $parts[0] | ||||||||||||||||||||||||||||||
| 101 | : Mail::Message::Body::Multipart->new(parts => \@parts); | ||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | # Setting the type explicitly, only after the body object is finalized | ||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | $body->type($type) if defined $type; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | $body->disposition($dispose) if defined $dispose; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | $body->description($descr) if defined $descr; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | $body->language($lang) if defined $lang; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 108 | 2 | ▶ | $body->contentId($cid) if defined $cid; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | $body->transferEncoding($transfenc) if defined $transfenc; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | 2 | $class->buildFromBody($body, $head, @headerlines); | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | sub buildFromBody(@) | ||||||||||||||||||||||||||||||
| 116 | 23 | ▶ | { my ($class, $body) = (shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
buildFromBody: called CC=9 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 23 | my $head; | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if(blessed $_[0] && $_[0]->isa('Mail::Message::Head')) { $head = shift } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("Mail::Message::Head")
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("Mail::Message::Head")
builtin::blessed($_[0])
$_[0]->isa("Mail::Message::Head")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Mail::Message::Head")
| |||||||||||||||||||||||||||||||
| 120 | else | ||||||||||||||||||||||||||||||
| 121 | 23 | ▶ | { defined $_[0] or shift; # explicit undef as head | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 122 | 23 | $head = Mail::Message::Head::Complete->new; | |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 23 | ▶ | while(@_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | { if(blessed $_[0]) { $head->add(shift) } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 127 | 80 | else { $head->add(shift, shift) } | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 23 | my $message = $class->new(head => $head); | |||||||||||||||||||||||||||||
| 131 | 23 | $message->body($body); | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | # be sure the message-id is actually stored in the header. | ||||||||||||||||||||||||||||||
| 134 | 23 | ▶ | defined $head->get('message-id') or $head->add('Message-Id' => '<'.$message->messageId.'>'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 135 | 23 | ▶ | defined $head->get('Date') or $head->add(Date => Mail::Message::Field->toDate); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 136 | 23 | ▶ | defined $head->get('MIME-Version') or $head->add('MIME-Version' => '1.0'); # required by rfc2045 | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | 23 | $message; | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | #-------------------- | ||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 7 | 1; | |||||||||||||||||||||||||||||