[Rt-commit] r8351 - rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Tue Jul 31 21:40:37 EDT 2007


Author: ruz
Date: Tue Jul 31 21:40:37 2007
New Revision: 8351

Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/I18N.pm

Log:
I18N::_EncodeGuess()
* don't log anything if string is empty, just get out
* log error if we can not load Encode::Guess and we have work to be done


Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/I18N.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/I18N.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/I18N.pm	Tue Jul 31 21:40:37 2007
@@ -375,11 +375,14 @@
 
 sub _GuessCharset {
     my $fallback = 'iso-8859-1';
-    my $charset;
 
     # if $_[0] is null/empty, we don't guess its encoding
-    if ( $_[0] and RT->Config->Get('EmailInputEncodings') and eval { require Encode::Guess; 1 } ) {
-	Encode::Guess->set_suspects(RT->Config->Get('EmailInputEncodings'));
+    return $fallback unless defined $_[0] && length $_[0];
+
+    my $charset;
+    my @encodings = RT->Config->Get('EmailInputEncodings');
+    if ( @encodings and eval { require Encode::Guess; 1 } ) {
+	Encode::Guess->set_suspects( @encodings );
 	my $decoder = Encode::Guess->guess( $_[0] );
 
 	if ( ref $decoder ) {
@@ -402,11 +405,13 @@
 	    $RT::Logger->warning("Encode::Guess failed: $decoder; fallback to $fallback");
 	}
     }
-    else {
-	$RT::Logger->warning("Cannot Encode::Guess; fallback to $fallback");
+    elsif ( @encodings && $@ ) {
+        $RT::Logger->error("You have set EmailInputEncodings, but we couldn't load Encode::Guess: $@");
+    } else {
+        $RT::Logger->warning("No EmailInputEncodings set, fallback to $fallback");
     }
 
-    return($charset || $fallback);
+    return ($charset || $fallback);
 }
 
 # }}}


More information about the Rt-commit mailing list