[rt-users] Re: [fsck.com #5135] Problems with Subject Encoding or RFC2047 violated on SendEmail.pm

Paulo Matos pjsm at fct.unl.pt
Thu Feb 19 10:01:14 EST 2004


	Hi again!

	I solved the problem... provided patch in attachment...

	Jesse, please take a look and merge it whenever you can. 

--
	Paulo Matos
-------------- next part --------------
#
# rt-3.0.8-RFC2047fix_on_SendMail.pm.patch
#
# * 2004.02.19 Paulo Matos <paulo.matos at fct.unl.pt>
#
# Solves rt3 #5135
# - Problems with Subject Encoding or RFC2047 violated on SendEmail.pm
#
diff -uNr RT.orig/Action/SendEmail.pm RT/Action/SendEmail.pm
--- RT.orig/Action/SendEmail.pm	Wed Feb 18 01:50:36 2004
+++ RT/Action/SendEmail.pm	Thu Feb 19 14:22:29 2004
@@ -663,15 +663,41 @@
 sub MIMEEncodeString {
     my  $self = shift;
     my $value = shift;
-    my $enc = shift;
+    # using RFC2047 notation, sec 2.
+    # encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
+    my $charset = shift;
+    my $encoding = 'B';
+    # An 'encoded-word' may not be more than 75 characters long
+    #
+    # MIME encoding increases 4/3*(number of bytes), and always in multiples
+    # of 4. Thus we have to find the best available value of bytes available
+    # for each chunk.
+    #
+    # First we get the integer max which max*4/3 would fit on space.
+    # Then we find the greater multiple of 3 lower or equal than $max.
+    my $max = int(((75-length('=?'.$charset.'?'.$encoding.'?'.'?='))*3)/4);
+    $max = int($max/3)*3;
 
     chomp $value;
     return ($value) unless $value =~ /[^\x20-\x7e]/;
 
     $value =~ s/\s*$//;
     Encode::_utf8_off($value);
-    my $res = Encode::from_to( $value, "utf-8", $enc );
-    $value = encode_mimeword( $value,  'B', $enc );
+    my $res = Encode::from_to( $value, "utf-8", $charset );
+   
+    if ($max > 0) {
+      # copy value and split in chuncks
+      my $str=$value;
+      my @chunks = unpack("a$max" x int(length($str)/$max 
+                                  + ((length($str) % $max) ? 1:0)), $str);
+      # encode an join chuncks
+      $value = join " ", 
+                     map encode_mimeword( $_, $encoding, $charset ), @chunks ;
+      return($value); 
+    } else {
+      # gives an error...
+      $RT::Logger->crit("Can't encode! Charset or encoding too big.\n");
+    }
 }
 
 # }}}


More information about the rt-users mailing list