X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FMIME.pm;h=05534e3e054c47d2cb281f683aaacf1a0ac7a52e;hb=4ac94f292bfbf36863795ed9d695be7ad2b5b344;hp=95dafb8dc5075ed9a515143c00dd8e584e653bb0;hpb=c775dcf61c6a5e45303684d3cf5a3d27c3730698;p=debbugs.git diff --git a/Debbugs/MIME.pm b/Debbugs/MIME.pm index 95dafb8..05534e3 100644 --- a/Debbugs/MIME.pm +++ b/Debbugs/MIME.pm @@ -229,9 +229,7 @@ sub convert_to_utf8 { return $data if $charset eq 'raw' or is_utf8($data,1); my $result; eval { - # this encode/decode madness is to make sure that the data - # really is valid utf8 and that the is_utf8 flag is off. - $result = encode("utf8",decode($charset,$data)) + $result = decode($charset,$data); }; if ($@) { warn "Unable to decode charset; '$charset' and '$data': $@"; @@ -286,10 +284,15 @@ sub encode_rfc1522 { # handle being passed undef properly return undef if not defined $rawstr; + if (is_utf8($rawstr)) { + $rawstr= encode_utf8($rawstr); + } # We process words in reverse so we can preserve spacing between # encoded words. This regex splits on word|nonword boundaries and - # nonword|nonword boundaries. - my @words = reverse split /(?:(?<=[\s\n])|(?=[\s\n]))/m, $rawstr; + # nonword|nonword boundaries. We also consider parenthesis and " + # to be nonwords to avoid escaping them in comments in violation + # of RFC1522 + my @words = reverse split /(?:(?<=[\s\n\)\(\"])|(?=[\s\n\)\(\"]))/m, $rawstr; my $previous_word_encoded = 0; my $string = ''; @@ -311,7 +314,7 @@ sub encode_rfc1522 { if (length $encoded > 75) { # Turn utf8 into the internal perl representation # so . is a character, not a byte. - my $tempstr = decode_utf8($word,Encode::FB_DEFAULT); + my $tempstr = is_utf8($word)?$word:decode_utf8($word,Encode::FB_DEFAULT); my @encoded; # Strip it into 10 character long segments, and encode # the segments