From 63d76e0f57ccb502c69b18a1c2ded561670e2c46 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 16 Dec 2023 10:46:21 +0100 Subject: [PATCH] Use message codepage if body code page is not present --- lib/Email/Outlook/Message.pm | 2 +- t/internals.t | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/Email/Outlook/Message.pm b/lib/Email/Outlook/Message.pm index d9ec179..8d89946 100644 --- a/lib/Email/Outlook/Message.pm +++ b/lib/Email/Outlook/Message.pm @@ -404,7 +404,7 @@ sub _body_html_character_set { sub _body_character_set { my $self = shift; my $body_encoding = shift || ""; - my $codepage = $self->{CODEPAGE}; + my $codepage = $self->{CODEPAGE} || $self->{MESSAGE_CODEPAGE}; my $codepage_value; if (defined $codepage) { 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;