| 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::Box::Parser::Perl;{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent 'Mail::Box::Parser'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error fault info warning trace/ ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use List::Util qw/sum/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use IO::File (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Mail::Message::Field (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $empty_line = qr/^\015?\012?$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub init(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->SUPER::init($args); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $self->{MBPP_mode} = $args->{mode} || 'r'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'mode'} || 'r'
MC/DC0%0/1
$args->{'mode'} || 'r'
$args->{'mode'}
Truth table0%0/2
A
A= $args->{'mode'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $self->{MBPP_filename} = $args->{filename} || ref $args->{file} | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | or error __x"filename or handle required to create a parser."; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{'filename'} || ref $args->{'file'}
MC/DC0%0/2
$args->{'filename'} || ref $args->{'file'}
$args->{'filename'}
ref $args->{'file'}
Truth table0%0/3
A || B
A= $args->{'filename'}B= ref $args->{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->start(file => $args->{file}); | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub filename() { $_[0]->{MBPP_filename} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub openMode() { $_[0]->{MBPP_mode} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
openMode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub file() { $_[0]->{MBPP_file} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub start(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $self->openFile(%args) or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $self->takeFileInfo; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | trace "opened folder ".$self->filename." to be parsed"; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub stop() | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | trace "close parser for file " . $self->filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->closeFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | sub restart() | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self->closeFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $self->openFile(@_) or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->takeFileInfo; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | trace "restarted parser for file " . $self->filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub fileChanged() | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileChanged: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my ($size, $mtime) = (stat $self->filename)[7,9]; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return 0 if !defined $size || !defined $mtime; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $size and defined $mtime
MC/DC0%0/2
defined $size and defined $mtime
defined $size
defined $mtime
Truth table0%0/3
A and B
A= defined $sizeB= defined $mtime
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $size != $self->{MBPP_size} || $mtime != $self->{MBPP_mtime}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | sub filePosition(;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filePosition: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | @_ ? $self->file->seek(shift, 0) : $self->file->tell; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub readHeader() | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readHeader: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $file = $self->file or return (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my @ret = ($file->tell, undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $line = $file->getline; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | LINE: | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | while(defined $line) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | { last LINE if $line =~ $empty_line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($name, $body) = split /\s*\:\s*/, $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | unless(defined $body) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | { warning __x"unexpected end of header in {file}:\n {line}", file => $self->filename, line => $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(@ret && $self->fixHeaderErrors) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ret and $self->fixHeaderErrors
MC/DC0%0/2
@ret and $self->fixHeaderErrors
@ret
$self->fixHeaderErrors
Truth table0%0/3
A and B
A= @retB= $self->fixHeaderErrors
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | { $ret[-1][1] .= ' '.$line; # glue err line to previous field | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $line = $file->getline; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | next LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $file->seek(-length $line, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | last LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | length $body or $body = "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Collect folded lines | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | while($line = $file->getline) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | { $line =~ m!^[ \t]! ? ($body .= $line) : last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $body =~ s/\015//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | push @ret, [ $name, $body ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $ret[1] = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | @ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | sub _is_good_end($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | { my ($self, $where) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_good_end: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # No seps, then when have to trust it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $sep = $self->activeSeparator // return 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->activeSeparator // (return 1)
MC/DC0%0/1
$self->activeSeparator // (return 1)
$self->activeSeparator
Truth table0%0/2
A
A= $self->activeSeparator
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $here = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $file->seek($where, 0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Find first non-empty line on specified location. | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $line = $file->getline; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $line = $file->getline while defined $line && $line =~ $empty_line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $line and $line =~ /$empty_line/
MC/DC0%0/2
defined $line and $line =~ /$empty_line/
defined $line
$line =~ /$empty_line/
Truth table0%0/3
A and B
A= defined $lineB= $line =~ /$empty_line/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Check completed, return to old spot. | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $file->seek($here, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $line // return 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$line // (return 1)
MC/DC0%0/1
$line // (return 1)
$line
Truth table0%0/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | substr($line, 0, length $sep) eq $sep | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
substr($line, 0, length $sep) eq $sep && ($sep ne 'From ' || $line =~ / (?:19[6-9]|20[0-3])[0-9]\b/)
$sep ne "From " or $line =~ / (?:19[6-9]|20[0-3])[0-9]\b/
MC/DC0%0/3
substr($line, 0, length $sep) eq $sep && ($sep ne 'From ' || $line =~ / (?:19[6-9]|20[0-3])[0-9]\b/)
substr($line, 0, length $sep) eq $sep
$sep ne "From "
$line =~ / (?:19[6-9]|20[0-3])[0-9]\b/
Truth table0%0/4
A && B or C
A= substr($line, 0, length $sep) eq $sepB= $sep ne "From "C= $line =~ / (?:19[6-9]|20[0-3])[0-9]\b/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | && ($sep ne 'From ' || $line =~ m/ (?:19[6-9]|20[0-3])[0-9]\b/ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | sub readSeparator() | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readSeparator: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $sep = $self->activeSeparator // return (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->activeSeparator // (return ())
MC/DC0%0/1
$self->activeSeparator // (return ())
$self->activeSeparator
Truth table0%0/2
A
A= $self->activeSeparator
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $start = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $line = $file->getline; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | while(defined $line && $line =~ $empty_line) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $line and $line =~ /$empty_line/
MC/DC0%0/2
defined $line and $line =~ /$empty_line/
defined $line
$line =~ /$empty_line/
Truth table0%0/3
A and B
A= defined $lineB= $line =~ /$empty_line/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | { $start = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $line = $file->getline; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $line // return (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$line // (return ())
MC/DC0%0/1
$line // (return ())
$line
Truth table0%0/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $line =~ s/[\012\015]+$/\n/; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | substr($line, 0, length $sep) eq $sep | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | and return ($start, $line); | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $file->seek($start, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | (); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | sub _readStrippedLines(;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | { my ($self, $exp_chars, $exp_lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_readStrippedLines: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $seps = $self->separators; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $lines = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $msgend; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if(@$seps) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | LINE: | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | { my $where = $file->getpos; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $line = $file->getline or last LINE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | foreach my $sep (@$seps) | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | { substr($line, 0, length $sep) eq $sep or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Some apps fail to escape lines starting with From | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | next if $sep eq 'From ' && $line !~ m/ 19[789][0-9]| 20[0-9][0-9]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sep eq "From " and not $line =~ / 19[789][0-9]| 20[0-9][0-9]/
MC/DC0%0/2
$sep eq "From " and not $line =~ / 19[789][0-9]| 20[0-9][0-9]/
$sep eq "From "
not $line =~ / 19[789][0-9]| 20[0-9][0-9]/
Truth table0%0/3
A and not(B)
A= $sep eq "From "B= not $line =~ / 19[789][0-9]| 20[0-9][0-9]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $file->setpos($where); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $msgend = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | last LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | push @$lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if(@$lines && $lines->[-1] =~ s/\015?\012\z//) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$lines and $lines->[-1] =~ s/\015?\012\z//
MC/DC0%0/2
@$lines and $lines->[-1] =~ s/\015?\012\z//
@$lines
$lines->[-1] =~ s/\015?\012\z//
Truth table0%0/3
A and B
A= @$linesB= $lines->[-1] =~ s/\015?\012\z//
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | { # Keep an empty line to signal the existence of a preamble, but | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # remove a second. | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | pop @$lines if @$seps==1 && @$lines > 1 && length($lines->[-1])==0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@$seps == 1 and @$lines > 1 and length $lines->[-1] == 0
@$seps == 1 and @$lines > 1
MC/DC0%0/3
@$seps == 1 and @$lines > 1 and length $lines->[-1] == 0
@$seps == 1
@$lines > 1
length $lines->[-1] == 0
Truth table0%0/4
A and B and C
A= @$seps == 1B= @$lines > 1C= length $lines->[-1] == 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | else # File without separators. | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | { $lines = ref $file eq 'Mail::Box::FastScalar' ? $file->getlines : [ $file->getlines ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $bodyend = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if($self->stripGt) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | { s/^\>(\>*From\s)/$1/ for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | unless($self->trusted) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | { s/\015$// for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | # input is read as binary stream (i.e. preserving CRLF on Windows). | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Code is based on this assumption. Removal of CR if not trusted | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # conflicts with this assumption. [Markus Spann] | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ($bodyend, $lines, $msgend); | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | sub _take_scalar($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | { my ($self, $begin, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take_scalar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $file->seek($begin, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $file->read($buffer, $end-$begin); | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $buffer =~ s/\015//gr; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | sub bodyAsString(;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | { my ($self, $exp_chars, $exp_lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bodyAsString: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $begin = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if(defined $exp_chars && $exp_chars>=0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $exp_chars and $exp_chars >= 0
MC/DC0%0/2
defined $exp_chars and $exp_chars >= 0
defined $exp_chars
$exp_chars >= 0
Truth table0%0/3
A and B
A= defined $exp_charsB= $exp_chars >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | { # Get at once may be successful | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $end = $begin + $exp_chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if($self->_is_good_end($end)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | { my $body = $self->_take_scalar($begin, $end); | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | $body =~ s/^\>(\>*From\s)/$1/gm if $self->stripGt; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return ($begin, $file->tell, $body); | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my ($end, $lines) = $self->_readStrippedLines($exp_chars, $exp_lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ($begin, $end, join('', @$lines)); | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sub bodyAsList(;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | { my ($self, $exp_chars, $exp_lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bodyAsList: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $begin = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my ($end, $lines) = $self->_readStrippedLines($exp_chars, $exp_lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ($begin, $end, $lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | sub bodyAsFile($;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | { my ($self, $out, $exp_chars, $exp_lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bodyAsFile: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $begin = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ($end, $lines) = $self->_readStrippedLines($exp_chars, $exp_lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $out->print($_) for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ($begin, $end, scalar @$lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sub bodyDelayed(;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | { my ($self, $exp_chars, $exp_lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bodyDelayed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $begin = $file->tell; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if(defined $exp_chars) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | { my $end = $begin + $exp_chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if($self->_is_good_end($end)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | { $file->seek($end, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | return ($begin, $end, $exp_chars, $exp_lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ($end, $lines) = $self->_readStrippedLines($exp_chars, $exp_lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $chars = sum(map length, @$lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ($begin, $end, $chars, scalar @$lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | sub openFile(%) | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
openFile: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | #XXX IO::File is hard to remove because of the mode to be translated | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | my $fh = $self->{MBPP_file} = $args{file} || | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | IO::File->new($self->filename, $args{mode} || $self->openMode) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$args{'file'} || 'IO::File'->new($self->filename, $args{'mode'} || $self->openMode)
$args{'mode'} || $self->openMode
MC/DC0%0/2
$args{'file'} || 'IO::File'->new($self->filename, $args{'mode'} || $self->openMode)
$args{'file'}
'IO::File'->new($self->filename, $args{'mode'} || $self->openMode)
MC/DC0%0/2
$args{'mode'} || $self->openMode
$args{'mode'}
$self->openMode
Truth table0%0/3
A || B
A= $args{'file'}B= 'IO::File'->new($self->filename, $args{'mode'} || $self->openMode)
Truth table0%0/3
A || B
A= $args{'mode'}B= $self->openMode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $fh->binmode(':raw') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fh->can("binmode") or $fh->can("BINMODE")
MC/DC0%0/2
$fh->can("binmode") or $fh->can("BINMODE")
$fh->can("binmode")
$fh->can("BINMODE")
Truth table0%0/3
A or B
A= $fh->can("binmode")B= $fh->can("BINMODE")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | if $fh->can('binmode') || $fh->can('BINMODE'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->resetSeparators; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | sub closeFile() | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
closeFile: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $self->resetSeparators; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | my $file = delete $self->{MBPP_file} or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $file->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | sub takeFileInfo() | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
takeFileInfo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | @$self{ qw/MBPP_size MBPP_mtime/ } = (stat $self->filename)[7,9]; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | sub DESTROY | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->stop; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||