Assume ISO-8859-1 if text/plain without charset

ICU4J is too large
pull/147/head
M66B 6 years ago
parent 2ac54627a0
commit 2709a66e34

@ -137,7 +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)
* ~~[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).

@ -162,7 +162,7 @@ dependencies {
//implementation "net.freeutils:jcharset:$jcharset_version"
// https://mvnrepository.com/artifact/com.ibm.icu/icu4j
implementation "com.ibm.icu:icu4j:$icu4j_version"
//implementation "com.ibm.icu:icu4j:$icu4j_version"
// http://www.xbill.org/dnsjava/
implementation "dnsjava:dnsjava:$dnsjava_version"

@ -23,9 +23,6 @@ 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;
@ -568,16 +565,15 @@ public class MessageHelper {
ContentType ct = new ContentType(part.getContentType());
String charset = ct.getParameter("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));
}
if (BuildConfig.DEBUG)
warnings.add(context.getString(R.string.title_no_charset, ct.toString()));
if (part.isMimeType("text/plain"))
try {
// The first 127 characters are the same as in US-ASCII
result = new String(result.getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException ex) {
warnings.add(Helper.formatThrowable(ex));
}
} else {
if ("US-ASCII".equals(Charset.forName(charset).name()) &&
!"US-ASCII".equals(charset.toUpperCase()))

@ -457,7 +457,6 @@
<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…
Cancel
Save