mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 02:50:56 +01:00
Guess unspecified character sets
This commit is contained in:
@@ -23,6 +23,9 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.ibm.icu.text.CharsetDetector;
|
||||
import com.ibm.icu.text.CharsetMatch;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
@@ -564,7 +567,18 @@ public class MessageHelper {
|
||||
|
||||
ContentType ct = new ContentType(part.getContentType());
|
||||
String charset = ct.getParameter("charset");
|
||||
if (!TextUtils.isEmpty(charset)) {
|
||||
if (TextUtils.isEmpty(charset)) {
|
||||
try {
|
||||
CharsetDetector detector = new CharsetDetector();
|
||||
String defset = (part.isMimeType("text/plain") ? "US-ASCII" : "ISO-8859-1");
|
||||
detector.setText(result.getBytes(defset));
|
||||
CharsetMatch match = detector.detect();
|
||||
result = new String(result.getBytes(match.getName()));
|
||||
warnings.add(context.getString(R.string.title_guessed_charset, match.getName()));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
warnings.add(Helper.formatThrowable(ex));
|
||||
}
|
||||
} else {
|
||||
if ("US-ASCII".equals(Charset.forName(charset).name()) &&
|
||||
!"US-ASCII".equals(charset.toUpperCase()))
|
||||
warnings.add(context.getString(R.string.title_no_charset, charset));
|
||||
|
||||
Reference in New Issue
Block a user