mirror of https://github.com/M66B/FairEmail.git
Guess unspecified character sets
This commit is contained in:
parent
1f1332a169
commit
e564c18b90
|
@ -137,6 +137,7 @@ FairEmail uses:
|
|||
* [JavaMail](https://projects.eclipse.org/projects/ee4j.javamail). Copyright (c) 1997-2018 Oracle® and/or its affiliates. All rights reserved. [GPLv2+CE license](https://javaee.github.io/javamail/JavaMail-License).
|
||||
* [jsoup](https://jsoup.org/). Copyright © 2009 - 2017 Jonathan Hedley. [MIT license](https://jsoup.org/license).
|
||||
* ~~[JCharset](http://www.freeutils.net/source/jcharset/). Copyright © 2005-2015 Amichai Rothman. [GNU General Public License](http://www.freeutils.net/source/jcharset/#license)~~
|
||||
* [ICU4J](http://site.icu-project.org). Copyright © 1991-2019 Unicode, Inc. All rights reserved. [UNICODE, INC. LICENSE AGREEMENT](http://www.unicode.org/copyright.html#License)
|
||||
* [Android Support Library](https://developer.android.com/tools/support-library/). Copyright (C) 2011 The Android Open Source Project. [Apache license](https://android.googlesource.com/platform/frameworks/support/+/master/LICENSE.txt).
|
||||
* [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/). Copyright 2018 The Android Open Source Project, Inc. [Apache license](https://github.com/googlesamples/android-architecture-components/blob/master/LICENSE).
|
||||
* [colorpicker](https://android.googlesource.com/platform/frameworks/opt/colorpicker). Copyright (C) 2013 The Android Open Source Project. [Apache license](https://android.googlesource.com/platform/frameworks/opt/colorpicker/+/master/src/com/android/colorpicker/ColorPickerDialog.java).
|
||||
|
|
|
@ -109,6 +109,7 @@ dependencies {
|
|||
def javamail_version = "1.6.3"
|
||||
def jsoup_version = "1.11.3"
|
||||
def jcharset_version = "2.0"
|
||||
def icu4j_version = "63.1"
|
||||
def dnsjava_version = "2.1.8"
|
||||
def openpgp_version = "12.0"
|
||||
def requery_version = "3.26.0"
|
||||
|
@ -160,6 +161,9 @@ dependencies {
|
|||
// http://www.freeutils.net/source/jcharset/
|
||||
//implementation "net.freeutils:jcharset:$jcharset_version"
|
||||
|
||||
// https://mvnrepository.com/artifact/com.ibm.icu/icu4j
|
||||
implementation "com.ibm.icu:icu4j:$icu4j_version"
|
||||
|
||||
// http://www.xbill.org/dnsjava/
|
||||
implementation "dnsjava:dnsjava:$dnsjava_version"
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -456,6 +456,7 @@
|
|||
<string name="title_no_adobe">Adobe Acrobat reader cannot open safely shared files, see the FAQ for more information</string>
|
||||
<string name="title_no_body">No message text found</string>
|
||||
<string name="title_no_charset">Unsupported encoding: %1$s</string>
|
||||
<string name="title_guessed_charset">Guessed encoding: %1$s</string>
|
||||
|
||||
<string name="title_try">Try FairEmail, an open source, privacy friendly email app for Android</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue