Skip to content

Commit

Permalink
BUGFIX: 2858688 3.0.4 - charset not set in multipart/* message *parts*
Browse files Browse the repository at this point in the history
https://sourceforge.net/tracker/?func=detail&aid=2858688&group_id=13002&atid=113002

This fixes the problem for the, "Send a List Message" screen, both when create an HTML message (with no PlainText version) and when you create an HTML and PlainText Message. 

Tests are included (4) all failed before changes, all now pass. All prev. tests pass.
  • Loading branch information
justingit committed Sep 14, 2009
1 parent 18bb8bb commit 218b0f1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
13 changes: 10 additions & 3 deletions dada/DADA/App/FormatMessages.pm
Expand Up @@ -567,16 +567,23 @@ sub _make_multipart {
my $self = shift;
my $entity = shift;

# I wanted to do this, before we make it multipart:
my $orig_charset = $entity->head->mime_attr('content-type.charset');

require MIME::Entity;

my $html_body = $entity->bodyhandle;
my $html_content = $html_body->as_string;

$entity->make_multipart('alternative');

my $plaintext_entity = MIME::Entity->build(Type => 'text/plain',
Data => $self->_create_plaintext_from_html($html_content)
);
my $plaintext_entity = MIME::Entity->build(
Type => 'text/plain',
Data => $self->_create_plaintext_from_html($html_content),
);
$plaintext_entity->head->mime_attr(
"content-type.charset" => $orig_charset,
);

$entity->add_part($plaintext_entity, 0);

Expand Down
29 changes: 19 additions & 10 deletions dada/DADA/App/MassSend.pm
Expand Up @@ -233,17 +233,26 @@ sub send_email {

$msg->attr('content-type.charset' => $li->{charset_value});

$msg->attach(
Type => 'text/plain',
Data => $text_message_body,
Encoding => $li->{plaintext_encoding},
);

$msg->attach(
Type => 'text/html',
Data => $html_message_body,
Encoding => $li->{html_encoding},
);
my $pt_part = MIME::Lite->new(
Type => 'text/plain',
Data => $text_message_body,
Encoding => $li->{plaintext_encoding},
);
$pt_part->attr(
'content-type.charset' => $li->{charset_value}
);
$msg->attach($pt_part);

my $html_part = MIME::Lite->new(
Type => 'text/html',
Data => $html_message_body,
Encoding => $li->{html_encoding},
);
$html_part->attr(
'content-type.charset' => $li->{charset_value}
);
$msg->attach($html_part);

}elsif($html_message_body){

Expand Down
38 changes: 38 additions & 0 deletions dada/t/DADA_App_MassSend.t
Expand Up @@ -117,6 +117,26 @@ sleep(1);
$msg = slurp($mh->test_send_file);
like($msg, qr/Content-type: multipart\/alternative\;/, "Multipart/alternative header set!");

my $parser;
my $entity;
my @parts;
$parser = new MIME::Parser;
$parser = optimize_mime_parser($parser);
$entity = $parser->parse_data($msg);
@parts = $entity->parts;
ok(
$ls->param('charset_value') eq $parts[0]->head->mime_attr('content-type.charset'),
"Charset Match " . $parts[0]->head->mime_attr('content-type.charset')
);
ok(
$ls->param('charset_value') eq $parts[1]->head->mime_attr('content-type.charset'),
"Charset Match(2) " . $parts[0]->head->mime_attr('content-type.charset')
);
undef $parser;
undef $entity;
undef @parts;


undef $msg;
ok(unlink($mh->test_send_file));
undef $q;
Expand All @@ -143,6 +163,24 @@ like($msg, qr/Content-type: text\/plain/i, "text/plain header set!");
like($msg, qr/This is the html message body!\n/m, "Found plain text version of HTML message");
like($msg, qr/\<h1\>This is the html message body!\<\/h1\>/m, "Found HTML version of HTML message");


$parser = new MIME::Parser;
$parser = optimize_mime_parser($parser);
$entity = $parser->parse_data($msg);
@parts = $entity->parts;
ok(
$ls->param('charset_value') eq $parts[0]->head->mime_attr('content-type.charset'),
"Charset Match " . $parts[0]->head->mime_attr('content-type.charset')
);
ok(
$ls->param('charset_value') eq $parts[1]->head->mime_attr('content-type.charset'),
"Charset Match(2) " . $parts[0]->head->mime_attr('content-type.charset')
);
undef $parser;
undef $entity;
undef @parts;


ok(unlink($mh->test_send_file));


Expand Down

0 comments on commit 218b0f1

Please sign in to comment.