Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major perf improvement with large #s of addresses and small block data #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/Email/Outlook/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sub _empty_new {
my $class = shift;

return bless {
ADDRESSES => [], ATTACHMENTS => [], FROM_ADDR_TYPE => "",
ADDRESSES => {}, ATTACHMENTS => [], FROM_ADDR_TYPE => "",
VERBOSE => 0, EMBEDDED => 1
}, $class;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ sub _process_address {
my $addr_info = Email::Outlook::Message::AddressInfo->new($pps,
$self->{VERBOSE});

push @{$self->{ADDRESSES}}, $addr_info;
$self->{ADDRESSES}->{$addr_info->name} = $addr_info->display_address;
return;
}

Expand Down Expand Up @@ -368,14 +368,7 @@ sub _expand_address_list {
sub _find_name_in_addresspool {
my ($self, $name) = @_;

my $addresspool = $self->{ADDRESSES};

foreach my $address (@{$addresspool}) {
if ($name eq $address->name) {
return $address->display_address;
}
}
return;
return $self->{ADDRESSES}->{$name};
}

# TODO: Don't really want to need this!
Expand Down
8 changes: 4 additions & 4 deletions lib/Email/Outlook/Message/AddressInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ sub _process_subdirectory {
return;
}

sub name { my $self = shift; return $self->property('NAME') }
sub address_type { my $self = shift; return $self->property('TYPE') }
sub address { my $self = shift; return $self->property('ADDRESS') }
sub smtp_address { my $self = shift; return $self->property('SMTPADDRESS') }
sub name { $_[0]->property('NAME') }
sub address_type { $_[0]->property('TYPE') }
sub address { $_[0]->property('ADDRESS') }
sub smtp_address { $_[0]->property('SMTPADDRESS') }

sub display_address {
my $self = shift;
Expand Down
25 changes: 14 additions & 11 deletions lib/Email/Outlook/Message/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ our $skipproperties = {
'6740' => "Sent Mail Server EntryId",
};

my $decoder = Encode::find_encoding("UTF-16LE");

sub new {
my ($class, $pps, $verbose) = @_;
my $self = bless {
Expand Down Expand Up @@ -225,12 +227,10 @@ sub property {
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;
next unless $map->{$code} eq $name;
my $prop = $self->get_mapi_property($code);
if ($prop) {
my ($encoding, $data) = @{$prop};
return $self->_decode_mapi_property($encoding, $data);
return $self->_decode_mapi_property(@{$prop});
} else {
return;
}
Expand All @@ -241,10 +241,13 @@ sub property {
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);
}
if ($encoding eq $ENCODING_UNICODE) {
$data = $decoder->decode($data);
$data =~ s/ \000 $ //sgx;
return $data;
}

if ($encoding eq $ENCODING_ASCII) {
$data =~ s/ \000 $ //sgx;
return $data;
}
Expand Down Expand Up @@ -359,12 +362,12 @@ sub _process_property_stream {
my ($n, $len) = ($self->_property_stream_header_length, length $data) ;

while ($n + 16 <= $len) {
my @f = unpack "v4", substr $data, $n, 8;
my ($f0, $f1) = unpack "v2", substr $data, $n, 8;

my $encoding = sprintf("%04X", $f[0]);
my $encoding = sprintf("%04X", $f0);

unless ($VARIABLE_ENCODINGS->{$encoding}) {
my $property = sprintf("%04X", $f[1]);
my $property = sprintf("%04X", $f1);
my $propdata = substr $data, $n+8, 8;
$self->set_mapi_property($property, [$encoding, $propdata]);
}
Expand Down