Index: lib/Mail/SpamAssassin/PerMsgStatus.pm =================================================================== --- lib/Mail/SpamAssassin/PerMsgStatus.pm (revision 588211) +++ lib/Mail/SpamAssassin/PerMsgStatus.pm (working copy) @@ -665,22 +665,46 @@ # This is the new message. my $newmsg = ''; + # the SpamAssassin report + my $report = $self->get_report(); + # the report charset - my $report_charset = "; charset=iso-8859-1"; + my $report_charset = 'iso-8859-1'; if ($self->{conf}->{report_charset}) { - $report_charset = "; charset=" . $self->{conf}->{report_charset}; + $report_charset = $self->{conf}->{report_charset}; } - # the SpamAssassin report - my $report = $self->get_report(); - # If there are any wide characters, need to MIME-encode in UTF-8 - # TODO: If $report_charset is something other than iso-8859-1/us-ascii, then - # we could try converting to that charset if possible - unless ($] < 5.008 || utf8::downgrade($report, 1)) { - $report_charset = "; charset=utf-8"; - utf8::encode($report); + unless ($] < 5.008) { + use Encode; + my $charset_is_utf8 = 0; + if ($self->{conf}->{normalize_charset}) { + $report = Encode::decode('utf8',$report) unless (Encode::is_utf8($report)); + $charset_is_utf8 = 1; + } + else { + if ($self->{msg}->{charset}) { + eval { + my $scratch = $report; + $report = Encode::decode($self->{msg}->{charset},$scratch,Encode::FB_CROAK); + $charset_is_utf8 = 1; + }; + } + } + if ($charset_is_utf8) { + $charset_is_utf8 = 1; + eval { + my $scratch = $report; + $report = Encode::encode($report_charset,$scratch,Encode::FB_CROAK); + $charset_is_utf8 = 0; + }; + if ($charset_is_utf8) { + $report = Encode::encode('utf8',$report); + $report_charset = 'utf-8'; + } + } } + my $report_charset_param = "; charset=" . $report_charset; # get original headers, "pristine" if we can do it my $from = $self->{msg}->get_pristine_header("From"); @@ -798,7 +822,7 @@ This is a multi-part message in MIME format. --$boundary -Content-Type: text/plain$report_charset +Content-Type: text/plain$report_charset_param Content-Disposition: inline Content-Transfer-Encoding: 8bit