| 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 | 8 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error warning/ ]; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | use Mail::Box::Parser::Lines (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | #-------------------- | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | sub _scalar2lines($) | ||||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | { my $lines = [ split /^/, ${$_[0]} ]; | ||||||||||||||||||||||||||||||||
|
Subroutine
_scalar2lines: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | # pop @$lines if @$lines && ! length $lines->[-1]; | ||||||||||||||||||||||||||||||||||
| 31 | 15 | $lines; | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | sub read($@) | ||||||||||||||||||||||||||||||||||
| 35 | 16 | ▶ | { # try avoiding copy of large strings | ||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=14 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 36 | 16 | my ($class, undef, %args) = @_; | |||||||||||||||||||||||||||||||||
| 37 | 16 | ▶ | my $trusted = exists $args{trusted} ? $args{trusted} : 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 16 | ▶ | my $strip_status = exists $args{strip_status_fields} ? delete $args{strip_status_fields} : 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 16 | my $body_type = $args{body_type}; | |||||||||||||||||||||||||||||||||
| 40 | 16 | my $pclass = $args{parser_class}; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 16 | my $parser; | |||||||||||||||||||||||||||||||||
| 43 | 16 | my $ref = ref $_[1]; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 16 | ▶ | if($args{seekable}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { $parser = ($pclass // 'Mail::Box::Parser::Perl') | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$pclass // "Mail::Box::Parser::Perl"
MC/DC0%0/1
$pclass // "Mail::Box::Parser::Perl"
$pclass
Truth table0%0/2
A
A= $pclass
| |||||||||||||||||||||||||||||||||||
| 47 | ->new(%args, filename => "file ($ref)", file => $_[1], trusted => $trusted); | ||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | else | ||||||||||||||||||||||||||||||||||
| 50 | 16 | { my ($source, $lines); | |||||||||||||||||||||||||||||||||
| 51 | 16 | ▶ | if(!$ref) | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 52 | 12 | { $source = 'scalar'; | |||||||||||||||||||||||||||||||||
| 53 | 12 | $lines = _scalar2lines \$_[1]; | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | elsif($ref eq 'SCALAR') | ||||||||||||||||||||||||||||||||||
| 56 | 1 | { $source = 'ref scalar'; | |||||||||||||||||||||||||||||||||
| 57 | 1 | $lines = _scalar2lines $_[1]; | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | elsif($ref eq 'ARRAY') | ||||||||||||||||||||||||||||||||||
| 60 | 1 | { $source = 'array of lines'; | |||||||||||||||||||||||||||||||||
| 61 | 1 | $lines = $_[1]; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | ▶ | elsif($ref eq 'GLOB' || (blessed $_[1] && $_[1]->isa('IO::Handle'))) | |||||||||||||||||||||||||||||||||
|
Condition50%3/6
$ref eq "GLOB" or builtin::blessed($_[1]) and $_[1]->isa("IO::Handle")
builtin::blessed($_[1]) and $_[1]->isa("IO::Handle")
MC/DC0%0/3
$ref eq "GLOB" or builtin::blessed($_[1]) and $_[1]->isa("IO::Handle")
$ref eq "GLOB"
builtin::blessed($_[1])
$_[1]->isa("IO::Handle")
Truth table50%2/4
A or B and C
A= $ref eq "GLOB"B= builtin::blessed($_[1])C= $_[1]->isa("IO::Handle")
| |||||||||||||||||||||||||||||||||||
| 64 | 2 | { $source = "file ($ref)"; | |||||||||||||||||||||||||||||||||
| 65 | 2 | local $/ = undef; # slurp | |||||||||||||||||||||||||||||||||
| 66 | 2 | $lines = _scalar2lines \$_[1]->getline; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | else | ||||||||||||||||||||||||||||||||||
| 69 | 0 | { error __x"cannot read message from a {source}.", source => $_[1]/$ref; | |||||||||||||||||||||||||||||||||
| 70 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 16 | ▶ | $parser = ($pclass // 'Mail::Box::Parser::Lines') | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pclass // "Mail::Box::Parser::Lines"
MC/DC0%0/1
$pclass // "Mail::Box::Parser::Lines"
$pclass
Truth table50%1/2
A
A= $pclass
| |||||||||||||||||||||||||||||||||||
| 74 | ->new(%args, source => $source, lines => $lines, trusted => $trusted); | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 16 | $body_type = 'Mail::Message::Body::Lines'; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 16 | my $self = $class->new(%args); | |||||||||||||||||||||||||||||||||
| 80 | 16 | $self->readFromParser($parser, $body_type); | |||||||||||||||||||||||||||||||||
| 81 | 16 | $parser->stop; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 16 | my $head = $self->head; | |||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | $head->set('Message-ID' => '<'.$self->messageId.'>') unless $head->get('Message-ID'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | $head->delete('Status', 'X-Status') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | if $strip_status; | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 16 | $self; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 8 | 1; | |||||||||||||||||||||||||||||||||