Fix double body encoding when sending emails. Added tests. Fixes bug #11672.
This commit is contained in:
parent
40e6d7036b
commit
aed2c13f52
3 changed files with 47 additions and 5 deletions
|
|
@ -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...
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue