| 1 | # Copyrights 2001-2022 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::Box::Parser; | ||||||||||||||||||||||||||||
| 10 | 36 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 36 | $VERSION = '3.012'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 36 | ▶ | use base 'Mail::Reporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 36 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub new(@) | ||||||||||||||||||||||||||||
| 22 | 7 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | $class eq __PACKAGE__ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | ? $class->defaultParserType->new(@_) # bootstrap right parser | ||||||||||||||||||||||||||||
| 26 | : $class->SUPER::new(@_); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init(@) | ||||||||||||||||||||||||||||
| 30 | 7 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | #warn "PARSER type=".ref $self,$self->VERSION; | ||||||||||||||||||||||||||||
| 33 | 7 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 7 | ▶ | $self->{MBP_mode} = $args->{mode} || 'r'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'mode'} || 'r'
MC/DC0%0/1
$args->{'mode'} || 'r'
$args->{'mode'}
Truth table50%1/2
A
A= $args->{'mode'}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 7 | ▶ | unless($self->{MBP_filename} = $args->{filename} || ref $args->{file}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{'filename'} || ref $args->{'file'}
MC/DC0%0/2
$args->{'filename'} || ref $args->{'file'}
$args->{'filename'}
ref $args->{'file'}
Truth table33%1/3
A || B
A= $args->{'filename'}B= ref $args->{'file'}
| |||||||||||||||||||||||||||||
| 38 | 0 | { $self->log(ERROR => "Filename or handle required to create a parser."); | |||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | $self->start(file => $args->{file}); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub start(@) | ||||||||||||||||||||||||||||
| 49 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 7 | my %args = (@_, filename => $self->filename, mode => $self->{MBP_mode}); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 7 | ▶ | $self->openFile(\%args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | or return; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 7 | $self->takeFileInfo; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | $self->log(PROGRESS => "Opened folder $args{filename} to be parsed"); | |||||||||||||||||||||||||||
| 58 | 7 | $self; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub stop() | ||||||||||||||||||||||||||||
| 65 | 14 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 14 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # $self->log(WARNING => "File $filename changed during access.") | ||||||||||||||||||||||||||||
| 70 | # if $self->fileChanged; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 14 | $self->log(NOTICE => "Close parser for file $filename"); | |||||||||||||||||||||||||||
| 73 | 14 | $self->closeFile; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub restart() | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
restart: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $self->closeFile; | |||||||||||||||||||||||||||
| 82 | $self->openFile( {filename => $filename, mode => $self->{MBP_mode}} ) | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | $self->takeFileInfo; | |||||||||||||||||||||||||||
| 86 | 0 | $self->log(NOTICE => "Restarted parser for file $filename"); | |||||||||||||||||||||||||||
| 87 | 0 | $self; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub fileChanged() | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fileChanged: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($size, $mtime) = (stat $self->filename)[7,9]; | |||||||||||||||||||||||||||
| 94 | 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
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $size != $self->{MBP_size} || $mtime != $self->{MBP_mtime}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 28 | ▶ | sub filename() {shift->{MBP_filename}} | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub filePosition(;$) {shift->NotImplemented} | ||||||||||||||||||||||||||
|
Subroutine
filePosition: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub pushSeparator($) {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
pushSeparator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub popSeparator($) {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
popSeparator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub readSeparator($) {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
readSeparator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub readHeader() {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
readHeader: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub bodyAsString() {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
bodyAsString: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub bodyAsList() {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
bodyAsList: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub bodyAsFile() {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
bodyAsFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub bodyDelayed() {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
bodyDelayed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub lineSeparator() {shift->{MBP_linesep}} | ||||||||||||||||||||||||||
|
Subroutine
lineSeparator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub openFile(@) {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
openFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub closeFile(@) {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
closeFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub takeFileInfo() | ||||||||||||||||||||||||||||
| 143 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
takeFileInfo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 7 | @$self{ qw/MBP_size MBP_mtime/ } = (stat $self->filename)[7,9]; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 36 | my $parser_type; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | sub defaultParserType(;$) | ||||||||||||||||||||||||||||
| 151 | 1 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
defaultParserType: called CC=5 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Select the parser manually? | ||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 1 | { $parser_type = shift; | |||||||||||||||||||||||||||
| 156 | 1 | ▶ | return $parser_type if $parser_type->isa( __PACKAGE__ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | confess "Parser $parser_type does not extend " | |||||||||||||||||||||||||||
| 159 | . __PACKAGE__ . "\n"; | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # Already determined which parser we want? | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return $parser_type if $parser_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # Try to use C-based parser. | ||||||||||||||||||||||||||||
| 166 | 0 | eval 'require Mail::Box::Parser::C'; | |||||||||||||||||||||||||||
| 167 | #warn "C-PARSER errors $@\n" if $@; | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $parser_type = 'Mail::Box::Parser::C' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | unless $@; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Fall-back on Perl-based parser. | ||||||||||||||||||||||||||||
| 173 | 0 | require Mail::Box::Parser::Perl; | |||||||||||||||||||||||||||
| 174 | 0 | $parser_type = 'Mail::Box::Parser::Perl'; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | sub DESTROY | ||||||||||||||||||||||||||||
| 181 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 182 | 7 | $self->stop; | |||||||||||||||||||||||||||
| 183 | 7 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 36 | 1; | |||||||||||||||||||||||||||