[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.6-208-g1d7f154
? sunnavy
sunnavy at bestpractical.com
Thu Nov 25 01:48:47 EST 2010
The branch, 3.9-trunk has been updated
via 1d7f15406f1bcd1027c7cc44eaad361e988899e5 (commit)
via f5ca89fdf83ce9bd27b144eb1bcaa58bf5ec065f (commit)
via d71a25ebf6ccab45aead161cc8e3962c665b9546 (commit)
from adad1f44d54f6e863a7bfdfeeeedf66b57372863 (commit)
Summary of changes:
lib/RT/Dashboard/Mailer.pm | 2 +-
lib/RT/I18N.pm | 44 ++++++++++++++++++++++++++++++++------------
t/api/canonical_charset.t | 28 ++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 13 deletions(-)
create mode 100644 t/api/canonical_charset.t
- Log -----------------------------------------------------------------
commit d71a25ebf6ccab45aead161cc8e3962c665b9546
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Nov 25 13:50:54 2010 +0800
add RT::I18N::_CanonicalizeCharset
diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index e656994..6387fd4 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -214,9 +214,6 @@ sub SetMIMEEntityToEncoding {
SetMIMEEntityToEncoding( $_, $enc, $preserve_words ) foreach $entity->parts;
my $charset = _FindOrGuessCharset($entity) or return;
- # one and only normalization
- $charset = 'utf-8' if $charset =~ /^utf-?8$/i;
- $enc = 'utf-8' if $enc =~ /^utf-?8$/i;
SetMIMEHeadToEncoding(
$entity->head,
@@ -433,16 +430,17 @@ sub _FindOrGuessCharset {
my $head = $entity->head;
if ( my $charset = $head->mime_attr("content-type.charset") ) {
- return $charset;
+ return _CanonicalizeCharset($charset);
}
- if ( !$head_only and $head->mime_type =~ m{^text/}) {
- my $body = $entity->bodyhandle or return;
- return _GuessCharset( $body->as_string );
+ if ( !$head_only and $head->mime_type =~ m{^text/} ) {
+ my $body = $entity->bodyhandle or return;
+ return _GuessCharset( $body->as_string );
}
else {
- # potentially binary data -- don't guess the body
- return _GuessCharset( $head->as_string );
+
+ # potentially binary data -- don't guess the body
+ return _GuessCharset( $head->as_string );
}
}
@@ -497,9 +495,31 @@ sub _GuessCharset {
$RT::Logger->warning("No EmailInputEncodings set, fallback to $fallback");
}
- return ($charset || $fallback);
+ return _CanonicalizeCharset($charset || $fallback);
}
+=head2 _CanonicalizeCharset NAME
+
+canonicalize charset, return lowercase version.
+special cases are: gb2312 => gbk, utf8 => utf-8
+
+=cut
+
+sub _CanonicalizeCharset {
+ my $charset = lc shift;
+ return $charset unless $charset;
+
+ if ( $charset eq 'utf8' ) {
+ return 'utf-8';
+ }
+ elsif ( $charset eq 'gb2312' ) {
+ # gbk is superset of gb2312 so it's safe
+ return 'gbk';
+ }
+ else {
+ return $charset;
+ }
+}
=head2 SetMIMEHeadToEncoding HEAD OLD_CHARSET NEW_CHARSET
@@ -514,8 +534,8 @@ all the time
sub SetMIMEHeadToEncoding {
my ( $head, $charset, $enc, $preserve_words ) = ( shift, shift, shift, shift );
- $charset = 'utf-8' if $charset eq 'utf8';
- $enc = 'utf-8' if $enc eq 'utf8';
+ $charset = _CanonicalizeCharset($charset);
+ $enc = _CanonicalizeCharset($enc);
return if $charset eq $enc and $preserve_words;
commit f5ca89fdf83ce9bd27b144eb1bcaa58bf5ec065f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Nov 25 13:51:33 2010 +0800
test for RT::I18N::_CanonicalizeCharset
diff --git a/t/api/canonical_charset.t b/t/api/canonical_charset.t
new file mode 100644
index 0000000..05dfa58
--- /dev/null
+++ b/t/api/canonical_charset.t
@@ -0,0 +1,28 @@
+use warnings;
+use strict;
+
+use RT::Test nodata => 1, tests => 7;
+use RT::I18N;
+use Encode;
+
+my %map = (
+ gb2312 => 'gbk',
+ utf8 => 'utf-8',
+ 'utf-8' => 'utf-8',
+);
+
+for my $charset ( keys %map ) {
+ is( RT::I18N::_CanonicalizeCharset($charset),
+ $map{$charset}, "$charset => $map{$charset}" );
+ is( RT::I18N::_CanonicalizeCharset( uc $charset ),
+ $map{$charset}, uc( $charset ) . " => $map{$charset}" );
+}
+
+my $mime = MIME::Entity->build(
+ Type => 'text/plain; charset=gb2312',
+ Data => [encode('gbk', decode_utf8("æ³æ°ç¤¾å«æ¦11æ¥é»"))],
+);
+
+RT::I18N::SetMIMEEntityToUTF8($mime);
+is( $mime->stringify_body, 'æ³æ°ç¤¾å«æ¦11æ¥é»', 'gb2312 => gbk in mail' );
+
commit 1d7f15406f1bcd1027c7cc44eaad361e988899e5
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Nov 25 14:34:22 2010 +0800
RT->Config->Get auto dereference if config variable is @ or %
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 07e3d01..1cfa732 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -227,7 +227,7 @@ SUMMARY
Preview => 0,
);
- for (@{ RT->Config->Get('EmailDashboardRemove') || [] }) {
+ for (RT->Config->Get('EmailDashboardRemove')) {
$content =~ s/$_//g;
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list