File Coverage

blib/lib/Mail/Box/Parser/C.pm
Criterion Covered Total %
statement 15 61 24.5
branch 0 12 0.0
condition 0 35 0.0
subroutine 5 23 21.7
pod 14 18 77.7
total 34 149 22.8


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Box-Parser-C version 4.01.
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) 2002-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::C;{
13             our $VERSION = '4.01';
14             }
15              
16 1     1   544938 use parent qw/Mail::Box::Parser DynaLoader/;
  1         2  
  1         9  
17              
18             our $VERSION = '4.01';
19              
20 1     1   102 use strict;
  1         2  
  1         22  
21 1     1   3 use warnings;
  1         2  
  1         59  
22              
23 1     1   22 use Log::Report 'mail-box-parser-c';
  1         3  
  1         24  
24              
25 1     1   904 use Mail::Message::Field ();
  1         21847  
  1         938  
26              
27             #--------------------
28              
29             bootstrap Mail::Box::Parser::C $VERSION;
30              
31             ## Defined in the XS library
32             sub open_filename($$$);
33             sub open_filehandle($$$);
34             sub get_filehandle($);
35             sub close_file($);
36             sub push_separator($$);
37             sub pop_separator($);
38             sub get_position($);
39             sub set_position($$);
40             sub read_header($);
41             sub fold_header_line($$);
42             sub in_dosmode($);
43             sub read_separator($);
44             sub body_as_string($$$);
45             sub body_as_list($$$);
46             sub body_as_file($$$$);
47             sub body_delayed($$$);
48              
49             # Not used yet.
50             #fold_header_line(char *original, int wrap)
51             #in_dosmode(int boxnr)
52              
53             #--------------------
54              
55             sub init(@)
56 0     0 0   { my ($self, $args) = @_;
57 0           $self->SUPER::init($args);
58              
59 0           $self->{MBPC_file} = my $fh = $args->{file};
60 0   0       $self->{MBPC_mode} = $args->{mode} || 'r';
61 0 0 0       $self->{MBPC_filename} = $args->{filename} || ref $fh
62             or error __x"filename or handle required to create a parser.";
63              
64 0           $self->start;
65 0           $self;
66             }
67              
68             #--------------------
69              
70 0     0 1   sub filename() { $_[0]->{MBPC_filename} }
71 0     0 1   sub openMode() { $_[0]->{MBPC_mode} }
72 0     0 1   sub file() { $_[0]->{MBPC_file} }
73              
74              
75 0     0 1   sub boxnr() { $_[0]->{MBPC_boxnr} }
76              
77             #--------------------
78              
79             sub start(@)
80 0     0 1   { my ($self, %args) = @_;
81 0 0         $self->openFile(%args) or return;
82              
83 0           trace "opened folder ".$self->filename." to be parsed";
84 0           $self;
85             }
86              
87              
88             sub stop()
89 0     0 1   { my $self = shift;
90 0           trace "close parser for file " . $self->filename;
91 0           $self->closeFile;
92             }
93              
94             sub pushSeparator($)
95 0     0 1   { my ($self, $sep) = @_;
96 0           push_separator $self->boxnr, $sep;
97             }
98              
99 0     0 1   sub popSeparator() { pop_separator $_[0]->boxnr }
100              
101             sub filePosition(;$)
102 0     0 0   { my $boxnr = shift->boxnr;
103 0 0         @_ ? set_position($boxnr, shift) : get_position($boxnr);
104             }
105              
106 0     0 1   sub readHeader() { read_header $_[0]->boxnr }
107              
108 0     0 1   sub readSeparator() { read_separator $_[0]->boxnr }
109              
110             sub bodyAsString(;$$)
111 0     0 1   { my ($self, $exp_chars, $exp_lines) = @_;
112 0   0       body_as_string $self->boxnr, $exp_chars // -1, $exp_lines // -1;
      0        
113             }
114              
115             sub bodyAsList(;$$)
116 0     0 1   { my ($self, $exp_chars, $exp_lines) = @_;
117 0   0       body_as_list $self->boxnr, $exp_chars // -1, $exp_lines // -1;
      0        
118             }
119              
120             sub bodyAsFile($;$$)
121 0     0 1   { my ($self, $file, $exp_chars, $exp_lines) = @_;
122 0   0       body_as_file $self->boxnr, $file, $exp_chars // -1, $exp_lines // -1;
      0        
123             }
124              
125             sub bodyDelayed(;$$)
126 0     0 1   { my ($self, $exp_chars, $exp_lines) = @_;
127 0   0       body_delayed $self->boxnr, $exp_chars // -1, $exp_lines // -1;
      0        
128             }
129              
130             sub openFile(%)
131 0     0 0   { my ($self, %args) = @_;
132 0   0       my $trace = $args{trace} || 0;
133              
134 0   0       my $filename = $args{filename} || $self->filename;
135 0   0       my $mode = $args{mode} || $self->openMode;
136 0   0       my $fh = $args{file} || $self->file;
137              
138 0           my $boxnr;
139 0 0         if(defined $fh)
140 0   0       { $boxnr = open_filehandle($fh, $filename // "$fh", $trace);
141             }
142             else
143 0           { $boxnr = open_filename($filename, $mode, $trace);
144             }
145              
146 0           $self->{MBPC_boxnr} = $boxnr;
147 0 0         defined $boxnr ? $self : undef;
148             }
149              
150             sub closeFile() {
151 0     0 0   my $boxnr = delete $_[0]->{MBPC_boxnr};
152 0 0         defined $boxnr ? close_file $boxnr : ();
153             }
154              
155             1;