| 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--2014 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 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | use Email::MIME::ContentType; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | use base 'Email::Outlook::Message::Base'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 8 | our $MAP_ATTACHMENT_FILE = { | |||||||||||||||||||||||||||||||||||||
| 45 | '3701' => "DATA", # Data | ||||||||||||||||||||||||||||||||||||||
| 46 | '3704' => "SHORTNAME", # Short file name | ||||||||||||||||||||||||||||||||||||||
| 47 | '3707' => "LONGNAME", # Long file name | ||||||||||||||||||||||||||||||||||||||
| 48 | '370E' => "MIMETYPE", # mime type | ||||||||||||||||||||||||||||||||||||||
| 49 | '3712' => "CONTENTID", # content-id | ||||||||||||||||||||||||||||||||||||||
| 50 | '3716' => "DISPOSITION", # disposition | ||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my ($class, $pps, $verbosity) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my $self = $class->SUPER::new($pps, $verbosity); | |||||||||||||||||||||||||||||||||||||
| 56 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | $self->{MIMETYPE} ||= 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"MIMETYPE"} ||= "application/octet-stream"
MC/DC0%0/1
$self->{"MIMETYPE"} ||= "application/octet-stream"
$self->{"MIMETYPE"}
Truth table50%1/2
A
A= $self->{"MIMETYPE"}
| |||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | $self->{ENCODING} ||= 'base64'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"ENCODING"} ||= "base64"
MC/DC0%0/1
$self->{"ENCODING"} ||= "base64"
$self->{"ENCODING"}
Truth table50%1/2
A
A= $self->{"ENCODING"}
| |||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | $self->{DISPOSITION} ||= 'attachment'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"DISPOSITION"} ||= "attachment"
MC/DC0%0/1
$self->{"DISPOSITION"} ||= "attachment"
$self->{"DISPOSITION"}
Truth table50%1/2
A
A= $self->{"DISPOSITION"}
| |||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ($self->{MIMETYPE} eq 'multipart/signed') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $self->{ENCODING} = '8bit'; | |||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | sub to_email_mime { | ||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
to_email_mime: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my $mt = parse_content_type($self->{MIMETYPE}); | |||||||||||||||||||||||||||||||||||||
| 70 | my $m = Email::MIME->create( | ||||||||||||||||||||||||||||||||||||||
| 71 | attributes => { | ||||||||||||||||||||||||||||||||||||||
| 72 | content_type => "$mt->{discrete}/$mt->{composite}", | ||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | %{$mt->{attributes}}, | ||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{'LONGNAME'} || $self->{'SHORTNAME'}
$self->{'LONGNAME'} || $self->{'LONGNAME'}
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'}
Truth table66%2/3
A || B
A= $self->{'LONGNAME'}B= $self->{'LONGNAME'}
| |||||||||||||||||||||||||||||||||||||||
| 74 | encoding => $self->{ENCODING}, | ||||||||||||||||||||||||||||||||||||||
| 75 | filename => $self->{LONGNAME} || $self->{SHORTNAME}, | ||||||||||||||||||||||||||||||||||||||
| 76 | name => $self->{LONGNAME} || $self->{LONGNAME}, | ||||||||||||||||||||||||||||||||||||||
| 77 | disposition => $self->{DISPOSITION}, | ||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||
| 79 | header => [ 'Content-ID' => $self->{CONTENTID} ], | ||||||||||||||||||||||||||||||||||||||
| 80 | 2 | body => $self->{DATA}); | |||||||||||||||||||||||||||||||||||||
| 81 | 2 | return $m | |||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | sub _property_map { | ||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | return $MAP_ATTACHMENT_FILE; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_property_map: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | sub _process_subdirectory { | ||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($self, $pps) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_subdirectory: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $name = $self->_get_pps_name($pps); | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ($property, $encoding) = $self->_parse_item_name($name); | |||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($property eq '3701') { # Nested msg file | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $is_msg = 1; | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | foreach my $child (@{$pps->{Child}}) { | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | unless ($self->_get_pps_name($child) =~ / ^ ( __recip | __attach | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 97 | | __substg1 | __nameid | __properties ) /x | ||||||||||||||||||||||||||||||||||||||
| 98 | ) { | ||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $is_msg = 0; | |||||||||||||||||||||||||||||||||||||
| 100 | 0 | last; | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($is_msg) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $msgp = Email::Outlook::Message->_empty_new(); | |||||||||||||||||||||||||||||||||||||
| 105 | 0 | $msgp->_set_verbosity($self->{VERBOSE}); | |||||||||||||||||||||||||||||||||||||
| 106 | 0 | $msgp->_process_pps($pps); | |||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->{DATA} = $msgp->to_email_mime->as_string; | |||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->{MIMETYPE} = 'message/rfc822'; | |||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{ENCODING} = '8bit'; | |||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $child (@{$pps->{Child}}) { | |||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (eval { $child->isa('OLE::Storage_Lite::PPS::File')}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 114 | 0 | foreach my $prop ("Time1st", "Time2nd") { | |||||||||||||||||||||||||||||||||||||
| 115 | 0 | $child->{$prop} = undef; | |||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||
| 119 | my $nPps = OLE::Storage_Lite::PPS::Root->new( | ||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $pps->{Time1st}, $pps->{Time2nd}, $pps->{Child}); | |||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $io = IO::String->new($data); | |||||||||||||||||||||||||||||||||||||
| 123 | 0 | binmode($io); | |||||||||||||||||||||||||||||||||||||
| 124 | 0 | $nPps->save($io, 1); | |||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->{DATA} = $data; | |||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->_warn_about_unknown_directory($pps); | |||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | sub _property_stream_header_length { return 8; } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_property_stream_header_length: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | 8 | 1; | |||||||||||||||||||||||||||||||||||||