From 6dc2473b8b5488b6c3ebd996128e5b79bd6421fc Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 23 Oct 2014 13:50:46 +0800 Subject: Bug 1078314: Missing links and broken unicode characters in some bugmail --- extensions/Splinter/lib/Util.pm | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'extensions/Splinter') diff --git a/extensions/Splinter/lib/Util.pm b/extensions/Splinter/lib/Util.pm index 3c77239a9..e6cbe7493 100644 --- a/extensions/Splinter/lib/Util.pm +++ b/extensions/Splinter/lib/Util.pm @@ -25,6 +25,7 @@ use strict; use Bugzilla; use Bugzilla::Util; +use Email::MIME::ContentType qw(parse_content_type); use base qw(Exporter); @@ -130,7 +131,11 @@ sub munge_create_attachment { # (\015 and \012 are used because Perl \n is platform-dependent) sub add_review_links_to_email { my $email = shift; - my $body = $email->body; + return if $email->parts > 1; + + _fix_encoding($email); + my $body = $email->body_str; + my $new_body = 0; my $bug; @@ -157,7 +162,31 @@ sub add_review_links_to_email { $new_body = 1; } - $email->body_set($body) if $new_body; + $email->body_str_set($body) if $new_body; +} + +sub _fix_encoding { + my $part = shift; + + # don't touch the top-level part of multi-part mail + return if $part->parts > 1; + + # nothing to do if the part already has a charset + my $ct = parse_content_type($part->content_type); + my $charset = $ct->{attributes}{charset} + ? $ct->{attributes}{charset} + : ''; + return unless !$charset || $charset eq 'us-ascii'; + + if (Bugzilla->params->{utf8}) { + $part->charset_set('UTF-8'); + my $raw = $part->body_raw; + if (utf8::is_utf8($raw)) { + utf8::encode($raw); + $part->body_set($raw); + } + } + $part->encoding_set('quoted-printable'); } 1; -- cgit v1.2.3-24-g4f1b