Skip to content

Commit

Permalink
Use message codepage if body code page is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Dec 16, 2023
1 parent 120065f commit 63d76e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Email/Outlook/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 33 additions & 1 deletion t/internals.t
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 63d76e0

Please sign in to comment.