Skip to content

Commit

Permalink
Subparts should inherit email's encode_check
Browse files Browse the repository at this point in the history
Each subpart is created with $self->new(), and the code that did this
wasn't passing through its own encode_check value. This meant that
multipart emails created with non-default values for encode_check
weren't really getting them, since every subpart falls back to
Email::MIME's default of Encode::FB_CROAK.
  • Loading branch information
mmcclimon authored and rjbs committed Aug 31, 2017
1 parent 0c8887c commit cef9413
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Email/MIME.pm
Expand Up @@ -412,7 +412,7 @@ sub parts_multipart {
for my $bit (@bits) {
$bit =~ s/\A[\n\r]+//smg;
$bit =~ s/(?<!\x0d)$self->{mycrlf}\Z//sm;
my $email = (ref $self)->new($bit);
my $email = (ref $self)->new($bit, { encode_check => $self->encode_check });
push @parts, $email;
}

Expand Down Expand Up @@ -579,7 +579,7 @@ sub content_type_attribute_set {

=method encode_check
=method encode_check-set
=method encode_check_set
$email->encode_check;
$email->encode_check_set(0);
Expand Down
25 changes: 25 additions & 0 deletions t/encode-check.t
Expand Up @@ -32,6 +32,31 @@ subtest "encode_check 0 during create()" => sub {
);
};

subtest "encode_check 0 during create(), multi-part" => sub {
my $email = Email::MIME->create(
parts => [
q[Totally ascii first part],
q[Look, a snowman: ☃],
],
encode_check => Encode::FB_DEFAULT,
);

ok($email, 'we created an email with badly encoded data');

my $part_num = 1;

$email->walk_parts(sub {
my ($part) = @_;
return if $part->subparts;

is(
$part->encode_check,
Encode::FB_DEFAULT,
"subpart picked up email's encode_check setting"
);
});
};

subtest "encode_check 0 during new()" => sub {
my $email = Email::MIME->new(<<'EOF', { encode_check => 0 });
Date: Fri, 16 Jun 2017 09:48:19 -0400
Expand Down

0 comments on commit cef9413

Please sign in to comment.