diff --git a/lib/Email/Outlook/Message.pm b/lib/Email/Outlook/Message.pm index cf9e568..8d89946 100644 --- a/lib/Email/Outlook/Message.pm +++ b/lib/Email/Outlook/Message.pm @@ -96,7 +96,8 @@ our $MAP_SUBITEM_FILE = { '1042' => "INREPLYTO", # In reply to Message-Id '3007' => 'DATE2ND', # Creation Time '0039' => 'DATE1ST', # Outlook sent date - '3FDE' => 'CODEPAGE', # Code page for text or html body + '3FDE' => 'CODEPAGE', # PR_INTERNET_CPID - Code page for text or html body + '3FFD' => 'MESSAGE_CODEPAGE' # PR_MESSAGE_CODEPAGE - Message Code Page }; # Map codepage numbers to charset names. Codepages not listed here just get @@ -402,14 +403,27 @@ sub _body_html_character_set { sub _body_character_set { my $self = shift; - my $body_encoding = shift; - my $codepage = $self->{CODEPAGE}; - if (defined $body_encoding && $body_encoding eq "001F") { + my $body_encoding = shift || ""; + my $codepage = $self->{CODEPAGE} || $self->{MESSAGE_CODEPAGE}; + my $codepage_value; + + if (defined $codepage) { + $codepage_value = $MAP_CODEPAGE->{$codepage} || "CP$codepage"; + } else { + $codepage_value = "CP1252"; + } + + $self->{VERBOSE} and + warn "Body-encoding: $body_encoding; Codepage: $codepage_value"; + + if ($body_encoding eq "001F") { + if (defined $codepage and $codepage_value ne "UTF-8") { + $self->{VERBOSE} and + warn "Unicode encoding used to encode $codepage_value character set"; + } return "UTF-8"; - } elsif (defined $codepage) { - return $MAP_CODEPAGE->{$codepage} || "CP$codepage"; } else { - return 'CP1252'; + return $codepage_value; } } diff --git a/lib/Email/Outlook/Message/Base.pm b/lib/Email/Outlook/Message/Base.pm index 3717a2e..7797c60 100644 --- a/lib/Email/Outlook/Message/Base.pm +++ b/lib/Email/Outlook/Message/Base.pm @@ -175,7 +175,6 @@ our $skipproperties = { '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", diff --git a/t/internals.t b/t/internals.t index ac9e1ff..d422e45 100644 --- a/t/internals.t +++ b/t/internals.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 25; use Email::Outlook::Message; #use MIME::Entity; use Email::MIME::Creator; @@ -13,9 +13,15 @@ test_to_email_mime_with_no_parts($p); test_to_email_mime_with_plain_part($p); test_to_email_mime_with_html_part($p); test_to_email_mime_with_two_parts($p); +test_to_email_mime_with_plain_part_and_body_codepage(); +test_to_email_mime_with_plain_part_and_message_codepage(); # DONE +sub empty_message { + Email::Outlook::Message->_empty_new(); +} + sub test_copy_header_data { my $p = shift; @@ -67,6 +73,32 @@ sub test_to_email_mime_with_plain_part { like($m->content_type, qr{^text/plain; charset="?CP1252"?$}); } +sub test_to_email_mime_with_plain_part_and_body_codepage { + my $p = empty_message(); + $p->{BODY_PLAIN} = "plain"; + $p->{BODY_PLAIN_ENCODING} = "001E"; + $p->{CODEPAGE} = 1251; + $p->{BODY_HTML} = undef; + my $m = $p->to_email_mime; + ok(defined $m); + ok(($m->parts) == 1); + is($m->body, "plain"); + like($m->content_type, qr{^text/plain; charset="?CP1251"?$}); +} + +sub test_to_email_mime_with_plain_part_and_message_codepage { + my $p = empty_message(); + $p->{BODY_PLAIN} = "plain"; + $p->{BODY_PLAIN_ENCODING} = "001E"; + $p->{MESSAGE_CODEPAGE} = 1251; + $p->{BODY_HTML} = undef; + my $m = $p->to_email_mime; + ok(defined $m); + ok(($m->parts) == 1); + is($m->body, "plain"); + like($m->content_type, qr{^text/plain; charset="?CP1251"?$}); +} + sub test_to_email_mime_with_html_part { my $p = shift; $p->{BODY_PLAIN} = undef;