| 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::Body;{ | ||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Mail::Message::Body::Construct adds functionality to Mail::Message::Body | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use Mail::Message::Body::String (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use Mail::Message::Body::Lines (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | #-------------------- | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub foreachLine($) | ||||||||||||||||||||||||||||
| 31 | 4 | ▶ | { my ($self, $code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
foreachLine: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 4 | my $changes = 0; | |||||||||||||||||||||||||||
| 33 | 4 | my @result; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | foreach ($self->lines) | |||||||||||||||||||||||||||
| 36 | 8 | { my $becomes = $code->(); | |||||||||||||||||||||||||||
| 37 | 8 | ▶ | if(defined $becomes) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 8 | { push @result, $becomes; | |||||||||||||||||||||||||||
| 39 | 8 | ▶ | $changes++ if $becomes ne $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | else { $changes++ } | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | $changes ? (ref $self)->new(based_on => $self, data => \@result) : $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub concatenate(@) | ||||||||||||||||||||||||||||
| 49 | 9 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
concatenate: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 9 | ▶ | return $self if @_==1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 9 | my @unified; | |||||||||||||||||||||||||||
| 53 | 9 | foreach (grep defined, @_) | |||||||||||||||||||||||||||
| 54 | 21 | ▶ | { push @unified, | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 55 | ! ref $_ ? $_ | ||||||||||||||||||||||||||||
| 56 | : ref $_ eq 'ARRAY' ? @$_ | ||||||||||||||||||||||||||||
| 57 | : $_->isa('Mail::Message') ? $_->body->decoded | ||||||||||||||||||||||||||||
| 58 | : $_->isa('Mail::Message::Body') ? $_->decoded | ||||||||||||||||||||||||||||
| 59 | : error(__x"cannot concatenate element {which}", which => $_); | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 9 | (ref $self)->new( | |||||||||||||||||||||||||||
| 63 | based_on => $self, | ||||||||||||||||||||||||||||
| 64 | mime_type => 'text/plain', | ||||||||||||||||||||||||||||
| 65 | data => join('', @unified), | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub attach(@) | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
attach: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my @parts; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | push @parts, shift while @_ && blessed $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and builtin::blessed($_[0])
MC/DC0%0/2
@_ and builtin::blessed($_[0])
@_
builtin::blessed($_[0])
Truth table0%0/3
A and B
A= @_B= builtin::blessed($_[0])
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | @parts or return $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unshift @parts, $self->isNested ? $self->nested : $self->isMultipart ? $self->parts : $self; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | @parts==1 ? $parts[0] : Mail::Message::Body::Multipart->new(parts => \@parts, @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # tests in t/51stripsig.t | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub stripSignature($@) | ||||||||||||||||||||||||||||
| 86 | 14 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
stripSignature: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 14 | ▶ | return $self if $self->mimeType->isBinary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 14 | my $p = $args{pattern}; | |||||||||||||||||||||||||||
| 91 | 14 | ▶ | my $pattern = ! defined $p ? qr/^--\s?$/ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 92 | : ! ref $p ? qr/^\Q$p/ | ||||||||||||||||||||||||||||
| 93 | : $p; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 14 | my $lines = $self->lines; # no copy! | |||||||||||||||||||||||||||
| 96 | my $stop = defined $args{max_lines} ? @$lines - $args{max_lines} | ||||||||||||||||||||||||||||
| 97 | 14 | ▶ | : exists $args{max_lines} ? 0 | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 98 | : @$lines-10; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 14 | ▶ | $stop = 0 if $stop < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 14 | my ($sigstart, $found); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 14 | ▶ | if(ref $pattern eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1 | ▶ | { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 4 | ▶ | { $pattern->($lines->[$sigstart]) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 1 | $found = 1; | |||||||||||||||||||||||||||
| 107 | 1 | last; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else | ||||||||||||||||||||||||||||
| 111 | 13 | ▶ | { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 76 | ▶ | { $lines->[$sigstart] =~ $pattern or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 9 | $found = 1; | |||||||||||||||||||||||||||
| 114 | 9 | last; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 14 | ▶ | $found or return $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 10 | ▶ | my $bodytype = $args{result_type} || ref $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{'result_type'} || ref $self
MC/DC0%0/2
$args{'result_type'} || ref $self
$args{'result_type'}
ref $self
Truth table33%1/3
A || B
A= $args{'result_type'}B= ref $self
| |||||||||||||||||||||||||||||
| 121 | 10 | my $stripped = $bodytype->new(based_on => $self, data => [ @$lines[0..$sigstart-1] ]); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 10 | ▶ | wantarray or return $stripped; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 6 | my $sig = $bodytype->new(based_on => $self, data => [ @$lines[$sigstart..$#$lines] ]); | |||||||||||||||||||||||||||
| 126 | 6 | ($stripped, $sig); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 5 | 1; | |||||||||||||||||||||||||||