From f2283aa91efeac1947cb6539652b0b71ad52a540 Mon Sep 17 00:00:00 2001 From: Bernhard Redl Date: Sun, 1 May 2011 00:42:15 +0200 Subject: [PATCH] Catch IllegalCharsetNameException causing force-close on unsupported japanese charsets (issue 3272) --- src/com/fsck/k9/mail/internet/MimeUtility.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 84ce1e063..0fd320c0a 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -14,6 +14,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.regex.Pattern; import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; public class MimeUtility { @@ -1381,13 +1382,19 @@ public class MimeUtility { /* * See if there is conversion from the MIME charset to the Java one. + * this function may also throw an exception if the charset name is not known */ - if (!Charset.isSupported(charset)) { + boolean supported; + try { + supported = Charset.isSupported(charset); + } catch (IllegalCharsetNameException e) { + supported = false; + } + if (!supported) { Log.e(K9.LOG_TAG, "I don't know how to deal with the charset " + charset + ". Falling back to US-ASCII"); charset = "US-ASCII"; } - /* * Convert and return as new String */