]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/MIME.pm
Only use decode_utf8 if the string isn't already in perl's internal encoding
[debbugs.git] / Debbugs / MIME.pm
index 95dafb8dc5075ed9a515143c00dd8e584e653bb0..e94733ee016db8de4213700a7581bb3b6a00e285 100644 (file)
@@ -288,8 +288,10 @@ sub encode_rfc1522 {
      return undef if not defined $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 +313,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