| 1 | # Copyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Message. Meta-POD processed with | ||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | package Mail::Message; | ||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 7 | $VERSION = '3.012'; | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use Mail::Message::Head::Complete (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Mail::Message::Body::Lines (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use Mail::Message::Body::Multipart (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use Mail::Message::Body::Nested (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Mail::Message::Field (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use Mail::Address (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | sub build(@) | ||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||
|
Subroutine
build: called CC=38 SCAR=59.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | if($class->isa('Mail::Box::Message')) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 30 | 0 | { $class->log(ERROR | |||||||||||||||||||||||||||||
| 31 | => "Only build() Mail::Message's; they are not in a folder yet"); | ||||||||||||||||||||||||||||||
| 32 | 0 | return undef; | |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | my @parts | ||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | = ! ref $_[0] ? () | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 37 | : $_[0]->isa('Mail::Message') ? shift | ||||||||||||||||||||||||||||||
| 38 | : $_[0]->isa('Mail::Message::Body') ? shift | ||||||||||||||||||||||||||||||
| 39 | : (); | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | 2 | my ($head, @headerlines); | |||||||||||||||||||||||||||||
| 42 | 2 | my ($type, $transfenc, $dispose, $descr, $cid); | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | while(@_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 44 | 9 | { my $key = shift; | |||||||||||||||||||||||||||||
| 45 | 9 | ▶ | if(ref $key && $key->isa('Mail::Message::Field')) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $key and $key->isa("Mail::Message::Field")
MC/DC0%0/2
ref $key and $key->isa("Mail::Message::Field")
ref $key
$key->isa("Mail::Message::Field")
Truth table33%1/3
A and B
A= ref $keyB= $key->isa("Mail::Message::Field")
| |||||||||||||||||||||||||||||||
| 46 | 0 | { my $name = $key->name; | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if($name eq 'content-type') { $type = $key } | ||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||
| 48 | 0 | elsif($name eq 'content-transfer-encoding') { $transfenc = $key } | |||||||||||||||||||||||||||||
| 49 | 0 | elsif($name eq 'content-disposition') { $dispose = $key } | |||||||||||||||||||||||||||||
| 50 | 0 | elsif($name eq 'content-description') { $descr = $key } | |||||||||||||||||||||||||||||
| 51 | 0 | elsif($name eq 'content-id') { $cid = $key } | |||||||||||||||||||||||||||||
| 52 | 0 | else { push @headerlines, $key } | |||||||||||||||||||||||||||||
| 53 | 0 | next; | |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 9 | my $value = shift; | |||||||||||||||||||||||||||||
| 57 | 9 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 9 | my @data; | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 9 | ▶ | if($key eq 'head') | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 62 | 0 | { $head = $value } | |||||||||||||||||||||||||||||
| 63 | elsif($key eq 'data') | ||||||||||||||||||||||||||||||
| 64 | 3 | { @data = Mail::Message::Body->new(data => $value) } | |||||||||||||||||||||||||||||
| 65 | ▶ | 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"
| |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { @data = map Mail::Message::Body->new(file => $_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 67 | , ref $value eq 'ARRAY' ? @$value : $value; | ||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | elsif($key eq 'attach') | ||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | { foreach my $c (ref $value eq 'ARRAY' ? @$value : $value) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { defined $c or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | push @data, ref $c && $c->isa('Mail::Message') | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $c and $c->isa("Mail::Message")
MC/DC0%0/2
ref $c and $c->isa("Mail::Message")
ref $c
$c->isa("Mail::Message")
Truth table0%0/3
A and B
A= ref $cB= $c->isa("Mail::Message")
| |||||||||||||||||||||||||||||||
| 73 | ? Mail::Message::Body::Nested->new(nested => $c) | ||||||||||||||||||||||||||||||
| 74 | : $c; | ||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | elsif($key =~ | ||||||||||||||||||||||||||||||
| 78 | m/^content\-(type|transfer\-encoding|disposition|description|id)$/i ) | ||||||||||||||||||||||||||||||
| 79 | 0 | { my $k = lc $1; | |||||||||||||||||||||||||||||
| 80 | 0 | my $field = Mail::Message::Field->new($key, $value); | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if($k eq 'type') { $type = $field } | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 82 | 0 | elsif($k eq 'disposition') { $dispose = $field } | |||||||||||||||||||||||||||||
| 83 | 0 | elsif($k eq 'description') { $descr = $field } | |||||||||||||||||||||||||||||
| 84 | 0 | elsif($k eq 'id') { $cid = $field } | |||||||||||||||||||||||||||||
| 85 | 0 | else { $transfenc = $field } | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | elsif($key =~ m/^[A-Z]/) | ||||||||||||||||||||||||||||||
| 88 | 6 | { push @headerlines, $key, $value } | |||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||||
| 90 | 0 | { $class->log(WARNING => "Skipped unknown key '$key' in build"); | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 9 | push @parts, grep defined, @data; | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | my $body | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 97 | = @parts==0 ? Mail::Message::Body::Lines->new() | ||||||||||||||||||||||||||||||
| 98 | : @parts==1 ? $parts[0] | ||||||||||||||||||||||||||||||
| 99 | : Mail::Message::Body::Multipart->new(parts => \@parts); | ||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | # Setting the type explicitly, only after the body object is finalized | ||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | $body->type($type) if defined $type; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | $body->disposition($dispose) if defined $dispose; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | $body->description($descr) if defined $descr; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | $body->contentId($cid) if defined $cid; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | $body->transferEncoding($transfenc) if defined $transfenc; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 2 | $class->buildFromBody($body, $head, @headerlines); | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | #------------------------------------------ | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | sub buildFromBody(@) | ||||||||||||||||||||||||||||||
| 115 | 22 | ▶ | { my ($class, $body) = (shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
buildFromBody: called CC=9 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 116 | 22 | my @log = $body->logSettings; | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 22 | my $head; | |||||||||||||||||||||||||||||
| 119 | 22 | ▶ | if(ref $_[0] && $_[0]->isa('Mail::Message::Head')) { $head = shift } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and $_[0]->isa("Mail::Message::Head")
MC/DC0%0/2
ref $_[0] and $_[0]->isa("Mail::Message::Head")
ref $_[0]
$_[0]->isa("Mail::Message::Head")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("Mail::Message::Head")
| |||||||||||||||||||||||||||||||
| 120 | else | ||||||||||||||||||||||||||||||
| 121 | 22 | ▶ | { shift unless defined $_[0]; # undef as head | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 122 | 22 | $head = Mail::Message::Head::Complete->new(@log); | |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 22 | ▶ | while(@_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 126 | 76 | ▶ | { if(ref $_[0]) {$head->add(shift)} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 127 | 76 | else {$head->add(shift, shift)} | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 22 | my $message = $class->new | |||||||||||||||||||||||||||||
| 131 | ( head => $head | ||||||||||||||||||||||||||||||
| 132 | , @log | ||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | 22 | $message->body($body); | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | # be sure the message-id is actually stored in the header. | ||||||||||||||||||||||||||||||
| 138 | 22 | ▶ | $head->add('Message-Id' => '<'.$message->messageId.'>') | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 139 | unless defined $head->get('message-id'); | ||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | 22 | ▶ | $head->add(Date => Mail::Message::Field->toDate) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 142 | unless defined $head->get('Date'); | ||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||
| 144 | 22 | ▶ | $head->add('MIME-Version' => '1.0') # required by rfc2045 | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 145 | unless defined $head->get('MIME-Version'); | ||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | 22 | $message; | |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | #------------------------------------------ | ||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||
| 153 | 7 | 1; | |||||||||||||||||||||||||||||