summaryrefslogtreecommitdiffstats
path: root/extensions/BMO
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/BMO')
-rw-r--r--extensions/BMO/Extension.pm35
1 files changed, 25 insertions, 10 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm
index 1e0593c4e..d6839b2a7 100644
--- a/extensions/BMO/Extension.pm
+++ b/extensions/BMO/Extension.pm
@@ -40,6 +40,7 @@ use Bugzilla::Util;
use Date::Parse;
use DateTime;
+use Email::MIME::ContentType qw(parse_content_type);
use Encode qw(find_encoding encode_utf8);
use File::MimeInfo::Magic;
use List::MoreUtils qw(natatime);
@@ -1132,9 +1133,29 @@ sub _inject_headers_into_body {
sub _replace_placeholder_in_part {
my ($part, $replacement) = @_;
- # fix encoding
- my $body = $part->body;
- if (Bugzilla->params->{'utf8'}) {
+ _fix_encoding($part);
+
+ # replace
+ my $placeholder = quotemeta('@@body-headers@@');
+ my $body = $part->body_str;
+ $body =~ s/$placeholder/$replacement/;
+ $part->body_str_set($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)) {
@@ -1142,13 +1163,7 @@ sub _replace_placeholder_in_part {
$part->body_set($raw);
}
}
- $part->encoding_set('quoted-printable') if !is_7bit_clean($body);
-
- # replace
- my $placeholder = quotemeta('@@body-headers@@');
- $body = $part->body_str;
- $body =~ s/$placeholder/$replacement/;
- $part->body_str_set($body);
+ $part->encoding_set('quoted-printable');
}
sub _syslog {