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/Profanivore/Extension.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'extensions/Profanivore') diff --git a/extensions/Profanivore/Extension.pm b/extensions/Profanivore/Extension.pm index cdec6e1c6..49b2f61c3 100644 --- a/extensions/Profanivore/Extension.pm +++ b/extensions/Profanivore/Extension.pm @@ -23,6 +23,7 @@ package Bugzilla::Extension::Profanivore; use strict; use base qw(Bugzilla::Extension); +use Email::MIME::ContentType qw(parse_content_type); use Regexp::Common 'RE_ALL'; use Bugzilla::Util qw(is_7bit_clean); @@ -117,17 +118,26 @@ sub mailer_before_send { sub _fix_encoding { my $part = shift; - my $body = $part->body; - if (Bugzilla->params->{'utf8'}) { + + # 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'); - # encoding_set works only with bytes, not with utf8 strings. my $raw = $part->body_raw; if (utf8::is_utf8($raw)) { utf8::encode($raw); $part->body_set($raw); } } - $part->encoding_set('quoted-printable') if !is_7bit_clean($body); + $part->encoding_set('quoted-printable'); } sub _filter_text { -- cgit v1.2.3-24-g4f1b