Skip to content

Commit

Permalink
Fix double body encoding when sending emails. Added tests. Fixes bug …
Browse files Browse the repository at this point in the history
…#11672.
  • Loading branch information
perlDreamer committed Jul 5, 2010
1 parent 40e6d70 commit aed2c13
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -4,6 +4,7 @@
- fixed #11696: WebGUI 7.9.8 gotcha
- fixed #11698: Trash dies on missing or bad workflow
- fixed #11692: Dates not imported correctly into Thingy
- fixed #11672: UTF-Error in message body (from DataForm)

7.9.8
- fixed #11651: First Day of Week is a string...
Expand Down
9 changes: 5 additions & 4 deletions lib/WebGUI/Mail/Send.pm
Expand Up @@ -98,8 +98,9 @@ Macros in the footer will be evaluated.
sub addFooter {
my $self = shift;
return if $self->{_footerAdded};
my $text = "\n\n".$self->session->setting->get("mailFooter");
WebGUI::Macro::process($self->session, \$text);
my $footer = "\n\n".$self->session->setting->get("mailFooter");
WebGUI::Macro::process($self->session, \$footer);
my $text = encode("utf8", $footer);
$self->{_footerAdded} = 1;
my @parts = $self->getMimeEntity->parts();
##No parts yet, add one with the footer content.
Expand All @@ -117,7 +118,7 @@ sub addFooter {
Charset => "UTF-8",
Encoding => "quoted-printable",
Type => 'text/plain',
Data => encode('utf8', $body_content),
Data => $body_content,
);
shift @parts;
unshift @parts, $new_part;
Expand All @@ -130,7 +131,7 @@ sub addFooter {
Charset => "UTF-8",
Encoding => "quoted-printable",
Type => 'text/html',
Data => encode('utf8', $body_content),
Data => $body_content,
);
shift @parts;
unshift @parts, $new_part;
Expand Down
42 changes: 41 additions & 1 deletion t/Mail/Send.t
Expand Up @@ -42,7 +42,7 @@ if ( $@ ) { diag( "Can't prepare mail server: $@" ) }
#----------------------------------------------------------------------------
# Tests

plan tests => 34; # Increment this number for each test you create
plan tests => 38; # Increment this number for each test you create

WebGUI::Test->addToCleanup(SQL => 'delete from mailQueue');

Expand Down Expand Up @@ -177,6 +177,46 @@ is($dbMail->getMimeEntity->head->get('Subject'), "=?UTF-8?Q?H=C3=84ufige=20Frage
ok(defined $result && $result, 'by default, we make multipart messages');
}

{
##Disable the footer for easy processing
my $origFooter = $session->setting->get('mailFooter');
$session->setting->set('mailFooter', "");
my $textMail = WebGUI::Mail::Send->create( $session );
$textMail->addText("H\x{00C4}ufige Fragen");
$textMail->addFooter();
is $textMail->getMimeEntity->parts(0)->bodyhandle->as_string,
encode('utf-8', "H\x{00C4}ufige Fragen\n\n"),
'check that adding a footer does not double encode the body when it is text';
my $htmlMail = WebGUI::Mail::Send->create( $session );
$htmlMail->addHtml("__H\x{00C4}ufige Fragen__");
$htmlMail->addFooter();
my ($encoded_segment) = $htmlMail->getMimeEntity->parts(0)->bodyhandle->as_string =~ /__([^_]+)__/;
is $encoded_segment,
encode('utf-8', "H\x{00C4}ufige Fragen"),
'... similarly with an html body';
$session->setting->set('mailFooter', $origFooter);
}

{
##Set the footer to contain UTF-8 characters
my $origFooter = $session->setting->get('mailFooter');
$session->setting->set('mailFooter', "Not beta: \x{00DF} ");
my $textMail = WebGUI::Mail::Send->create( $session );
$textMail->addText("");
$textMail->addFooter();
is $textMail->getMimeEntity->parts(0)->bodyhandle->as_string,
encode('utf-8', "\n\nNot beta: \x{00DF} "),
'check that footer is encoded as UTF-8 for a text body';
my $htmlMail = WebGUI::Mail::Send->create( $session );
$htmlMail->addHtml("");
$htmlMail->addFooter();
my ($encoded_segment) = $htmlMail->getMimeEntity->parts(0)->bodyhandle->as_string =~ /Not beta: (\S+)/;
is $encoded_segment,
encode('utf-8', "\x{00DF}"),
'... similarly with an html body';
$session->setting->set('mailFooter', $origFooter);
}

my $smtpServerOk = 0;

#----------------------------------------------------------------------------
Expand Down

0 comments on commit aed2c13

Please sign in to comment.