[Rt-commit] [svn] r751 - rt/trunk/lib/RT/Action
leira at pallas.eruditorum.org
leira at pallas.eruditorum.org
Mon Apr 26 19:01:18 EDT 2004
Author: leira
Date: Mon Apr 26 19:01:15 2004
New Revision: 751
Modified:
rt/trunk/lib/RT/Action/SendEmail.pm
Log:
Applied Paulo Matos's patch from #5135.
SendEmail didn't conform to RFC #2047.
Modified: rt/trunk/lib/RT/Action/SendEmail.pm
==============================================================================
--- rt/trunk/lib/RT/Action/SendEmail.pm (original)
+++ rt/trunk/lib/RT/Action/SendEmail.pm Mon Apr 26 19:01:15 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-commit
mailing list