james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r531877 - in /james/mime4j/trunk/src/main/java/org/mime4j: field/Field.java message/TempFileTextBody.java util/CharsetUtil.java
Date Tue, 24 Apr 2007 11:06:07 GMT
Author: norman
Date: Tue Apr 24 04:06:05 2007
New Revision: 531877

URL: http://svn.apache.org/viewvc?view=rev&rev=531877
Log:
Fallback defaultcharset if writing and the charset can not detected

Modified:
    james/mime4j/trunk/src/main/java/org/mime4j/field/Field.java
    james/mime4j/trunk/src/main/java/org/mime4j/message/TempFileTextBody.java
    james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java

Modified: james/mime4j/trunk/src/main/java/org/mime4j/field/Field.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/field/Field.java?view=diff&rev=531877&r1=531876&r2=531877
==============================================================================
--- james/mime4j/trunk/src/main/java/org/mime4j/field/Field.java (original)
+++ james/mime4j/trunk/src/main/java/org/mime4j/field/Field.java Tue Apr 24 04:06:05 2007
@@ -183,6 +183,9 @@
         return TO.equalsIgnoreCase(name);
     }
     
+    /**
+     * @see #getRaw()
+     */
     public String toString() {
         return raw;
     }

Modified: james/mime4j/trunk/src/main/java/org/mime4j/message/TempFileTextBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/message/TempFileTextBody.java?view=diff&rev=531877&r1=531876&r2=531877
==============================================================================
--- james/mime4j/trunk/src/main/java/org/mime4j/message/TempFileTextBody.java (original)
+++ james/mime4j/trunk/src/main/java/org/mime4j/message/TempFileTextBody.java Tue Apr 24 04:06:05
2007
@@ -74,7 +74,7 @@
         }
         
         if (javaCharset == null) {
-            javaCharset = "ISO8859-1";
+            javaCharset = "ISO-8859-1";
             
             if (log.isWarnEnabled()) {
                 if (mimeCharset == null) {

Modified: james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531877&r1=531876&r2=531877
==============================================================================
--- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java (original)
+++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java Tue Apr 24 04:06:05
2007
@@ -20,6 +20,8 @@
 package org.mime4j.util;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
 import java.util.HashMap;
 import java.util.TreeSet;
 
@@ -1119,15 +1121,22 @@
     }
 
     public static java.nio.charset.Charset getCharset(String charsetName) {
-        if(charsetName == null) charsetName = "ISO8859-1";
-            
-        java.nio.charset.Charset c = java.nio.charset.Charset.forName(charsetName);
+        String defaultCharset = "ISO-8851-1";
         
-        if (c == null) {
-            c = java.nio.charset.Charset.forName("ISO8859-1");
+        // Use the default chareset if given charset is null
+        if(charsetName == null) charsetName = defaultCharset;
             
+        try {
+            return java.nio.charset.Charset.forName(charsetName);
+        } catch (IllegalCharsetNameException e) {
+            log.info("Illegal charset " + charsetName + ", fallback to " + defaultCharset
+ ": " + e);
+            // Use default charset on exception 
+            return java.nio.charset.Charset.forName(defaultCharset);
+        } catch (UnsupportedCharsetException ex) {
+            log.info("Unsupported charset " + charsetName + ", fallback to " + defaultCharset
+ ": " + ex);
+            // Use default charset on exception
+            return java.nio.charset.Charset.forName(defaultCharset);
         }
-        return c;
         
     }
     /*



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message