blib/lib/Email/Outlook/Message/Attachment.pm

filter: Statementstmt 54.4% 37 / 68 Branchbran 20.0% 2 / 10 Conditioncond 58.3% 7 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 54.5% 60 / 110 CC 14 SCAR 32.5
CC
14
Cov
51%
_process_subdirectory
72.0
new
5.1
to_email_mime
3.1
CRAP 25.8
↑ Summary blib/lib/Email/Outlook/Message/Base.pm »
1 package Email::Outlook::Message::Attachment;
2 =head1 NAME
3  
4 Email::Outlook::Message::Attachment - Handle attachment data in .msg files
5  
6 =head1 DESCRIPTION
7  
8 This is an internal module of Email::Outlook::Message. It is a subclass of
9 Email::Outlook::Message::Base.
10  
11 =head1 METHODS
12  
13 =over 8
14  
15 =item B<new($pps, $verbosity)>
16  
17 Create a new attachment object, using $pps as data source. Overrides the base
18 method by setting some default values.
19  
20 =item B<to_email_mime()>
21  
22 Convert the attachment to an Email::MIME object.
23  
24 =back
25  
26 =head1 AUTHOR
27  
28 Matijs van Zuijlen, C<matijs@matijs.net>
29  
30 =head1 COPYRIGHT AND LICENSE
31  
32 Copyright 2002--2020 by Matijs van Zuijlen
33  
34 This module is free software; you can redistribute it and/or modify
35 it under the same terms as Perl itself.
36  
37 =cut
38 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 $VERSION = "0.920";
43 9 ▶use Email::MIME::ContentType;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 9 ▶use base 'Email::Outlook::Message::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 9 our $MAP_ATTACHMENT_FILE = {
47 '3701' => "DATA", # Data
48 '3704' => "SHORTNAME", # Short file name
49 '3707' => "LONGNAME", # Long file name
50 '370E' => "MIMETYPE", # mime type
51 '3712' => "CONTENTID", # content-id
52 '3716' => "DISPOSITION", # disposition
53 };
54  
55 sub new {
56 2 ▶ my ($class, $pps, $verbosity) = @_;
Subroutine new: called CC=5 SCAR=16.4
Pod documented
57 2 my $self = $class->SUPER::new($pps, $verbosity);
58 2 bless $self, $class;
59 2 ▶ $self->{MIMETYPE} ||= 'application/octet-stream';
Condition50%1/2
$self->{"MIMETYPE"} ||= "application/octet-stream"
l!l
20
MC/DC0%0/1
$self->{"MIMETYPE"} ||= "application/octet-stream"
$self->{"MIMETYPE"}
Truth table50%1/2
A
A= $self->{"MIMETYPE"}
Aresult
11
00
60 2 ▶ $self->{ENCODING} ||= 'base64';
Condition50%1/2
$self->{"ENCODING"} ||= "base64"
l!l
02
MC/DC0%0/1
$self->{"ENCODING"} ||= "base64"
$self->{"ENCODING"}
Truth table50%1/2
A
A= $self->{"ENCODING"}
Aresult
11
00
61 2 ▶ $self->{DISPOSITION} ||= 'attachment';
Condition50%1/2
$self->{"DISPOSITION"} ||= "attachment"
l!l
02
MC/DC0%0/1
$self->{"DISPOSITION"} ||= "attachment"
$self->{"DISPOSITION"}
Truth table50%1/2
A
A= $self->{"DISPOSITION"}
Aresult
11
00
62 2 ▶ if ($self->{MIMETYPE} eq 'multipart/signed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MIMETYPE"} eq "multipart/signed") 1 1 2
63 1 $self->{ENCODING} = '8bit';
64 }
65 2 return $self;
66 }
67  
68 sub to_email_mime {
69 2 ▶ my $self = shift;
Subroutine to_email_mime: called CC=3 SCAR=11.2
Pod documented
70  
71 2 my $mt = parse_content_type($self->{MIMETYPE});
72 my $m = Email::MIME->create(
73 attributes => {
74 content_type => "$mt->{discrete}/$mt->{composite}",
75 2 ▶ %{$mt->{attributes}},
Condition66%4/6
$self->{'LONGNAME'} || $self->{'SHORTNAME'}
l!l&&r!l&&!r
101
$self->{'LONGNAME'} || $self->{'LONGNAME'}
l!l&&r!l&&!r
101
MC/DC50%1/2
$self->{'LONGNAME'} || $self->{'SHORTNAME'}
$self->{'LONGNAME'} $self->{'SHORTNAME'}
MC/DC50%1/2
$self->{'LONGNAME'} || $self->{'LONGNAME'}
$self->{'LONGNAME'} $self->{'LONGNAME'}
Truth table66%2/3
A || B
A= $self->{'LONGNAME'}B= $self->{'SHORTNAME'}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $self->{'LONGNAME'}B= $self->{'LONGNAME'}
ABresult
1X1
011
000
76 encoding => $self->{ENCODING},
77 filename => $self->{LONGNAME} || $self->{SHORTNAME},
78 name => $self->{LONGNAME} || $self->{LONGNAME},
79 disposition => $self->{DISPOSITION},
80 },
81 header => [ 'Content-ID' => $self->{CONTENTID} ],
82 2 body => $self->{DATA});
83 2 return $m
84 }
85  
86 sub _property_map {
87 2 ▶ return $MAP_ATTACHMENT_FILE;
Subroutine _property_map: called CC=1 SCAR=0.0
88 }
89  
90 sub _process_subdirectory {
91 0 ▶ my ($self, $pps) = @_;
Subroutine _process_subdirectory: not called CC=8 SCAR=42.8
92 0 my $name = $self->_get_pps_name($pps);
93 0 my ($property, $encoding) = $self->_parse_item_name($name);
94  
95 0 ▶ if ($property eq '3701') { # Nested msg file
Branch: 1 branch
BranchTrueFalseTotal
if ($property eq '3701') { } 0 0 0
96 0 my $is_msg = 1;
97 0 foreach my $child (@{$pps->{Child}}) {
98 0 ▶ unless ($self->_get_pps_name($child) =~ / ^ ( __recip | __attach
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_get_pps_name($child) =~ / ^ ( __recip | __attach | __substg1 | __nameid | __properties ) /x) 0 0 0
99 | __substg1 | __nameid | __properties ) /x
100 ) {
101 0 $is_msg = 0;
102 0 last;
103 }
104 }
105 0 ▶ if ($is_msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_msg) { } 0 0 0
106 0 my $msgp = Email::Outlook::Message->_empty_new();
107 0 $msgp->_set_verbosity($self->{VERBOSE});
108 0 $msgp->_process_pps($pps);
109  
110 0 $self->{DATA} = $msgp->to_email_mime->as_string;
111 0 $self->{MIMETYPE} = 'message/rfc822';
112 0 $self->{ENCODING} = '8bit';
113 } else {
114 0 foreach my $child (@{$pps->{Child}}) {
115 0 ▶ if (eval { $child->isa('OLE::Storage_Lite::PPS::File')}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $child->isa("OLE::Storage_Lite::PPS::File") } }) 0 0 0
116 0 foreach my $prop ("Time1st", "Time2nd") {
117 0 $child->{$prop} = undef;
118 }
119 }
120 }
121 my $nPps = OLE::Storage_Lite::PPS::Root->new(
122 0 $pps->{Time1st}, $pps->{Time2nd}, $pps->{Child});
123 0 my $data;
124 0 my $io = IO::String->new($data);
125 0 binmode($io);
126 0 $nPps->save($io, 1);
127 0 $self->{DATA} = $data;
128 }
129 } else {
130 0 $self->_warn_about_unknown_directory($pps);
131 }
132 0 return;
133 }
134  
135 2 ▶sub _property_stream_header_length { return 8; }
Subroutine _property_stream_header_length: called CC=1 SCAR=0.0
136  
137 9 1;
↑ Summary blib/lib/Email/Outlook/Message/Base.pm »