| 1 | package Email::Outlook::Message; | ||||||||||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | Email::Outlook::Message.pm - Read Outlook .msg files | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use Email::Outlook::Message; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | my $msg = new Email::Outlook::Message $filename, $verbose; | ||||||||||||||||||||||||||||
| 11 | my $mime = $msg->to_email_mime; | ||||||||||||||||||||||||||||
| 12 | $mime->as_string; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Parses .msg message files as produced by Microsoft Outlook. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =over 8 | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =item B<new($msg, $verbose)> | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Parse the file pointed at by $msg. Set $verbose to a true value to | ||||||||||||||||||||||||||||
| 25 | print information about skipped parts of the .msg file on STDERR. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =item B<to_email_mime> | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Output result as an Email::MIME object. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =back | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 BUGS | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Not all data that is in the .msg file is converted. There are some | ||||||||||||||||||||||||||||
| 36 | parts whose meaning escapes me, although more documentation on MIME | ||||||||||||||||||||||||||||
| 37 | properties is available these days. Other parts do not make sense outside | ||||||||||||||||||||||||||||
| 38 | of Outlook and Exchange. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | GPG signed mail is not processed correctly. Neither are attachments of | ||||||||||||||||||||||||||||
| 41 | type 'appledoublefile'. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | It would be nice if we could write .MSG files too, but that will require | ||||||||||||||||||||||||||||
| 44 | quite a big rewrite. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Matijs van Zuijlen, C<matijs@matijs.net> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Copyright 2002--2014 by Matijs van Zuijlen | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | This module is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 55 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 8 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 8 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 8 | $VERSION = "0.919"; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | ▶ | use Email::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 8 | ▶ | use Email::MIME::Creator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 8 | ▶ | use Email::Outlook::Message::AddressInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 8 | ▶ | use Email::Outlook::Message::Attachment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 8 | ▶ | use base 'Email::Outlook::Message::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | our $skipheaders = { | ||||||||||||||||||||||||||||
| 72 | 8 | map { uc($_) => 1 } | |||||||||||||||||||||||||||
| 73 | "MIME-Version", | ||||||||||||||||||||||||||||
| 74 | "Content-Type", | ||||||||||||||||||||||||||||
| 75 | "Content-Transfer-Encoding", | ||||||||||||||||||||||||||||
| 76 | "X-Mailer", | ||||||||||||||||||||||||||||
| 77 | "X-Msgconvert", | ||||||||||||||||||||||||||||
| 78 | "X-MS-Tnef-Correlator", | ||||||||||||||||||||||||||||
| 79 | "X-MS-Has-Attach" | ||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 8 | our $MAP_SUBITEM_FILE = { | |||||||||||||||||||||||||||
| 83 | '1000' => "BODY_PLAIN", # Body | ||||||||||||||||||||||||||||
| 84 | '1009' => "BODY_RTF", # Compressed-RTF version of body | ||||||||||||||||||||||||||||
| 85 | '1013' => "BODY_HTML", # HTML Version of body | ||||||||||||||||||||||||||||
| 86 | '0037' => "SUBJECT", # Subject | ||||||||||||||||||||||||||||
| 87 | '0047' => "SUBMISSION_ID", # Seems to contain the date | ||||||||||||||||||||||||||||
| 88 | '007D' => "HEAD", # Full headers | ||||||||||||||||||||||||||||
| 89 | '0C1A' => "FROM", # From: Name | ||||||||||||||||||||||||||||
| 90 | '0C1E' => "FROM_ADDR_TYPE", # From: Address type | ||||||||||||||||||||||||||||
| 91 | '0C1F' => "FROM_ADDR", # From: Address | ||||||||||||||||||||||||||||
| 92 | '0E04' => "TO", # To: Names | ||||||||||||||||||||||||||||
| 93 | '0E03' => "CC", # Cc: Names | ||||||||||||||||||||||||||||
| 94 | '1035' => "MESSAGEID", # Message-Id | ||||||||||||||||||||||||||||
| 95 | '1039' => "REFERENCES", # References: Header | ||||||||||||||||||||||||||||
| 96 | '1042' => "INREPLYTO", # In reply to Message-Id | ||||||||||||||||||||||||||||
| 97 | '3007' => 'DATE2ND', # Creation Time | ||||||||||||||||||||||||||||
| 98 | '0039' => 'DATE1ST', # Outlook sent date | ||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # | ||||||||||||||||||||||||||||
| 102 | # Main body of module | ||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub new { | ||||||||||||||||||||||||||||
| 106 | 6 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 6 | ▶ | my $file = shift or croak "File name is required parameter"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 5 | my $verbose = shift; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | my $self = $class->_empty_new; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 5 | $self->{EMBEDDED} = 0; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 5 | my $msg = OLE::Storage_Lite->new($file); | |||||||||||||||||||||||||||
| 115 | 5 | my $pps = $msg->getPpsTree(1); | |||||||||||||||||||||||||||
| 116 | 5 | ▶ | $pps or croak "Parsing $file as OLE file failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 5 | $self->_set_verbosity($verbose); | |||||||||||||||||||||||||||
| 118 | # TODO: Use separate object as parser? | ||||||||||||||||||||||||||||
| 119 | 5 | $self->_process_pps($pps); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 5 | return $self; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub _empty_new { | ||||||||||||||||||||||||||||
| 125 | 6 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_empty_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 6 | return bless { | |||||||||||||||||||||||||||
| 128 | ADDRESSES => [], ATTACHMENTS => [], FROM_ADDR_TYPE => "", | ||||||||||||||||||||||||||||
| 129 | VERBOSE => 0, EMBEDDED => 1 | ||||||||||||||||||||||||||||
| 130 | }, $class; | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub to_email_mime { | ||||||||||||||||||||||||||||
| 134 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
to_email_mime: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 9 | my $bodymime; | |||||||||||||||||||||||||||
| 137 | my $mime; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 9 | my @parts; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 9 | ▶ | if ($self->{BODY_PLAIN}) { push(@parts, $self->_create_mime_plain_body()); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 9 | ▶ | if ($self->{BODY_HTML}) { push(@parts, $self->_create_mime_html_body()); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 9 | ▶ | if ($self->{BODY_RTF}) { push(@parts, $self->_create_mime_rtf_body()); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 9 | ▶ | if ((scalar @parts) > 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 146 | 6 | for (@parts) { $self->_clean_part_header($_) }; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 6 | $bodymime = Email::MIME->create( | |||||||||||||||||||||||||||
| 149 | attributes => { | ||||||||||||||||||||||||||||
| 150 | content_type => "multipart/alternative", | ||||||||||||||||||||||||||||
| 151 | encoding => "8bit", | ||||||||||||||||||||||||||||
| 152 | }, | ||||||||||||||||||||||||||||
| 153 | parts => \@parts | ||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||
| 155 | } elsif ((@parts) == 1) { | ||||||||||||||||||||||||||||
| 156 | 2 | $bodymime = $parts[0]; | |||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||
| 158 | 1 | $bodymime = $self->_create_mime_plain_body(); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 9 | ▶ | if (@{$self->{ATTACHMENTS}}>0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 2 | $self->_clean_part_header($bodymime); | |||||||||||||||||||||||||||
| 163 | 2 | my $mult = Email::MIME->create( | |||||||||||||||||||||||||||
| 164 | attributes => { | ||||||||||||||||||||||||||||
| 165 | content_type => "multipart/mixed", | ||||||||||||||||||||||||||||
| 166 | encoding => "8bit", | ||||||||||||||||||||||||||||
| 167 | }, | ||||||||||||||||||||||||||||
| 168 | parts => [$bodymime], | ||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||
| 170 | 2 | foreach my $att (@{$self->{ATTACHMENTS}}) { | |||||||||||||||||||||||||||
| 171 | 2 | $self->_SaveAttachment($mult, $att); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 2 | $mime = $mult; | |||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||
| 175 | 7 | $mime = $bodymime; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | #$mime->header_set('Date', undef); | ||||||||||||||||||||||||||||
| 179 | 9 | $self->_SetHeaderFields($mime); | |||||||||||||||||||||||||||
| 180 | 9 | $self->_copy_header_data($mime); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 9 | return $mime; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||||||||
| 186 | # Below are functions that walk the PPS tree. This is simply a tree walk. | ||||||||||||||||||||||||||||
| 187 | # It's not really recursive (except when an attachment contains a .msg | ||||||||||||||||||||||||||||
| 188 | # file), since the tree is shallow (max. 1 subdirectory deep). | ||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||
| 190 | # The structure is as follows: | ||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||
| 192 | # Root | ||||||||||||||||||||||||||||
| 193 | # Items with properties of the e-mail | ||||||||||||||||||||||||||||
| 194 | # Dirs containting adresses | ||||||||||||||||||||||||||||
| 195 | # Items with properties of the address | ||||||||||||||||||||||||||||
| 196 | # Dirs containing Attachments | ||||||||||||||||||||||||||||
| 197 | # Items with properties of the attachment (including its data) | ||||||||||||||||||||||||||||
| 198 | # Dir that is itself a .msg file (if the attachment is an email). | ||||||||||||||||||||||||||||
| 199 | # | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub _property_map { | ||||||||||||||||||||||||||||
| 202 | 5 | ▶ | return $MAP_SUBITEM_FILE; | ||||||||||||||||||||||||||
|
Subroutine
_property_map: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||
| 206 | # Process a subdirectory. This is either an address or an attachment. | ||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||
| 208 | sub _process_subdirectory { | ||||||||||||||||||||||||||||
| 209 | 12 | ▶ | my ($self, $pps) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_process_subdirectory: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 12 | $self->_extract_ole_date($pps); | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 12 | my $name = $self->_get_pps_name($pps); | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 12 | ▶ | if ($name =~ '__recip_version1 0_ ') { # Address of one recipient | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 216 | 5 | $self->_process_address($pps); | |||||||||||||||||||||||||||
| 217 | } elsif ($name =~ '__attach_version1 0_ ') { # Attachment | ||||||||||||||||||||||||||||
| 218 | 2 | $self->_process_attachment($pps); | |||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||
| 220 | 5 | $self->_warn_about_unknown_directory($pps); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 12 | return; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # | ||||||||||||||||||||||||||||
| 226 | # Process a subdirectory that contains an email address. | ||||||||||||||||||||||||||||
| 227 | # | ||||||||||||||||||||||||||||
| 228 | sub _process_address { | ||||||||||||||||||||||||||||
| 229 | 5 | ▶ | my ($self, $pps) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_process_address: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | my $addr_info = Email::Outlook::Message::AddressInfo->new($pps, | ||||||||||||||||||||||||||||
| 232 | 5 | $self->{VERBOSE}); | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 5 | push @{$self->{ADDRESSES}}, $addr_info; | |||||||||||||||||||||||||||
| 235 | 5 | return; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # | ||||||||||||||||||||||||||||
| 239 | # Process a subdirectory that contains an attachment. | ||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||
| 241 | sub _process_attachment { | ||||||||||||||||||||||||||||
| 242 | 2 | ▶ | my ($self, $pps) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_process_attachment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | my $attachment = Email::Outlook::Message::Attachment->new($pps, | ||||||||||||||||||||||||||||
| 245 | 2 | $self->{VERBOSE}); | |||||||||||||||||||||||||||
| 246 | 2 | push @{$self->{ATTACHMENTS}}, $attachment; | |||||||||||||||||||||||||||
| 247 | 2 | return; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # | ||||||||||||||||||||||||||||
| 251 | # Header length of the property stream depends on whether the Message | ||||||||||||||||||||||||||||
| 252 | # object is embedded or not. | ||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||
| 254 | sub _property_stream_header_length { | ||||||||||||||||||||||||||||
| 255 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_property_stream_header_length: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 256 | 5 | ▶ | return ($self->{EMBEDDED} ? 24 : 32) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # | ||||||||||||||||||||||||||||
| 260 | # Helper functions | ||||||||||||||||||||||||||||
| 261 | # | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||
| 264 | # Extract time stamp of this OLE item (this is in GMT) | ||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||
| 266 | sub _extract_ole_date { | ||||||||||||||||||||||||||||
| 267 | 12 | ▶ | my ($self, $pps) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_extract_ole_date: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||
| 268 | 12 | ▶ | unless (defined ($self->{OLEDATE})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | # Make Date | ||||||||||||||||||||||||||||
| 270 | 5 | my $datearr; | |||||||||||||||||||||||||||
| 271 | 5 | $datearr = $pps->{Time2nd}; | |||||||||||||||||||||||||||
| 272 | 5 | ▶ | $datearr = $pps->{Time1st} unless $datearr and $datearr->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$datearr and $datearr->[0]
MC/DC0%0/2
$datearr and $datearr->[0]
$datearr
$datearr->[0]
Truth table33%1/3
A and B
A= $datearrB= $datearr->[0]
| |||||||||||||||||||||||||||||
| 273 | 5 | ▶ | $self->{OLEDATE} = $self->_format_date($datearr) if $datearr and $datearr->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$datearr and $datearr->[0]
MC/DC0%0/2
$datearr and $datearr->[0]
$datearr
$datearr->[0]
Truth table33%1/3
A and B
A= $datearrB= $datearr->[0]
| |||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 12 | return; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # If we didn't get the date from the original header data, we may be able | ||||||||||||||||||||||||||||
| 279 | # to get it from the SUBMISSION_ID: | ||||||||||||||||||||||||||||
| 280 | # It seems to have the format of a semicolon-separated list of key=value | ||||||||||||||||||||||||||||
| 281 | # pairs. The key l has a value with the format: | ||||||||||||||||||||||||||||
| 282 | # <SERVER>-<DATETIME>Z-<NUMBER>, where DATETIME is the date and time (gmt) | ||||||||||||||||||||||||||||
| 283 | # in the format YYMMDDHHMMSS. | ||||||||||||||||||||||||||||
| 284 | sub _submission_id_date { | ||||||||||||||||||||||||||||
| 285 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_submission_id_date: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 10 | ▶ | my $submission_id = $self->{SUBMISSION_ID} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 5 | ▶ | $submission_id =~ m/ l=.*- (\d\d) (\d\d) (\d\d) (\d\d) (\d\d) (\d\d) Z-.* /x | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | or return; | ||||||||||||||||||||||||||||
| 290 | 5 | my $year = $1; | |||||||||||||||||||||||||||
| 291 | 5 | ▶ | $year += 100 if $year < 20; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 5 | return $self->_format_date([$6,$5,$4,$3,$2-1,$year]); | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | sub _SaveAttachment { | ||||||||||||||||||||||||||||
| 296 | 2 | ▶ | my ($self, $mime, $att) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_SaveAttachment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 2 | my $m = $att->to_email_mime; | |||||||||||||||||||||||||||
| 299 | 2 | $self->_clean_part_header($m); | |||||||||||||||||||||||||||
| 300 | 2 | $mime->parts_add([$m]); | |||||||||||||||||||||||||||
| 301 | 2 | return; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # Set header fields | ||||||||||||||||||||||||||||
| 305 | sub _AddHeaderField { | ||||||||||||||||||||||||||||
| 306 | 99 | ▶ | my ($self, $mime, $fieldname, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_AddHeaderField: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | #my $oldvalue = $mime->header($fieldname); | ||||||||||||||||||||||||||||
| 309 | #return if $oldvalue; | ||||||||||||||||||||||||||||
| 310 | 99 | ▶ | $mime->header_set($fieldname, $value) if $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 99 | return; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | sub _Address { | ||||||||||||||||||||||||||||
| 315 | 9 | ▶ | my ($self, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_Address: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 9 | ▶ | my $result = $self->{$tag} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{$tag} || ''
MC/DC100%1/1
$self->{$tag} || ''
$self->{$tag}
Truth table100%2/2
A
A= $self->{$tag}
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 9 | ▶ | my $address = $self->{$tag . "_ADDR"} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$$self{$tag . '_ADDR'} || ''
MC/DC100%1/1
$$self{$tag . '_ADDR'} || ''
$$self{$tag . '_ADDR'}
Truth table100%2/2
A
A= $$self{$tag . '_ADDR'}
| |||||||||||||||||||||||||||||
| 320 | 9 | ▶ | if ($address) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 2 | ▶ | $result .= " " if $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 2 | $result .= "<$address>"; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 9 | return $result; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # Find SMTP addresses for the given list of names | ||||||||||||||||||||||||||||
| 329 | sub _expand_address_list { | ||||||||||||||||||||||||||||
| 330 | 18 | ▶ | my ($self, $names) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_expand_address_list: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 18 | ▶ | return "" unless defined $names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 10 | my @namelist = split / ; [ ]* /x, $names; | |||||||||||||||||||||||||||
| 335 | 10 | my @result; | |||||||||||||||||||||||||||
| 336 | 10 | name: foreach my $name (@namelist) { | |||||||||||||||||||||||||||
| 337 | 5 | my $addresstext = $self->_find_name_in_addresspool($name); | |||||||||||||||||||||||||||
| 338 | 5 | ▶ | if ($addresstext) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 5 | push @result, $addresstext; | |||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||
| 341 | 0 | push @result, $name; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | 10 | return join ", ", @result; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | sub _find_name_in_addresspool { | ||||||||||||||||||||||||||||
| 348 | 5 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_find_name_in_addresspool: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 5 | my $addresspool = $self->{ADDRESSES}; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 5 | foreach my $address (@{$addresspool}) { | |||||||||||||||||||||||||||
| 353 | 5 | ▶ | if ($name eq $address->name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 5 | return $address->display_address; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 0 | return; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | # TODO: Don't really want to need this! | ||||||||||||||||||||||||||||
| 361 | sub _clean_part_header { | ||||||||||||||||||||||||||||
| 362 | 16 | ▶ | my ($self, $part) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_clean_part_header: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 363 | 16 | $part->header_set('Date'); | |||||||||||||||||||||||||||
| 364 | 16 | ▶ | unless ($part->content_type =~ m{ ^ multipart / }x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 13 | $part->header_set('MIME-Version') | |||||||||||||||||||||||||||
| 366 | }; | ||||||||||||||||||||||||||||
| 367 | 16 | return; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | sub _create_mime_plain_body { | ||||||||||||||||||||||||||||
| 371 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_mime_plain_body: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 372 | return Email::MIME->create( | ||||||||||||||||||||||||||||
| 373 | attributes => { | ||||||||||||||||||||||||||||
| 374 | content_type => "text/plain", | ||||||||||||||||||||||||||||
| 375 | charset => "UTF-8", | ||||||||||||||||||||||||||||
| 376 | disposition => "inline", | ||||||||||||||||||||||||||||
| 377 | encoding => "8bit", | ||||||||||||||||||||||||||||
| 378 | }, | ||||||||||||||||||||||||||||
| 379 | body => $self->{BODY_PLAIN} | ||||||||||||||||||||||||||||
| 380 | 8 | ); | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | sub _create_mime_html_body { | ||||||||||||||||||||||||||||
| 384 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_mime_html_body: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 385 | return Email::MIME->create( | ||||||||||||||||||||||||||||
| 386 | attributes => { | ||||||||||||||||||||||||||||
| 387 | content_type => "text/html", | ||||||||||||||||||||||||||||
| 388 | disposition => "inline", | ||||||||||||||||||||||||||||
| 389 | encoding => "8bit", | ||||||||||||||||||||||||||||
| 390 | }, | ||||||||||||||||||||||||||||
| 391 | body => $self->{BODY_HTML} | ||||||||||||||||||||||||||||
| 392 | 2 | ); | |||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | # Implementation based on the information in | ||||||||||||||||||||||||||||
| 396 | # http://www.freeutils.net/source/jtnef/rtfcompressed.jsp, | ||||||||||||||||||||||||||||
| 397 | # and the implementation in tnef version 1.4.5. | ||||||||||||||||||||||||||||
| 398 | 8 | my $MAGIC_COMPRESSED_RTF = 0x75465a4c; | |||||||||||||||||||||||||||
| 399 | 8 | my $MAGIC_UNCOMPRESSED_RTF = 0x414c454d; | |||||||||||||||||||||||||||
| 400 | 8 | my $BASE_BUFFER = | |||||||||||||||||||||||||||
| 401 | "{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman " | ||||||||||||||||||||||||||||
| 402 | . "\\fswiss \\fmodern \\fscript \\fdecor MS Sans SerifSymbolArial" | ||||||||||||||||||||||||||||
| 403 | . "Times New RomanCourier{\\colortbl\\red0\\green0\\blue0\n\r\\par " | ||||||||||||||||||||||||||||
| 404 | . "\\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx"; | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | sub _create_mime_rtf_body { | ||||||||||||||||||||||||||||
| 408 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_mime_rtf_body: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 409 | 5 | my $data = $self->{BODY_RTF}; | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 5 | my ($size, $rawsize, $magic, $crc) = unpack "V4", substr $data, 0, 16; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 5 | my $buffer; | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 5 | ▶ | if ($magic == $MAGIC_COMPRESSED_RTF) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 416 | 5 | $buffer = $BASE_BUFFER; | |||||||||||||||||||||||||||
| 417 | 5 | my $output_length = length($buffer) + $rawsize; | |||||||||||||||||||||||||||
| 418 | 5 | my @flags; | |||||||||||||||||||||||||||
| 419 | 5 | my $in = 16; | |||||||||||||||||||||||||||
| 420 | 5 | ▶ | while (length($buffer) < $output_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 456 | ▶ | if (@flags == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | 60 | @flags = split "", unpack "b8", substr $data, $in++, 1; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | 456 | my $flag = shift @flags; | |||||||||||||||||||||||||||
| 425 | 456 | ▶ | if ($flag eq "0") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 195 | $buffer .= substr $data, $in++, 1; | |||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||
| 428 | 261 | my ($a, $b) = unpack "C2", substr $data, $in, 2; | |||||||||||||||||||||||||||
| 429 | 261 | my $offset = ($a << 4) | ($b >> 4); | |||||||||||||||||||||||||||
| 430 | 261 | my $length = ($b & 0xf) + 2; | |||||||||||||||||||||||||||
| 431 | 261 | my $buflen = length $buffer; | |||||||||||||||||||||||||||
| 432 | 261 | my $longoffset = $buflen - ($buflen % 4096) + $offset; | |||||||||||||||||||||||||||
| 433 | 261 | ▶ | if ($longoffset >= $buflen) { $longoffset -= 4096; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | 261 | ▶ | while ($length > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | 1364 | $buffer .= substr $buffer, $longoffset, 1; | |||||||||||||||||||||||||||
| 436 | 1364 | $length--; | |||||||||||||||||||||||||||
| 437 | 1364 | $longoffset++; | |||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | 261 | $in += 2; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | 5 | $buffer = substr $buffer, length $BASE_BUFFER; | |||||||||||||||||||||||||||
| 443 | } elsif ($magic == $MAGIC_UNCOMPRESSED_RTF) { | ||||||||||||||||||||||||||||
| 444 | 0 | $buffer = substr $data, 16; | |||||||||||||||||||||||||||
| 445 | } else { | ||||||||||||||||||||||||||||
| 446 | 0 | carp "Incorrect magic number in RTF body.\n"; | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | 5 | return Email::MIME->create( | |||||||||||||||||||||||||||
| 449 | attributes => { | ||||||||||||||||||||||||||||
| 450 | content_type => "application/rtf", | ||||||||||||||||||||||||||||
| 451 | disposition => "inline", | ||||||||||||||||||||||||||||
| 452 | encoding => "base64", | ||||||||||||||||||||||||||||
| 453 | }, | ||||||||||||||||||||||||||||
| 454 | body => $buffer | ||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | # Copy original header data. | ||||||||||||||||||||||||||||
| 458 | # Note: This should contain the Date: header. | ||||||||||||||||||||||||||||
| 459 | sub _copy_header_data { | ||||||||||||||||||||||||||||
| 460 | 10 | ▶ | my ($self, $mime) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_copy_header_data: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 10 | ▶ | defined $self->{HEAD} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | # The extra \n is neede for Email::Simple to pick up all headers. | ||||||||||||||||||||||||||||
| 465 | # This is a change in Email::Simple. | ||||||||||||||||||||||||||||
| 466 | 7 | my $parsed = Email::Simple->new($self->{HEAD} . "\n"); | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 7 | foreach my $tag (grep { !$skipheaders->{uc $_}} $parsed->header_names) { | |||||||||||||||||||||||||||
| 469 | 34 | $mime->header_set($tag, $parsed->header($tag)); | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | 7 | return; | |||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | # Set header fields | ||||||||||||||||||||||||||||
| 475 | sub _SetHeaderFields { | ||||||||||||||||||||||||||||
| 476 | 9 | ▶ | my ($self, $mime) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_SetHeaderFields: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 9 | $self->_AddHeaderField($mime, 'Subject', $self->{SUBJECT}); | |||||||||||||||||||||||||||
| 479 | 9 | $self->_AddHeaderField($mime, 'From', $self->_Address("FROM")); | |||||||||||||||||||||||||||
| 480 | #$self->_AddHeaderField($mime, 'Reply-To', $self->_Address("REPLYTO")); | ||||||||||||||||||||||||||||
| 481 | 9 | $self->_AddHeaderField($mime, 'To', $self->_expand_address_list($self->{TO})); | |||||||||||||||||||||||||||
| 482 | 9 | $self->_AddHeaderField($mime, 'Cc', $self->_expand_address_list($self->{CC})); | |||||||||||||||||||||||||||
| 483 | 9 | $self->_AddHeaderField($mime, 'Message-Id', $self->{MESSAGEID}); | |||||||||||||||||||||||||||
| 484 | 9 | $self->_AddHeaderField($mime, 'In-Reply-To', $self->{INREPLYTO}); | |||||||||||||||||||||||||||
| 485 | 9 | $self->_AddHeaderField($mime, 'References', $self->{REFERENCES}); | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | # Least preferred option to set the Date: header; this uses the date the | ||||||||||||||||||||||||||||
| 488 | # msg file was saved. | ||||||||||||||||||||||||||||
| 489 | 9 | $self->_AddHeaderField($mime, 'Date', $self->{OLEDATE}); | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | # Second preferred option: get it from the SUBMISSION_ID: | ||||||||||||||||||||||||||||
| 492 | 9 | $self->_AddHeaderField($mime, 'Date', $self->_submission_id_date()); | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | # Most prefered option from the property list | ||||||||||||||||||||||||||||
| 495 | 9 | $self->_AddHeaderField($mime, 'Date', $self->{DATE2ND}); | |||||||||||||||||||||||||||
| 496 | 9 | $self->_AddHeaderField($mime, 'Date', $self->{DATE1ST}); | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | # After this, we'll try getting the date from the original headers. | ||||||||||||||||||||||||||||
| 499 | 9 | return; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 8 | 1; | |||||||||||||||||||||||||||