/usr/share/perl5/Email/Outlook/Message/Base.pm is in libemail-outlook-message-perl 0.917-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | package Email::Outlook::Message::Base;
=head1 NAME
Email::Outlook::Message::Base - Base parser for .msg files.
=head1 DESCRIPTION
This is an internal module of Email::Outlook::Message.
=head1 METHODS
=over 8
=item B<new($pps, $verbose)>
=item B<get_mapi_property($code)>
=item B<set_mapi_property($code, $data)>
=item B<mapi_property_names()>
=item B<property($name)>
=back
=head1 AUTHOR
Matijs van Zuijlen, C<matijs@matijs.net>
=head1 COPYRIGHT AND LICENSE
Copyright 2002--2014 by Matijs van Zuijlen
This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Encode;
use IO::String;
use POSIX;
use Carp;
use OLE::Storage_Lite;
my $DIR_TYPE = 1;
my $FILE_TYPE = 2;
# Variable encodings
my $ENCODING_UNICODE = '001F';
my $ENCODING_ASCII = '001E';
my $ENCODING_BINARY = '0102';
my $ENCODING_DIRECTORY = '000D';
our $VARIABLE_ENCODINGS = {
'000D' => 'Directory',
'001F' => 'Unicode',
'001E' => 'Ascii?',
'0102' => 'Binary',
};
# Fixed encodings
my $ENCODING_INTEGER16 = '0002';
my $ENCODING_INTEGER32 = '0003';
my $ENCODING_BOOLEAN = '000B';
my $ENCODING_DATE = '0040';
#
# Descriptions partially based on mapitags.h
#
our $skipproperties = {
# Envelope properties
'0002' => "Alternate Recipient Allowed",
'000B' => "Conversation Key",
'0017' => "Importance", #TODO: Use this.
'001A' => "Message Class",
'0023' => "Originator Delivery Report Requested",
'0026' => "Priority", #TODO: Use this.
'0029' => "Read Receipt Requested", #TODO: Use this.
'0036' => "Sensitivity", # As assessed by the Sender
'003B' => "Sent Representing Search Key",
'003D' => "Subject Prefix",
'003F' => "Received By EntryId",
'0040' => "Received By Name",
# TODO: These two fields are part of the Sender field.
'0041' => "Sent Representing EntryId",
'0042' => "Sent Representing Name",
'0043' => "Received Representing EntryId",
'0044' => "Received Representing Name",
'0046' => "Read Receipt EntryId",
'0051' => "Received By Search Key",
'0052' => "Received Representing Search Key",
'0053' => "Read Receipt Search Key",
# TODO: These two fields are part of the Sender field.
'0064' => "Sent Representing Address Type",
'0065' => "Sent Representing Email Address",
'0070' => "Conversation Topic",
'0071' => "Conversation Index",
'0075' => "Received By Address Type",
'0076' => "Received By Email Address",
'0077' => "Received Representing Address Type",
'0078' => "Received Representing Email Address",
'007F' => "TNEF Correlation Key",
# Recipient properties
'0C15' => "Recipient Type",
# Sender properties
'0C19' => "Sender Entry Id",
'0C1D' => "Sender Search Key",
'0C1E' => "Sender Address Type",
# Non-transmittable properties
'0E02' => "Display Bcc",
'0E06' => "Message Delivery Time",
'0E07' => "Message Flags",
'0E0A' => "Sent Mail EntryId",
'0E0F' => "Responsibility",
'0E1B' => "Has Attachments",
'0E1D' => "Normalized Subject",
'0E1F' => "RTF In Sync",
'0E20' => "Attachment Size",
'0E21' => "Attachment Number",
'0E23' => "Internet Article Number",
'0E27' => "Security Descriptor",
'0E79' => "Trust Sender",
'0FF4' => "Access",
'0FF6' => "Instance Key",
'0FF7' => "Access Level",
'0FF9' => "Record Key",
'0FFE' => "Object Type",
'0FFF' => "EntryId",
# Content properties
'1006' => "RTF Sync Body CRC",
'1007' => "RTF Sync Body Count",
'1008' => "RTF Sync Body Tag",
'1010' => "RTF Sync Prefix Count",
'1011' => "RTF Sync Trailing Count",
'1046' => "Original Message ID",
'1080' => "Icon Index",
'1081' => "Last Verb Executed",
'1082' => "Last Verb Execution Time",
'10F3' => "URL Component Name",
'10F4' => "Attribute Hidden",
'10F5' => "Attribute System",
'10F6' => "Attribute Read Only",
# 'Common property'
'3000' => "Row Id",
'3001' => "Display Name",
'3002' => "Address Type",
'3007' => "Creation Time",
'3008' => "Last Modification Time",
'300B' => "Search Key",
# Message store info
'340D' => "Store Support Mask",
'3414' => "Message Store Provider",
# Attachment properties
'3702' => "Attachment Encoding",
'3703' => "Attachment Extension",
# TODO: Use the following to distinguish between nested msg and other OLE
# stores.
'3705' => "Attachment Method",
'3709' => "Attachment Rendering", # Icon as WMF
'370A' => "Tag identifying application that supplied the attachment",
'370B' => "Attachment Rendering Position",
'3713' => "Attachment Content Location", #TODO: Use this?
# 3900 -- 39FF: 'Address book'
'3900' => "Address Book Display Type",
'39FF' => "Address Book 7 Bit Display Name",
# Mail User Object
'3A00' => "Account",
'3A20' => "Transmittable Display Name",
'3A40' => "Send Rich Info",
'3FDE' => "Internet Code Page", # TODO: Perhaps use this.
# 'Display table properties'
'3FF8' => "Creator Name",
'3FF9' => "Creator EntryId",
'3FFA' => "Last Modifier Name",
'3FFB' => "Last Modifier EntryId",
'3FFD' => "Message Code Page",
# 'Transport-defined envelope property'
'4019' => "Sender Flags",
'401A' => "Sent Representing Flags",
'401B' => "Received By Flags",
'401C' => "Received Representing Flags",
'4029' => "Read Receipt Address Type",
'402A' => "Read Receipt Email Address",
'402B' => "Read Receipt Name",
'5FF6' => "Recipient Display Name",
'5FF7' => "Recipient EntryId",
'5FFD' => "Recipient Flags",
'5FFF' => "Recipient Track Status",
# 'Provider-defined internal non-transmittable property'
'664A' => "Has Named Properties",
'6740' => "Sent Mail Server EntryId",
};
sub new {
my ($class, $pps, $verbose) = @_;
my $self = bless {
_pps_file_entries => {},
_pps => $pps
}, $class;
$self->_set_verbosity($verbose);
$self->_process_pps($pps);
return $self;
}
sub mapi_property_names {
my $self = shift;
return keys %{$self->{_pps_file_entries}};
}
sub get_mapi_property {
my ($self, $code) = @_;
return $self->{_pps_file_entries}->{$code};
}
sub set_mapi_property {
my ($self, $code, $data) = @_;
$self->{_pps_file_entries}->{$code} = $data;
return;
}
sub property {
my ($self, $name) = @_;
my $map = $self->_property_map;
# TODO: Prepare reverse map instead of doing dumb lookup.
foreach my $code (keys %{$map}) {
my $key = $map->{$code};
next unless $key eq $name;
my $prop = $self->get_mapi_property($code);
if ($prop) {
my ($encoding, $data) = @{$prop};
return $self->_decode_mapi_property($encoding, $data);
} else {
return;
}
}
return;
}
sub _decode_mapi_property {
my ($self, $encoding, $data) = @_;
if ($encoding eq $ENCODING_ASCII or $encoding eq $ENCODING_UNICODE) {
if ($encoding eq $ENCODING_UNICODE) {
$data = decode("UTF-16LE", $data);
}
$data =~ s/ \000 $ //sgx;
return $data;
}
if ($encoding eq $ENCODING_BINARY) {
return $data;
}
if ($encoding eq $ENCODING_DATE) {
my @a = OLE::Storage_Lite::OLEDate2Local $data;
return $self->_format_date(\@a);
}
if ($encoding eq $ENCODING_INTEGER16) {
return unpack("v", substr($data, 0, 2));
}
if ($encoding eq $ENCODING_INTEGER32) {
return unpack("V", substr($data, 0, 4));
}
if ($encoding eq $ENCODING_BOOLEAN) {
return unpack("C", substr($data, 0, 1));
}
warn "Unhandled encoding $encoding\n";
return $data;
}
sub _process_pps {
my ($self, $pps) = @_;
foreach my $child (@{$pps->{Child}}) {
if ($child->{Type} == $DIR_TYPE) {
$self->_process_subdirectory($child);
} elsif ($child->{Type} == $FILE_TYPE) {
$self->_process_pps_file_entry($child);
} else {
carp "Unknown entry type: $child->{Type}";
}
}
$self->_check_pps_file_entries($self->_property_map);
return;
}
sub _get_pps_name {
my ($self, $pps) = @_;
my $name = OLE::Storage_Lite::Ucs2Asc($pps->{Name});
$name =~ s/ \W / /gx;
return $name;
}
sub _parse_item_name {
my ($self, $name) = @_;
if ($name =~ / ^ __substg1 [ ] 0_ (....) (....) $ /x) {
my ($property, $encoding) = ($1, $2);
if ($encoding eq $ENCODING_UNICODE and not ($self->{HAS_UNICODE})) {
$self->{HAS_UNICODE} = 1;
}
return ($property, $encoding);
} else {
return (undef, undef);
}
}
sub _warn_about_unknown_directory {
my ($self, $pps) = @_;
my $name = $self->_get_pps_name($pps);
if ($name eq '__nameid_version1 0') {
# TODO: Use this data to access so-called named properties.
$self->{VERBOSE}
and warn "Skipping DIR entry $name (Introductory stuff)\n";
} else {
warn "Unknown DIR entry $name\n";
}
return;
}
sub _warn_about_unknown_file {
my ($self, $pps) = @_;
my $name = $self->_get_pps_name($pps);
if ($name eq 'Olk10SideProps_0001') {
$self->{VERBOSE}
and warn "Skipping FILE entry $name (Properties)\n";
} else {
warn "Unknown FILE entry $name\n";
}
return;
}
#
# Generic processor for a file entry: Inserts the entry's data into the
# $self's mapi property list.
#
sub _process_pps_file_entry {
my ($self, $pps) = @_;
my $name = $self->_get_pps_name($pps);
my ($property, $encoding) = $self->_parse_item_name($name);
if (defined $property) {
$self->set_mapi_property($property, [$encoding, $pps->{Data}]);
} elsif ($name eq '__properties_version1 0') {
$self->_process_property_stream ($pps->{Data});
} else {
$self->_warn_about_unknown_file($pps);
}
return;
}
sub _process_property_stream {
my ($self, $data) = @_;
my ($n, $len) = ($self->_property_stream_header_length, length $data) ;
while ($n + 16 <= $len) {
my @f = unpack "v4", substr $data, $n, 8;
my $encoding = sprintf("%04X", $f[0]);
unless ($VARIABLE_ENCODINGS->{$encoding}) {
my $property = sprintf("%04X", $f[1]);
my $propdata = substr $data, $n+8, 8;
$self->set_mapi_property($property, [$encoding, $propdata]);
}
} continue {
$n += 16 ;
}
return;
}
sub _check_pps_file_entries {
my ($self, $map) = @_;
foreach my $property ($self->mapi_property_names) {
if (my $key = $map->{$property}) {
$self->_use_property($key, $property);
} else {
$self->_warn_about_skipped_property($property);
}
}
return;
}
sub _use_property {
my ($self, $key, $property) = @_;
my ($encoding, $data) = @{$self->get_mapi_property($property)};
$self->{$key} = $self->_decode_mapi_property($encoding, $data);
$self->{VERBOSE}
and $self->_log_property("Using ", $property, $key);
return;
}
sub _warn_about_skipped_property {
my ($self, $property) = @_;
return unless $self->{VERBOSE};
my $meaning = $skipproperties->{$property} || "UNKNOWN";
$self->_log_property("Skipping", $property, $meaning);
return;
}
sub _log_property {
my ($self, $message, $property, $meaning) = @_;
my ($encoding, $data) = @{$self->get_mapi_property($property)};
my $value = $self->_decode_mapi_property($encoding, $data);
$value = substr($value, 0, 50);
if ($encoding eq $ENCODING_BINARY) {
if ($value =~ / [[:print:]] /x) {
$value =~ s/ [^[:print:]] /./gx;
} else {
$value =~ s/ . / sprintf("%02x ", ord($&)) /sgex;
}
}
if (length($value) > 45) {
$value = substr($value, 0, 41) . " ...";
}
warn "$message property $encoding:$property ($meaning): $value\n";
return;
}
sub _set_verbosity {
my ($self, $verbosity) = @_;
$self->{VERBOSE} = $verbosity ? 1 : 0;
return;
}
#
# Format a gmt date according to RFC822
#
sub _format_date {
my ($self, $datearr) = @_;
my $day = qw(Sun Mon Tue Wed Thu Fri Sat)[strftime("%w", @{$datearr})];
my $month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[strftime("%m", @{$datearr}) - 1];
return strftime("$day, %d $month %Y %H:%M:%S +0000", @{$datearr});
}
1;
|