blib/lib/Convert/TNEF.pm

filter: Statementstmt 71.7% 180 / 251 Branchbran 44.0% 67 / 152 Conditioncond 41.3% 24 / 58 MC/DCmcdc 8.3% 3 / 36 Subroutinesub 80.0% 20 / 25 Podpod 0.0% 0 / 6 totaltotal 55.6% 294 / 528 CC 101 SCAR 40.0
CC
101
Cov
59%
_debug_print
182.0
read
80.8
purge
42.0
CRAP 54.5
↑ Summary
1 # Convert::TNEF.pm
2 #
3 # Copyright (c) 1999 Douglas Wilson <dougw@cpan.org>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
6  
7 package Convert::TNEF;
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 $VERSION
13 $TNEF_SIGNATURE
14 $TNEF_PURE
15 $LVL_MESSAGE
16 $LVL_ATTACHMENT
17 $errstr
18 $g_file_cnt
19 %dflts
20 %atp
21 %att
22 %att_name
23 1 );
24  
25 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use IO::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use MIME::Body;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 $VERSION = '0.18';
31  
32 # Set some TNEF constants. Everything turned
33 # out to be in little endian order, so I just added
34 # 'reverse' everywhere that I needed to
35 # instead of reversing the hex codes.
36 1 $TNEF_SIGNATURE = reverse pack( 'H*', '223E9F78' );
37 1 $TNEF_PURE = reverse pack( 'H*', '00010000' );
38  
39 1 $LVL_MESSAGE = pack( 'H*', '01' );
40 1 $LVL_ATTACHMENT = pack( 'H*', '02' );
41  
42 1 %atp = (
43 Triples => pack( 'H*', '0000' ),
44 String => pack( 'H*', '0001' ),
45 Text => pack( 'H*', '0002' ),
46 Date => pack( 'H*', '0003' ),
47 Short => pack( 'H*', '0004' ),
48 Long => pack( 'H*', '0005' ),
49 Byte => pack( 'H*', '0006' ),
50 Word => pack( 'H*', '0007' ),
51 Dword => pack( 'H*', '0008' ),
52 Max => pack( 'H*', '0009' ),
53 );
54  
55 1 for ( keys %atp ) {
56 10 $atp{$_} = reverse $atp{$_};
57 }
58  
59 33 ▶sub _ATT {
Subroutine _ATT: called CC=1 SCAR=0.0
60 33 my ( $att, $id ) = @_;
61 33 return reverse($id) . $att;
62 }
63  
64 # The side comments are 'MAPI' equivalents
65 %att = (
66 Null => _ATT( pack( 'H*', '0000' ), pack( 'H4', '0000' ) ),
67 # PR_ORIGINATOR_RETURN_ADDRESS
68 From => _ATT( $atp{Triples}, pack( 'H*', '8000' ) ),
69 # PR_SUBJECT
70 Subject => _ATT( $atp{String}, pack( 'H*', '8004' ) ),
71 # PR_CLIENT_SUBMIT_TIME
72 DateSent => _ATT( $atp{Date}, pack( 'H*', '8005' ) ),
73 # PR_MESSAGE_DELIVERY_TIME
74 DateRecd => _ATT( $atp{Date}, pack( 'H*', '8006' ) ),
75 # PR_MESSAGE_FLAGS
76 MessageStatus => _ATT( $atp{Byte}, pack( 'H*', '8007' ) ),
77 # PR_MESSAGE_CLASS
78 MessageClass => _ATT( $atp{Word}, pack( 'H*', '8008' ) ),
79 # PR_MESSAGE_ID
80 MessageID => _ATT( $atp{String}, pack( 'H*', '8009' ) ),
81 # PR_PARENT_ID
82 ParentID => _ATT( $atp{String}, pack( 'H*', '800A' ) ),
83 # PR_CONVERSATION_ID
84 ConversationID => _ATT( $atp{String}, pack( 'H*', '800B' ) ),
85 Body => _ATT( $atp{Text}, pack( 'H*', '800C' ) ), # PR_BODY
86 # PR_IMPORTANCE
87 Priority => _ATT( $atp{Short}, pack( 'H*', '800D' ) ),
88 # PR_ATTACH_DATA_xxx
89 AttachData => _ATT( $atp{Byte}, pack( 'H*', '800F' ) ),
90 # PR_ATTACH_FILENAME
91 AttachTitle => _ATT( $atp{String}, pack( 'H*', '8010' ) ),
92 # PR_ATTACH_RENDERING
93 AttachMetaFile => _ATT( $atp{Byte}, pack( 'H*', '8011' ) ),
94 # PR_CREATION_TIME
95 AttachCreateDate => _ATT( $atp{Date}, pack( 'H*', '8012' ) ),
96 # PR_LAST_MODIFICATION_TIME
97 AttachModifyDate => _ATT( $atp{Date}, pack( 'H*', '8013' ) ),
98 # PR_LAST_MODIFICATION_TIME
99 DateModified => _ATT( $atp{Date}, pack( 'H*', '8020' ) ),
100 #PR_ATTACH_TRANSPORT_NAME
101 AttachTransportFilename => _ATT( $atp{Byte}, pack( 'H*', '9001' ) ),
102 AttachRenddata => _ATT( $atp{Byte}, pack( 'H*', '9002' ) ),
103 MAPIProps => _ATT( $atp{Byte}, pack( 'H*', '9003' ) ),
104 # PR_MESSAGE_RECIPIENTS
105 RecipTable => _ATT( $atp{Byte}, pack( 'H*', '9004' ) ),
106 Attachment => _ATT( $atp{Byte}, pack( 'H*', '9005' ) ),
107 TnefVersion => _ATT( $atp{Dword}, pack( 'H*', '9006' ) ),
108 OemCodepage => _ATT( $atp{Byte}, pack( 'H*', '9007' ) ),
109 # PR_ORIG_MESSAGE_CLASS
110 OriginalMessageClass => _ATT( $atp{Word}, pack( 'H*', '0006' ) ),
111  
112 # PR_RCVD_REPRESENTING_xxx or PR_SENT_REPRESENTING_xxx
113 Owner => _ATT( $atp{Byte}, pack( 'H*', '0000' ) ),
114 # PR_SENT_REPRESENTING_xxx
115 SentFor => _ATT( $atp{Byte}, pack( 'H*', '0001' ) ),
116 # PR_RCVD_REPRESENTING_xxx
117 Delegate => _ATT( $atp{Byte}, pack( 'H*', '0002' ) ),
118 # PR_DATE_START
119 DateStart => _ATT( $atp{Date}, pack( 'H*', '0006' ) ),
120 DateEnd => _ATT( $atp{Date}, pack( 'H*', '0007' ) ), # PR_DATE_END
121 # PR_OWNER_APPT_ID
122 AidOwner => _ATT( $atp{Long}, pack( 'H*', '0008' ) ),
123 # PR_RESPONSE_REQUESTED
124 1 RequestRes => _ATT( $atp{Short}, pack( 'H*', '0009' ) ),
125 );
126  
127 # Create reverse lookup table
128 1 %att_name = reverse %att;
129  
130 # Global counter for creating file names
131 1 $g_file_cnt = 0;
132  
133 # Set some package global defaults for new objects
134 # which can be overridden for any individual object.
135 1 %dflts = (
136 debug => 0,
137 debug_max_display => 1024,
138 debug_max_line_size => 64,
139 ignore_checksum => 0,
140 display_after_err => 32,
141 output_to_core => 4096,
142 output_dir => File::Spec->curdir,
143 output_prefix => "tnef",
144 buffer_size => 1024,
145 );
146  
147 # Make a file name
148 0 ▶sub _mk_fname {
Subroutine _mk_fname: not called CC=1 SCAR=6.9
149 0 my $parms = shift;
150 File::Spec->catfile( $parms->{output_dir},
151 0 $parms->{output_prefix} . "-" . $$ . "-"
152 . ++$g_file_cnt . ".doc" );
153 }
154  
155 1 ▶sub _rtn_err {
Subroutine _rtn_err: called CC=5 SCAR=27.8
156 1 my ( $errmsg, $fh, $parms ) = @_;
157 1 $errstr = $errmsg;
158 1 ▶ if ( $parms->{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parms->{"debug"}) 0 1 1
159 0 ▶ my $read_size = $parms->{display_after_err} || 32;
Condition0%0/2
$parms->{'display_after_err'} || 32
l!l
00
MC/DC0%0/1
$parms->{'display_after_err'} || 32
$parms->{'display_after_err'}
Truth table0%0/2
A
A= $parms->{'display_after_err'}
Aresult
11
00
160 0 my $data;
161 0 $fh->read( $data, $read_size );
162 0 print "Error: $errstr\n";
163 0 print "Data:\n";
164 0 ▶ print $1, "\n" while $data =~
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /([^\r\n]{0,$parms->{"debug_max_line_size"}})\r?\n?/g and do { print $1, "\n" } 0 0 0
165 /([^\r\n]{0,$parms->{debug_max_line_size}})\r?\n?/g;
166 0 print "HData:\n";
167 0 my $hdata = unpack( "H*", $data );
168 0 ▶ print $1, "\n"
Branch: 1 branch
BranchTrueFalseTotal
$hdata =~ /(.{0,$parms->{"debug_max_line_size"}})/g and do { print $1, "\n" } 0 0 0
169 while $hdata =~ /(.{0,$parms->{debug_max_line_size}})/g;
170 }
171 1 return undef;
172 }
173  
174 0 ▶sub _read_err {
Subroutine _read_err: not called CC=2 SCAR=17.9
175 0 my ( $bytes, $fh, $errmsg ) = @_;
176 0 ▶ $errstr =
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes ? : 0 0 0
177 ( defined $bytes ) ? "Premature EOF" : "Read Error:" . $errmsg;
178 0 return undef;
179 }
180  
181 0 ▶sub read_ent {
Subroutine read_ent: not called CC=5 SCAR=34.0
Pod undocumented
182 0 ▶ croak "Usage: Convert::TNEF->read_ent(entity, parameters) "
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 or @_ == 3 0 0 0
Condition0%0/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
183 unless @_ == 2 or @_ == 3;
184 0 my $self = shift;
185 0 my ( $ent, $parms ) = @_;
186 0 ▶ my $io = $ent->open("r") or do {
Branch: 1 branch
BranchTrueFalseTotal
my $io = $ent->open("r") or do { $Convert::TNEF::errstr = "Can't open entity: $!"; return undef } 0 0 0
187 0 $errstr = "Can't open entity: $!";
188 0 return undef;
189 };
190 0 my $tnef = $self->read( $io, $parms );
191 0 ▶ $io->close or do {
Branch: 1 branch
BranchTrueFalseTotal
$io->close or do { $Convert::TNEF::errstr = "Error closing handle: $!"; return undef } 0 0 0
192 0 $errstr = "Error closing handle: $!";
193 0 return undef;
194 };
195 0 return $tnef;
196 }
197  
198 2 ▶sub read_in {
Subroutine read_in: called CC=5 SCAR=18.5
Pod undocumented
199 2 ▶ croak "Usage: Convert::TNEF->read_in(filename, parameters) "
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 or @_ == 3 0 2 2
Condition66%2/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
110
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table66%2/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
200 unless @_ == 2 or @_ == 3;
201 2 my $self = shift;
202 2 my ( $fname, $parms ) = @_;
203 2 ▶ open( INFILE, "<$fname" ) or do {
Branch: 1 branch
BranchTrueFalseTotal
open INFILE, "<$fname" or do { $Convert::TNEF::errstr = "Can't open ${fname}: $!"; return undef } 2 0 2
204 0 $errstr = "Can't open $fname: $!";
205 0 return undef;
206 };
207 2 binmode INFILE;
208 2 my $tnef = $self->read( \*INFILE, $parms );
209 2 ▶ close INFILE or do {
Branch: 1 branch
BranchTrueFalseTotal
close INFILE or do { $Convert::TNEF::errstr = "Error closing ${fname}: $!"; return undef } 2 0 2
210 0 $errstr = "Error closing $fname: $!";
211 0 return undef;
212 };
213 2 return $tnef;
214 }
215  
216 2 ▶sub read {
Subroutine read: called CC=46 SCAR=43.9
Pod undocumented
217 2 ▶ croak "Usage: Convert::TNEF->read(fh, parameters) "
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 or @_ == 3 0 2 2
Condition33%1/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
020
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table33%1/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
218 unless @_ == 2 or @_ == 3;
219 2 my $self = shift;
220 2 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
221 2 $self = {};
222 2 bless $self, $class;
223 2 my ( $fd, $parms ) = @_;
224 2 $fd = wraphandle($fd);
225  
226 2 my %parms = %dflts;
227 2 ▶ @parms{ keys %$parms } = values %$parms if defined $parms;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms 1 1 2
228 2 $parms = \%parms;
229 2 my $debug = $parms{debug};
230 2 my $ignore_checksum = $parms{ignore_checksum};
231  
232 # Start of TNEF stream
233 2 my $data;
234 2 my $num_bytes = $fd->read( $data, 4 );
235 2 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 4 0 2 2
236 2 ▶ print "TNEF start: ", unpack( "H*", $data ), "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
237 2 ▶ return _rtn_err( "Not TNEF-encapsulated", $fd, $parms )
Branch: 1 branch
BranchTrueFalseTotal
unless $data eq $Convert::TNEF::TNEF_SIGNATURE 0 2 2
238 unless $data eq $TNEF_SIGNATURE;
239  
240 # Key
241 2 $num_bytes = $fd->read( $data, 2 );
242 2 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 2 0 2 2
243 2 ▶ print "TNEF key: ", unpack( "H*", $data ), "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
244  
245 # Start of First Object
246 2 $num_bytes = $fd->read( $data, 1 );
247 2 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 1 0 2 2
248  
249 2 my $msg_att = "";
250  
251 2 my $is_msg = ( $data eq $LVL_MESSAGE );
252 2 my $is_att = ( $data eq $LVL_ATTACHMENT );
253 2 ▶ print "TNEF object start: ", unpack( "H*", $data ), "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
254 2 ▶ return _rtn_err( "Neither a message nor an attachment", $fd,
Branch: 1 branch
BranchTrueFalseTotal
unless $is_msg or $is_att 0 2 2
Condition33%1/3
$is_msg or $is_att
l!l&&r!l&&!r
200
MC/DC0%0/2
$is_msg or $is_att
$is_msg $is_att
Truth table33%1/3
A or B
A= $is_msgB= $is_att
ABresult
1X1
011
000
255 $parms )
256 unless $is_msg or $is_att;
257  
258 2 my $msg = Convert::TNEF::Data->new;
259 2 my @atts;
260  
261 # Current message or attachment in loop
262 2 my $ent = $msg;
263  
264 # Read message and attachments
265 LOOP: {
266 2 ▶ my $type = $is_msg ? 'message' : 'attachment';
Branch: 1 branch
BranchTrueFalseTotal
$is_msg ? : 18 6 24
267 24 ▶ print "Reading $type attribute\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
268 24 $num_bytes = $fd->read( $data, 4 );
269 24 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 4 0 24 24
270 24 my $att_id = $data;
271 24 my $att_name = $att_name{$att_id};
272  
273 24 ▶ print "TNEF $type attribute: ", unpack( "H*", $data ), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
274 if $debug;
275 return _rtn_err( "Bad Attribute found in $type", $fd, $parms )
276 24 ▶ unless $att_name{$att_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $Convert::TNEF::att_name{$att_id} 0 24 24
277 24 ▶ if ( $att_id eq $att{TnefVersion} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($att_id eq $Convert::TNEF::att{'TnefVersion'}) { } 2 22 24
elsif ($att_id eq $Convert::TNEF::att{'MessageClass'}) { } 2 20 22
elsif ($att_id eq $Convert::TNEF::att{'AttachRenddata'}) { } 1 19 20
278 2 ▶ return _rtn_err( "Version attribute found in attachment", $fd,
Branch: 1 branch
BranchTrueFalseTotal
if $is_att 0 2 2
279 $parms )
280 if $is_att;
281 } elsif ( $att_id eq $att{MessageClass} ) {
282 2 ▶ return _rtn_err( "MessageClass attribute found in attachment",
Branch: 1 branch
BranchTrueFalseTotal
if $is_att 0 2 2
283 $fd, $parms )
284 if $is_att;
285 } elsif ( $att_id eq $att{AttachRenddata} ) {
286 1 ▶ return _rtn_err( "AttachRenddata attribute found in message",
Branch: 1 branch
BranchTrueFalseTotal
if $is_msg 0 1 1
287 $fd, $parms )
288 if $is_msg;
289 1 push @atts, ( $ent = Convert::TNEF::Data->new );
290 } else {
291 19 ▶ return _rtn_err( "AttachRenddata must be first attribute", $fd,
Branch: 1 branch
BranchTrueFalseTotal
if $is_att and not @atts and $att_name ne "AttachRenddata" 0 19 19
Condition50%3/6
$is_att and not @atts and $att_name ne "AttachRenddata"
!ll&&!rl&&r
1900
$is_att and not @atts
!ll&&!rl&&r
1450
MC/DC0%0/3
$is_att and not @atts and $att_name ne "AttachRenddata"
$is_att not @atts $att_name ne "AttachRenddata"
Truth table50%2/4
A and not(B) and C
A= $is_attB= not @attsC= $att_name ne "AttachRenddata"
ABCresult
0XX0
10X0
1100
1111
292 $parms )
293 if $is_att
294 and !@atts
295 and $att_name ne "AttachRenddata";
296 }
297 24 ▶ print "Got attribute:$att_name{$att_id}\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
298  
299 24 $num_bytes = $fd->read( $data, 4 );
300 24 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 4 0 24 24
301  
302 24 ▶ print "HLength:", unpack( "H8", $data ), "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
303 24 my $length = unpack( "V", $data );
304 24 ▶ print "Length: $length\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
305  
306 # Get the attribute data (returns an object since data may
307 # actually end up in a file)
308 24 my $calc_chksum;
309 24 ▶ $data = _build_data( $fd, $length, \$calc_chksum, $parms )
Branch: 1 branch
BranchTrueFalseTotal
$data = _build_data($fd, $length, \$calc_chksum, $parms) or return undef 24 0 24
310 or return undef;
311 24 ▶ _debug_print( $length, $att_id, $data, $parms ) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 24 24
312 24 $ent->datahandle( $att_name, $data, $length );
313  
314 24 $num_bytes = $fd->read( $data, 2 );
315 24 ▶ return _read_err( $num_bytes, $fd, $! ) unless $num_bytes == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == 2 0 24 24
316 24 my $file_chksum = $data;
317 24 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 24 24
318 0 print "Calc Chksum:", unpack( "H*", $calc_chksum ), "\n";
319 0 print "File Chksum:", unpack( "H*", $file_chksum ), "\n";
320 }
321 24 ▶ return _rtn_err( "Bad Checksum", $fd, $parms )
Branch: 1 branch
BranchTrueFalseTotal
unless $calc_chksum eq $file_chksum or $ignore_checksum 1 23 24
Condition100%3/3
$calc_chksum eq $file_chksum or $ignore_checksum
l!l&&r!l&&!r
2211
MC/DC100%2/2
$calc_chksum eq $file_chksum or $ignore_checksum
$calc_chksum eq $file_chksum $ignore_checksum
Truth table100%3/3
A or B
A= $calc_chksum eq $file_chksumB= $ignore_checksum
ABresult
1X1
011
000
322 unless $calc_chksum eq $file_chksum
323 or $ignore_checksum;
324  
325 23 my $num_bytes = $fd->read( $data, 1 );
326  
327 # EOF (0 bytes) is ok
328 23 ▶ return _read_err( $num_bytes, $fd, $! ) unless defined $num_bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num_bytes 0 23 23
329 23 ▶ last LOOP if $num_bytes < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $num_bytes < 1 1 22 23
330 22 ▶ print "Next token:", unpack( "H2", $data ), "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 22 22
331 22 $is_msg = ( $data eq $LVL_MESSAGE );
332 22 ▶ return _rtn_err( "Found message data in attachment", $fd, $parms )
Branch: 1 branch
BranchTrueFalseTotal
if $is_msg and $is_att 0 22 22
Condition66%2/3
$is_msg and $is_att
!ll&&!rl&&r
6160
MC/DC0%0/2
$is_msg and $is_att
$is_msg $is_att
Truth table66%2/3
A and B
A= $is_msgB= $is_att
ABresult
0X0
100
111
333 if $is_msg and $is_att;
334 22 $is_att = ( $data eq $LVL_ATTACHMENT );
335 22 ▶ redo LOOP if $is_msg or $is_att;
Branch: 1 branch
BranchTrueFalseTotal
if $is_msg or $is_att 22 0 22
Condition66%2/3
$is_msg or $is_att
l!l&&r!l&&!r
1660
MC/DC0%0/2
$is_msg or $is_att
$is_msg $is_att
Truth table66%2/3
A or B
A= $is_msgB= $is_att
ABresult
1X1
011
000
336 0 return _rtn_err( "Not a TNEF $type", $fd, $parms );
337 }
338  
339 1 ▶ print "EOF\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
340  
341 1 $self->{TN_Message} = $msg;
342 1 $self->{TN_Attachments} = \@atts;
343 1 return $self;
344 }
345  
346 0 ▶sub _debug_print {
Subroutine _debug_print: not called CC=13 SCAR=52.0
347 0 my ( $length, $att_id, $data, $parms ) = @_;
348 0 ▶ if ( $length < $parms->{debug_max_display} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length < $parms->{'debug_max_display'}) { } 0 0 0
349 0 $data = $data->data;
350 0 ▶ if ( $att_id eq $att{TnefVersion} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($att_id eq $Convert::TNEF::att{'TnefVersion'}) { } 0 0 0
elsif (substr($att_id, 2) eq $Convert::TNEF::atp{'Date'} and $length == 14) { } 0 0 0
elsif ($att_id eq $Convert::TNEF::att{'AttachRenddata'} and $length == 14) { } 0 0 0
351 0 $data = unpack( "L", $data );
352 0 print "Version: $data\n";
353 ▶ } elsif ( substr( $att_id, 2 ) eq $atp{Date} and $length == 14 ) {
Condition0%0/3
substr($att_id, 2) eq $Convert::TNEF::atp{"Date"} and $length == 14
!ll&&!rl&&r
000
MC/DC0%0/2
substr($att_id, 2) eq $Convert::TNEF::atp{"Date"} and $length == 14
substr($att_id, 2) eq $Convert::TNEF::atp{"Date"} $length == 14
Truth table0%0/3
A and B
A= substr($att_id, 2) eq $Convert::TNEF::atp{"Date"}B= $length == 14
ABresult
0X0
100
111
354 0 my ( $yr, $mo, $day, $hr, $min, $sec, $dow ) =
355 unpack( "vvvvvvv", $data );
356 0 my $date = join ":", $yr, $mo, $day, $hr, $min, $sec, $dow;
357 0 print "Date: $date\n";
358 0 print "HDate:", unpack( "H*", $data ), "\n";
359 ▶ } elsif ( $att_id eq $att{AttachRenddata} and $length == 14 ) {
Condition0%0/3
$att_id eq $Convert::TNEF::att{"AttachRenddata"} and $length == 14
!ll&&!rl&&r
000
MC/DC0%0/2
$att_id eq $Convert::TNEF::att{"AttachRenddata"} and $length == 14
$att_id eq $Convert::TNEF::att{"AttachRenddata"} $length == 14
Truth table0%0/3
A and B
A= $att_id eq $Convert::TNEF::att{"AttachRenddata"}B= $length == 14
ABresult
0X0
100
111
360 0 my ( $atyp, $ulPosition, $dxWidth, $dyHeight, $dwFlags ) =
361 unpack( "vVvvV", $data );
362 0 $data = join ":", $atyp, $ulPosition, $dxWidth, $dyHeight,
363 $dwFlags;
364 0 print "AttachRendData: $data\n";
365 } else {
366 0 print "Data:\n";
367 0 ▶ print $1, "\n" while $data =~
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /([^\r\n]{0,$parms->{"debug_max_line_size"}})\r?\n?/g and do { print $1, "\n" } 0 0 0
368 /([^\r\n]{0,$parms->{debug_max_line_size}})\r?\n?/g;
369 0 print "HData:\n";
370 0 my $hdata = unpack( "H*", $data );
371 0 ▶ print $1, "\n"
Branch: 1 branch
BranchTrueFalseTotal
$hdata =~ /(.{0,$parms->{"debug_max_line_size"}})/g and do { print $1, "\n" } 0 0 0
372 while $hdata =~ /(.{0,$parms->{debug_max_line_size}})/g;
373 }
374 } else {
375 0 ▶ my $io = $data->open("r")
Branch: 1 branch
BranchTrueFalseTotal
my $io = $data->open("r") or croak("Error opening attachment data handle: $!") 0 0 0
376 or croak "Error opening attachment data handle: $!";
377 0 my $buffer;
378 0 $io->read( $buffer, $parms->{debug_max_display} );
379 0 ▶ $io->close or croak "Error closing attachment data handle: $!";
Branch: 1 branch
BranchTrueFalseTotal
$io->close or croak("Error closing attachment data handle: $!") 0 0 0
380 0 print "Data:\n";
381 0 ▶ print $1, "\n" while $buffer =~
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ /([^\r\n]{0,$parms->{"debug_max_line_size"}})\r?\n?/gs and do { print $1, "\n" } 0 0 0
382 /([^\r\n]{0,$parms->{debug_max_line_size}})\r?\n?/sg;
383 0 print "HData:\n";
384 0 my $hdata = unpack( "H*", $buffer );
385 0 ▶ print $1, "\n"
Branch: 1 branch
BranchTrueFalseTotal
$hdata =~ /(.{0,$parms->{"debug_max_line_size"}})/g and do { print $1, "\n" } 0 0 0
386 while $hdata =~ /(.{0,$parms->{debug_max_line_size}})/g;
387 }
388 }
389  
390 24 ▶sub _build_data {
Subroutine _build_data: called CC=9 SCAR=22.8
391 24 my ( $fd, $length, $chksumref, $parms ) = @_;
392 24 my $cutoff = $parms->{output_to_core};
393 24 my $incore = do {
394 0 ▶ if ( $cutoff eq 'NONE' ) { 0 } #Everything to files
Branch: 3 branches
BranchTrueFalseTotal
if ($cutoff eq 'NONE') { } 0 24 24
elsif ($cutoff eq 'ALL') { } 0 24 24
elsif ($cutoff < $length) { } 0 24 24
395 0 elsif ( $cutoff eq 'ALL' ) { 1 } #Everything in memory
396 0 elsif ( $cutoff < $length ) { 0 } #Large items in files
397 24 else { 1 } #Everything else in memory
398 };
399  
400 # Just borrow some other objects for the attachment attribute data
401 24 ▶ my $body =
Branch: 1 branch
BranchTrueFalseTotal
$incore ? : 24 0 24
402 ($incore)
403 ? new MIME::Body::Scalar
404 : new MIME::Body::File _mk_fname($parms);
405 24 $body->binmode(1);
406 24 my $io = $body->open("w");
407 24 my $bufsiz = $parms->{buffer_size};
408 24 ▶ $bufsiz = $length if $length < $bufsiz;
Branch: 1 branch
BranchTrueFalseTotal
if $length < $bufsiz 22 2 24
409 24 my $buffer;
410 24 my $chksum = 0;
411  
412 24 ▶ while ( $length > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 0) 26 24 50
413 26 my $num_bytes = $fd->read( $buffer, $bufsiz );
414 26 ▶ return _read_err( $num_bytes, $fd, $! )
Branch: 1 branch
BranchTrueFalseTotal
unless $num_bytes == $bufsiz 0 26 26
415 unless $num_bytes == $bufsiz;
416 26 $io->print($buffer);
417 26 $chksum += unpack( "%16C*", $buffer );
418 26 $chksum %= 65536;
419 26 $length -= $bufsiz;
420 26 ▶ $bufsiz = $length if $length < $bufsiz;
Branch: 1 branch
BranchTrueFalseTotal
if $length < $bufsiz 26 0 26
421 }
422 24 $$chksumref = pack( "v", $chksum );
423 24 $io->close;
424 24 return $body;
425 }
426  
427 0 ▶sub purge {
Subroutine purge: not called CC=6 SCAR=37.4
Pod undocumented
428 0 my $self = shift;
429 0 my $msg = $self->{TN_Message};
430 0 my @atts = $self->attachments;
431 0 for ( keys %$msg ) {
432 0 ▶ $msg->{$_}->purge if exists $att{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Convert::TNEF::att{$_} 0 0 0
433 }
434 0 for my $attch (@atts) {
435 0 for ( keys %$attch ) {
436 0 ▶ $attch->{$_}->purge if exists $att{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Convert::TNEF::att{$_} 0 0 0
437 }
438 }
439 }
440  
441 1 ▶sub message {
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
442 1 my $self = shift;
443 1 $self->{TN_Message};
444 }
445  
446 1 ▶sub attachments {
Subroutine attachments: called CC=2 SCAR=7.6
Pod undocumented
447 1 my $self = shift;
448 1 ▶ return @{ $self->{TN_Attachments} } if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
449 0 $self->{TN_Attachments};
450 }
451  
452 # This is for Messages or Attachments
453 # since they are essentially the same thing except
454 # for the leading attribute code
455 package Convert::TNEF::Data;
456  
457 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
458 3 my $proto = shift;
459 3 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
460 3 my $self = {};
461 3 $self->{TN_Size} = {};
462 3 bless $self, $class;
463 }
464  
465 3 ▶sub data {
Subroutine data: called CC=3 SCAR=11.4
466 3 my $self = shift;
467 3 ▶ my $attr = shift || 'AttachData';
Condition100%2/2
shift() || 'AttachData'
l!l
21
MC/DC100%1/1
shift() || 'AttachData'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
468 3 ▶ return $self->{$attr} && $self->{$attr}->as_string;
Condition33%1/3
$self->{$attr} && $self->{$attr}->as_string
!ll&&!rl&&r
003
MC/DC0%0/2
$self->{$attr} && $self->{$attr}->as_string
$self->{$attr} $self->{$attr}->as_string
Truth table33%1/3
A && B
A= $self->{$attr}B= $self->{$attr}->as_string
ABresult
0X0
100
111
469 }
470  
471 1 ▶sub name {
Subroutine name: called CC=4 SCAR=15.2
472 1 my $self = shift;
473 1 ▶ my $attr = shift || 'AttachTitle';
Condition50%1/2
shift() || 'AttachTitle'
l!l
01
MC/DC0%0/1
shift() || 'AttachTitle'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
474 1 ▶ my $name = $self->{$attr} && $self->{$attr}->data;
Condition33%1/3
$self->{$attr} && $self->{$attr}->data
!ll&&!rl&&r
001
MC/DC0%0/2
$self->{$attr} && $self->{$attr}->data
$self->{$attr} $self->{$attr}->data
Truth table33%1/3
A && B
A= $self->{$attr}B= $self->{$attr}->data
ABresult
0X0
100
111
475 1 ▶ $name =~ s/\x00+$// if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 1 0 1
476 1 return $name;
477 }
478  
479 # Try to get the long filename out of the
480 # 'Attachment' attribute.
481 1 ▶sub longname {
Subroutine longname: called CC=6 SCAR=19.2
482 1 my $self = shift;
483  
484 1 my $data = $self->data("Attachment");
485 1 ▶ return unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 1 1
486 1 my $pos = index( $data, pack( "H*", "1e00013001" ) );
487 1 ▶ $pos = index( $data, pack( "H*", "1e00073701" ) ) if ($pos < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 1 1
488 1 ▶ return $self->name unless $pos >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $pos >= 0 0 1 1
489 1 my $len = unpack( "V", substr( $data, $pos + 8, 4 ) );
490 1 my $longname = substr( $data, $pos + 12, $len );
491 1 ▶ $longname =~ s/\x00+$// if $longname;
Branch: 1 branch
BranchTrueFalseTotal
if $longname 1 0 1
492 1 ▶ return $longname || $self->name;
Condition33%1/3
$longname || $self->name
l!l&&r!l&&!r
100
MC/DC0%0/2
$longname || $self->name
$longname $self->name
Truth table33%1/3
A || B
A= $longnameB= $self->name
ABresult
1X1
011
000
493 }
494  
495 24 ▶sub datahandle {
Subroutine datahandle: called CC=4 SCAR=14.6
496 24 my $self = shift;
497 24 ▶ my $attr = shift || 'AttachData';
Condition50%1/2
shift() || 'AttachData'
l!l
240
MC/DC0%0/1
shift() || 'AttachData'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
498 24 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 24 0 24
499 24 ▶ $self->size( $attr, shift ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 24 0 24
500 24 return $self->{$attr};
501 }
502  
503 24 ▶sub size {
Subroutine size: called CC=3 SCAR=11.4
504 24 my $self = shift;
505 24 ▶ my $attr = shift || 'AttachData';
Condition50%1/2
shift() || 'AttachData'
l!l
240
MC/DC0%0/1
shift() || 'AttachData'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
506 24 ▶ $self->{TN_Size}->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 24 0 24
507 24 return $self->{TN_Size}->{$attr};
508 }
509  
510 # Autoload methods go after =cut, and are processed by the autosplit program.
511  
512 1 1;
513 __END__
↑ Summary