| 1 | # Copyrights 2001-2023 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::Head::ResentGroup; | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | $VERSION = '3.013'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base 'Mail::Message::Head::FieldGroup'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Mail::Message::Field::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Sys::Hostname 'hostname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Mail::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # all lower cased! | ||||||||||||||||||||||||||||
| 26 | 3 | my @ordered_field_names = | |||||||||||||||||||||||||||
| 27 | ( 'return-path', 'delivered-to' , 'received', 'resent-date' | ||||||||||||||||||||||||||||
| 28 | , 'resent-from', 'resent-sender', , 'resent-to', 'resent-cc' | ||||||||||||||||||||||||||||
| 29 | , 'resent-bcc', 'resent-message-id' | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | my %resent_field_names = map { ($_ => 1) } @ordered_field_names; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub init($$) | ||||||||||||||||||||||||||||
| 35 | 6 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 6 | $self->{MMHR_real} = $args->{message_head}; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | ▶ | $self->set(Received => $self->createReceived) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->orderedFields and not $self->received
MC/DC0%0/2
$self->orderedFields and not $self->received
$self->orderedFields
not $self->received
Truth table33%1/3
A and not(B)
A= $self->orderedFieldsB= not $self->received
| |||||||||||||||||||||||||||||
| 42 | if $self->orderedFields && ! $self->received; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 6 | $self; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub from($@) | ||||||||||||||||||||||||||||
| 49 | 4 | ▶ | { return $_[0]->resentFrom if @_ == 1; # backwards compat | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=12 SCAR=25.3
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | my ($class, $from, %args) = @_; | |||||||||||||||||||||||||||
| 52 | 3 | ▶ | my $head = $from->isa('Mail::Message::Head') ? $from : $from->head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | my (@groups, $group, $return_path, $delivered_to); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | foreach my $field ($head->orderedFields) | |||||||||||||||||||||||||||
| 57 | 24 | { my $name = $field->name; | |||||||||||||||||||||||||||
| 58 | 24 | ▶ | next unless $resent_field_names{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 12 | ▶ | if($name eq 'return-path') { $return_path = $field } | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 61 | 0 | elsif($name eq 'delivered-to') { $delivered_to = $field } | |||||||||||||||||||||||||||
| 62 | elsif(substr($name, 0, 7) eq 'resent-') | ||||||||||||||||||||||||||||
| 63 | 8 | ▶ | { $group->add($field) if defined $group } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | elsif($name eq 'received') | ||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 3 | $group = Mail::Message::Head::ResentGroup | |||||||||||||||||||||||||||
| 67 | ->new($field, message_head => $head); | ||||||||||||||||||||||||||||
| 68 | 3 | push @groups, $group; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | $group->add($delivered_to) if defined $delivered_to; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 3 | undef $delivered_to; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | ▶ | $group->add($return_path) if defined $return_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 3 | undef $return_path; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 3 | @groups; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub messageHead(;$) | ||||||||||||||||||||||||||||
| 85 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
messageHead: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 4 | ▶ | @_ ? $self->{MMHR_real} = shift : $self->{MMHR_real}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub orderedFields() | ||||||||||||||||||||||||||||
| 91 | 14 | ▶ | { my $head = shift->head; | ||||||||||||||||||||||||||
|
Subroutine
orderedFields: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 14 | ▶ | map { $head->get($_) || () } @ordered_field_names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub set($;$) | ||||||||||||||||||||||||||||
| 97 | 27 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 27 | my $field; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 27 | ▶ | if(@_==1) { $field = shift } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | else | ||||||||||||||||||||||||||||
| 102 | 15 | { my ($fn, $value) = @_; | |||||||||||||||||||||||||||
| 103 | 15 | ▶ | my $name = $resent_field_names{lc $fn} ? $fn : "Resent-$fn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 15 | $field = Mail::Message::Field::Fast->new($name, $value); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 27 | $self->head->set($field); | |||||||||||||||||||||||||||
| 108 | 27 | $field; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | sub fields() { shift->orderedFields } | ||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub fieldNames() { map { $_->Name } shift->orderedFields } | ||||||||||||||||||||||||||
|
Subroutine
fieldNames: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub delete() | ||||||||||||||||||||||||||||
| 115 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 1 | my $head = $self->messageHead; | |||||||||||||||||||||||||||
| 117 | 1 | $head->removeField($_) foreach $self->fields; | |||||||||||||||||||||||||||
| 118 | 1 | $self; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 27 | ▶ | sub add(@) { shift->set(@_) } | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub addFields(@) { shift->notImplemented } | ||||||||||||||||||||||||||
|
Subroutine
addFields: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub returnPath() { shift->{MMHR_return_path} } | ||||||||||||||||||||||||||
|
Subroutine
returnPath: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub deliveredTo() { shift->head->get('Delivered-To') } | ||||||||||||||||||||||||||
|
Subroutine
deliveredTo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 6 | ▶ | sub received() { shift->head->get('Received') } | ||||||||||||||||||||||||||
|
Subroutine
received: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub receivedTimestamp() | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | { my $received = shift->received or return; | ||||||||||||||||||||||||||
|
Subroutine
receivedTimestamp: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $comment = $received->comment or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | Mail::Message::Field->dateToTimestamp($comment); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub date($) { shift->head->get('resent-date') } | ||||||||||||||||||||||||||
|
Subroutine
date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub dateTimestamp() | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { my $date = shift->date or return; | ||||||||||||||||||||||||||
|
Subroutine
dateTimestamp: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | Mail::Message::Field->dateToTimestamp($date->unfoldedBody); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub resentFrom() | ||||||||||||||||||||||||||||
| 156 | 1 | ▶ | { my $from = shift->head->get('resent-from') or return (); | ||||||||||||||||||||||||||
|
Subroutine
resentFrom: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 1 | ▶ | wantarray ? $from->addresses : $from; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub sender() | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | { my $sender = shift->head->get('resent-sender') or return (); | ||||||||||||||||||||||||||
|
Subroutine
sender: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | wantarray ? $sender->addresses : $sender; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub to() | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | { my $to = shift->head->get('resent-to') or return (); | ||||||||||||||||||||||||||
|
Subroutine
to: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | wantarray ? $to->addresses : $to; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | sub cc() | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | { my $cc = shift->head->get('resent-cc') or return (); | ||||||||||||||||||||||||||
|
Subroutine
cc: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | wantarray ? $cc->addresses : $cc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub bcc() | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | { my $bcc = shift->head->get('resent-bcc') or return (); | ||||||||||||||||||||||||||
|
Subroutine
bcc: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | wantarray ? $bcc->addresses : $bcc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | sub destinations() | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
destinations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 0 | ($self->to, $self->cc, $self->bcc); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 2 | ▶ | sub messageId() { shift->head->get('resent-message-id') } | ||||||||||||||||||||||||||
|
Subroutine
messageId: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 13 | ▶ | sub isResentGroupFieldName($) { $resent_field_names{lc $_[1]} } | ||||||||||||||||||||||||||
|
Subroutine
isResentGroupFieldName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 3 | my $unique_received_id = 'rc'.time; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub createReceived(;$) | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | { my ($self, $domain) = @_; | ||||||||||||||||||||||||||
|
Subroutine
createReceived: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | unless(defined $domain) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | { my $sender = ($self->sender)[0] || ($self->resentFrom)[0]; | ||||||||||||||||||||||||||
|
Condition0%0/3
($self->sender)[0] || ($self->resentFrom)[0]
MC/DC0%0/2
($self->sender)[0] || ($self->resentFrom)[0]
($self->sender)[0]
($self->resentFrom)[0]
Truth table0%0/3
A || B
A= ($self->sender)[0]B= ($self->resentFrom)[0]
| |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $domain = $sender->host if defined $sender; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | my $received | |||||||||||||||||||||||||||
| 210 | = 'from ' . $domain | ||||||||||||||||||||||||||||
| 211 | . ' by ' . hostname | ||||||||||||||||||||||||||||
| 212 | . ' with SMTP' | ||||||||||||||||||||||||||||
| 213 | . ' id ' . $unique_received_id++ | ||||||||||||||||||||||||||||
| 214 | . ' for ' . $self->head->get('Resent-To') # may be wrong | ||||||||||||||||||||||||||||
| 215 | . '; '. Mail::Message::Field->toDate; | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | $received; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 3 | 1; | |||||||||||||||||||||||||||