[Rt-commit] rt branch, 4.2/html-mail-error-safety, created. rt-4.2.1-43-g8807f0d
Alex Vandiver
alexmv at bestpractical.com
Mon Dec 2 12:47:44 EST 2013
The branch, 4.2/html-mail-error-safety has been created
at 8807f0d093961851b7d6d48daf783b799a47c3c9 (commit)
- Log -----------------------------------------------------------------
commit 8807f0d093961851b7d6d48daf783b799a47c3c9
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Dec 2 12:44:32 2013 -0500
Ensure that outgoing mail is not lost if HTML â text conversion fails
HTML::FormatText::WithLinks::AndTables may contain errors which make it
incapable of rendering the HTML to text. If the conversion fails, trap
it and ensure that we still at least send out the HTML version.
It is expected that these tests may begin to fail if
HTML::FormatText::WithLinks::AndTables resolves its bug surrounding
nested tables. Unfortunately, marking them TODO is difficult.
diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index 43c08ba..71f83db 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -660,14 +660,22 @@ sub _DowngradeFromHTML {
$orig_entity->head->mime_attr( "Content-Type" => 'text/html' );
$orig_entity->head->mime_attr( "Content-Type.charset" => 'utf-8' );
- $orig_entity->make_multipart('alternative', Force => 1);
require Encode;
- $new_entity->bodyhandle(MIME::Body::InCore->new(
+ my $html = eval {
+ my $body = $new_entity->bodyhandle->as_string;
# need to decode_utf8, see the doc of MIMEObj method
- \(RT::Interface::Email::ConvertHTMLToText(Encode::decode_utf8($new_entity->bodyhandle->as_string)))
- ));
+ $body = Encode::decode_utf8( $body );
+ RT::Interface::Email::ConvertHTMLToText( $body );
+ };
+ if ($@) {
+ $RT::Logger->error("Failed to downgrade HTML to plain text: $@");
+ return;
+ }
+ $new_entity->bodyhandle(MIME::Body::InCore->new( \$html ));
+
+ $orig_entity->make_multipart('alternative', Force => 1);
$orig_entity->add_part($new_entity, 0); # plain comes before html
$self->{MIMEObj} = $orig_entity;
diff --git a/t/mail/html-outgoing.t b/t/mail/html-outgoing.t
index d20dd63..1b460c2 100644
--- a/t/mail/html-outgoing.t
+++ b/t/mail/html-outgoing.t
@@ -4,10 +4,11 @@ use RT::Test tests => undef;
BEGIN {
plan skip_all => 'Email::Abstract and Test::Email required.'
unless eval { require Email::Abstract; require Test::Email; 1 };
- plan tests => 18;
+ plan tests => 22;
}
use RT::Test::Email;
+use Test::Warn;
my $root = RT::User->new(RT->SystemUser);
$root->Load('root');
@@ -86,6 +87,29 @@ mail_ok {
};
+diag "Failing HTML -> Text conversion";
+warnings_like {
+ my $body = '<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>';
+ mail_ok {
+ ($ok, $tmsg) = $t->Correspond(
+ MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
+ Body => $body,
+ Type => 'text/html',
+ ),
+ );
+ } { from => qr/RT System/,
+ bcc => 'root at localhost',
+ subject => qr/\Q[example.com #1] The internet is broken\E/,
+ body => qr{Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?$body}s,
+ 'Content-Type' => qr{text/html}, # TODO
+ },{ from => qr/RT System/,
+ to => 'enduser at example.com',
+ subject => qr/\Q[example.com #1] The internet is broken\E/,
+ body => qr{<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>},
+ 'Content-Type' => qr{text/html}, # TODO
+ };
+} [(qr/uninitialized value/, qr/Failed to downgrade HTML/)x3];
+
diag "Admin Comment in HTML";
mail_ok {
($ok, $tmsg) = $t->Comment(
-----------------------------------------------------------------------
More information about the rt-commit
mailing list