Message/Replace/MailHeader.pm

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