Message/Replace/MailHeader.pm

filter: Statementstmt 19.5% 19 / 97 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 20.0% 6 / 30 Podpod 95.6% 22 / 23 totaltotal 22.3% 47 / 210 CC 27 SCAR 23.7
CC
27
Cov
13%
init
30.0
replace
20.0
extract
20.0
CRAP 10.8
« Message/Construct/Read.pm ↑ Summary Message/Body/Multipart.pm »
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::Replace::MailHeader;{
13 1 our $VERSION = '4.05';
14 }
15  
16 1 ▶use parent 'Mail::Message::Head::Complete';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Log::Report 'mail-message', import => [ qw/__x error panic/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #--------------------
24  
25 sub new(@)
26 0 ▶{ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
27 0 ▶ unshift @_, 'raw_data' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
28 0 $class->SUPER::new(@_);
29 }
30  
31 sub init($)
32 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
33 0 $self->SUPER::init($args);
34  
35 0 ▶ $self->modify($args->{Modify} || $args->{Reformat} || 0);
Condition0%0/5
$args->{'Modify'} || $args->{'Reformat'} || 0
l!l
00
$args->{"Modify"} or $args->{"Reformat"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'Modify'} || $args->{'Reformat'} || 0
$args->{"Modify"} $args->{"Reformat"}
Truth table0%0/3
A or B
A= $args->{"Modify"}B= $args->{"Reformat"}
ABresult
1X1
011
000
36 0 ▶ $self->fold_length($args->{FoldLength} || 79);
Condition0%0/2
$args->{'FoldLength'} || 79
l!l
00
MC/DC0%0/1
$args->{'FoldLength'} || 79
$args->{'FoldLength'}
Truth table0%0/2
A
A= $args->{'FoldLength'}
Aresult
11
00
37 0 ▶ $self->mail_from($args->{MailFrom} || 'KEEP');
Condition0%0/2
$args->{'MailFrom'} || 'KEEP'
l!l
00
MC/DC0%0/1
$args->{'MailFrom'} || 'KEEP'
$args->{'MailFrom'}
Truth table0%0/2
A
A= $args->{'MailFrom'}
Aresult
11
00
38 0 $self;
39 }
40  
41 #--------------------
42  
43 sub delete($;$)
44 0 ▶{ my ($self, $tag) = (shift, shift);
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
45 0 ▶ @_ or return $self->delete($tag);
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->delete($tag) 0 0 0
46  
47 0 my $index = shift;
48 0 my @fields = $self->get($tag);
49 0 my ($field) = splice @fields, $index, 1;
50 0 $self->reset($tag, @fields);
51 0 $field;
52 }
53  
54  
55 sub add($$)
56 0 ▶{ my $self = shift;
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
57 0 my $field = $self->add(shift);
58 0 $field->unfoldedBody;
59 }
60  
61  
62 sub replace($$;$)
63 0 ▶{ my ($self, $tag, $line, $index) = @_;
Subroutine replace: not called CC=4 SCAR=30.0
Pod documented
64 0 ▶ $tag //= $line =~ s/^([^:]+)\:\s*// ? $1 : 'MISSING';
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^([^:]+)\:\s*// ? : 0 0 0
Condition0%0/3
$tag //= $line =~ s/^([^:]+)\:\s*// ? $1 : "MISSING"
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag //= $line =~ s/^([^:]+)\:\s*// ? $1 : "MISSING"
$tag $line =~ s/^([^:]+)\:\s*// ? $1 : "MISSING"
Truth table0%0/3
A //= B
A= $tagB= $line =~ s/^([^:]+)\:\s*// ? $1 : "MISSING"
ABresult
1X1
011
000
65  
66 0 my $field = Mail::Message::Field::Fast->new($tag, $line);
67 0 my @fields = $self->get($tag);
68 0 ▶ $fields[ $index||0 ] = $field;
Condition0%0/2
$index || 0
l!l
00
MC/DC0%0/1
$index || 0
$index
Truth table0%0/2
A
A= $index
Aresult
11
00
69 0 $self->reset($tag, @fields);
70  
71 0 $field;
72 }
73  
74 #--------------------
75  
76 sub get($;$)
77 0 ▶{ my $head = shift->head;
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
78 0 my @ret = map $head->get(@_), @_;
79  
80 0 ▶ wantarray ? (map $_->unfoldedBody, @ret)
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
@ret ? : 0 0 0
81 : @ret ? $ret[0]->unfoldedBody
82 : undef;
83 }
84  
85 #--------------------
86  
87 sub modify(;$)
88 0 ▶{ my $self = shift;
Subroutine modify: not called CC=2 SCAR=17.9
Pod documented
89 0 ▶ @_ ? ($self->{MH_refold} = shift) : $self->{MH_refold};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
90 }
91  
92  
93 sub mail_from(;$)
94 0 ▶{ my $self = shift;
Subroutine mail_from: not called CC=3 SCAR=24.8
Pod documented
95 0 ▶ @_ or return $self->{MH_mail_from};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MH_mail_from"} 0 0 0
96  
97 0 my $choice = uc(shift);
98 0 ▶ $choice =~ /^(IGNORE|ERROR|COERCE|KEEP)$/
Branch: 1 branch
BranchTrueFalseTotal
$choice =~ /^(IGNORE|ERROR|COERCE|KEEP)$/ or &error(&__x("bad Mail-From choice: '{pick}'.", "pick", $choice)) 0 0 0
99 or error __x"bad Mail-From choice: '{pick}'.", pick => $choice;
100  
101 0 $self->{MH_mail_from} = $choice;
102 }
103  
104  
105 sub fold(;$)
106 0 ▶{ my $self = shift;
Subroutine fold: not called CC=3 SCAR=24.8
Pod documented
107 0 ▶ my $wrap = @_ ? shift : $self->fold_length;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
108 0 $_->setWrapLength($wrap) for $self->orderedFields;
109 0 $self;
110 }
111  
112  
113 sub unfold(;$)
114 0 ▶{ my $self = shift;
Subroutine unfold: not called CC=3 SCAR=24.8
Pod documented
115 0 ▶ my @fields = @_ ? $self->get(shift) : $self->orderedFields;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
116 0 $_->setWrapLength(100_000) for @fields; # blunt approach
117 0 $self;
118 }
119  
120  
121 sub extract($)
122 0 ▶{ my ($self, $lines) = @_;
Subroutine extract: not called CC=4 SCAR=30.0
Pod documented
123  
124 0 my $parser = Mail::Box::Parser::Perl->new(filename => 'extract from array', data => $lines, trusted => 1);
125 0 $self->read($parser);
126 0 $parser->close;
127  
128 # Remove header from array
129 0 ▶ shift @$lines while @$lines && $lines->[0] != m/^[\r\n]+/;
Branch: 1 branch
BranchTrueFalseTotal
@$lines and $lines->[0] != /^[\r\n]+/ and do { shift @$lines } 0 0 0
Condition0%0/3
@$lines and $lines->[0] != /^[\r\n]+/
!ll&&!rl&&r
000
MC/DC0%0/2
@$lines and $lines->[0] != /^[\r\n]+/
@$lines $lines->[0] != /^[\r\n]+/
Truth table0%0/3
A and B
A= @$linesB= $lines->[0] != /^[\r\n]+/
ABresult
0X0
100
111
130 0 ▶ shift @$lines if @$lines;
Branch: 1 branch
BranchTrueFalseTotal
if @$lines 0 0 0
131 0 $self;
132 }
133  
134  
135 sub read($)
136 0 ▶{ my ($self, $file) = @_;
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
137 0 my $parser = Mail::Box::Parser::Perl->new(filename => ('from file-handle '.ref $file), file => $file, trusted => 1);
138 0 $self->read($parser);
139 0 $parser->close;
140 0 $self;
141 }
142  
143  
144 0 ▶sub empty() { $_[0]->removeFields( m/^/ ) }
Subroutine empty: not called CC=1 SCAR=6.9
Pod documented
145  
146  
147 sub header(;$)
148 0 ▶{ my $self = shift;
Subroutine header: not called CC=3 SCAR=24.8
Pod documented
149 0 ▶ $self->extract(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
150 0 ▶ $self->fold if $self->modify;
Branch: 1 branch
BranchTrueFalseTotal
if $self->modify 0 0 0
151 0 [ $self->orderedFields ];
152 }
153  
154  
155 0 ▶sub header_hashref($) { panic "Don't use header_hashref!!!" }
Subroutine header_hashref: not called CC=1 SCAR=6.9
Pod documented
156  
157  
158 0 ▶sub combine($;$) { panic "Don't use combine()!!!" }
Subroutine combine: not called CC=1 SCAR=6.9
Pod documented
159  
160  
161 0 ▶sub exists() { $_[0]->count }
Subroutine exists: not called CC=1 SCAR=6.9
Pod documented
162  
163  
164 0 ▶sub as_string() { $_[0]->string }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
165  
166  
167 sub fold_length(;$$)
168 0 ▶{ my $self = shift;
Subroutine fold_length: not called CC=3 SCAR=24.8
Pod documented
169 0 ▶ @_ or return $self->{MH_wrap};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MH_wrap"} 0 0 0
170  
171 0 my $old = $self->{MH_wrap};
172 0 my $wrap = $self->{MH_wrap} = shift;
173 0 ▶ $self->fold($wrap) if $self->modify;
Branch: 1 branch
BranchTrueFalseTotal
if $self->modify 0 0 0
174 0 $old;
175 }
176  
177  
178 0 ▶sub tags() { $_[0]->names }
Subroutine tags: not called CC=1 SCAR=6.9
Pod documented
179  
180  
181 0 ▶sub dup() { $_[0]->clone }
Subroutine dup: not called CC=1 SCAR=6.9
Pod documented
182  
183  
184 0 ▶sub cleanup() { $_[0] }
Subroutine cleanup: not called CC=1 SCAR=6.9
Pod documented
185  
186 #--------------------
187  
188 BEGIN
189 1 ▶{ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.4
190 0 ▶ *Mail::Header::new = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
191 0 my $class = shift;
192 0 Mail::Message::Replace::MailHeader->new(@_);
193 1 };
194 }
195  
196  
197  
198 sub isa($)
199 0 ▶{ my ($thing, $class) = @_;
Subroutine isa: not called CC=2 SCAR=17.9
Pod documented
200 0 ▶ $class eq 'Mail::Mailer' ? 1 : $thing->SUPER::isa($class);
Branch: 1 branch
BranchTrueFalseTotal
$class eq 'Mail::Mailer' ? : 0 0 0
201 }
202  
203  
204 1 1;
« Message/Construct/Read.pm ↑ Summary Message/Body/Multipart.pm »