From 52d6fed56d1edabf04e796fdd4a529b625e05009 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 14 Oct 2020 21:44:03 +0200 Subject: [PATCH] Replaced juniversalchardet by compact_enc_det --- ATTRIBUTION.md | 1 - app/build.gradle | 6 ------ app/src/main/assets/ATTRIBUTION.md | 2 +- .../java/eu/faircode/email/CharsetHelper.java | 20 ++----------------- 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 7ea7782857..e3c7f1c01e 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -27,5 +27,4 @@ FairEmail uses: * [GPX file type icon](https://www.flaticon.com/free-icon/gpx-file-format-variant_29258) made by [Freepik](https://www.flaticon.com/authors/freepik) from [Flaticon](https://www.flaticon.com). * [Disconnect's tracker protection lists](https://github.com/disconnectme/disconnect-tracking-protection). Copyright 2010-2020 Disconnect, Inc. [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license](https://github.com/disconnectme/disconnect-tracking-protection/blob/master/LICENSE). * [Over-Scroll Support For Android's RecyclerView, ListView, GridView, ScrollView ...](https://github.com/EverythingMe/overscroll-decor). Copyright (c) 2015, DoAT Media Ltd. [BSD-2-Clause License](https://github.com/EverythingMe/overscroll-decor/blob/master/LICENSE) -* [juniversalchardet](https://github.com/albfernandez/juniversalchardet). Copyright (C) 2001 the Initial Developer. All Rights Reserved. [GNU General Public License Version 2](https://github.com/albfernandez/juniversalchardet#license). * [Compact Encoding Detection](https://github.com/google/compact_enc_det). Copyright 2016 Google Inc. [Apache License 2.0](https://github.com/google/compact_enc_det/blob/master/LICENSE). diff --git a/app/build.gradle b/app/build.gradle index 91b5f84dfd..432703a64a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -241,7 +241,6 @@ dependencies { def overscroll_version = "1.1.0" def appauth_version = "0.7.1" def jcharset_version = "2.1" - def jchardet_version = "2.3.2" // https://developer.android.com/jetpack/androidx/releases/ @@ -402,9 +401,4 @@ dependencies { // http://www.freeutils.net/source/jcharset/ // https://mvnrepository.com/artifact/net.freeutils/jcharset implementation "net.freeutils:jcharset:$jcharset_version" - - // https://github.com/albfernandez/juniversalchardet - // https://www-archive.mozilla.org/projects/intl/chardet.html - // https://mvnrepository.com/artifact/com.github.albfernandez/juniversalchardet - implementation "com.github.albfernandez:juniversalchardet:$jchardet_version" } diff --git a/app/src/main/assets/ATTRIBUTION.md b/app/src/main/assets/ATTRIBUTION.md index e425ec1383..e3c7f1c01e 100644 --- a/app/src/main/assets/ATTRIBUTION.md +++ b/app/src/main/assets/ATTRIBUTION.md @@ -27,4 +27,4 @@ FairEmail uses: * [GPX file type icon](https://www.flaticon.com/free-icon/gpx-file-format-variant_29258) made by [Freepik](https://www.flaticon.com/authors/freepik) from [Flaticon](https://www.flaticon.com). * [Disconnect's tracker protection lists](https://github.com/disconnectme/disconnect-tracking-protection). Copyright 2010-2020 Disconnect, Inc. [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license](https://github.com/disconnectme/disconnect-tracking-protection/blob/master/LICENSE). * [Over-Scroll Support For Android's RecyclerView, ListView, GridView, ScrollView ...](https://github.com/EverythingMe/overscroll-decor). Copyright (c) 2015, DoAT Media Ltd. [BSD-2-Clause License](https://github.com/EverythingMe/overscroll-decor/blob/master/LICENSE) -* [juniversalchardet](https://github.com/albfernandez/juniversalchardet). Copyright (C) 2001 the Initial Developer. All Rights Reserved. [GNU General Public License Version 2](https://github.com/albfernandez/juniversalchardet#license). +* [Compact Encoding Detection](https://github.com/google/compact_enc_det). Copyright 2016 Google Inc. [Apache License 2.0](https://github.com/google/compact_enc_det/blob/master/LICENSE). diff --git a/app/src/main/java/eu/faircode/email/CharsetHelper.java b/app/src/main/java/eu/faircode/email/CharsetHelper.java index ed473117f5..873c849dc4 100644 --- a/app/src/main/java/eu/faircode/email/CharsetHelper.java +++ b/app/src/main/java/eu/faircode/email/CharsetHelper.java @@ -19,15 +19,11 @@ package eu.faircode.email; Copyright 2018-2020 by Marcel Bokhorst (M66B) */ -import org.mozilla.universalchardet.UniversalDetector; - import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; class CharsetHelper { - private static final int SAMPLE_SIZE = 1024; - static { System.loadLibrary("compact_enc_det"); } @@ -129,20 +125,8 @@ class CharsetHelper { static Charset detect(String text) { try { byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1); - Log.i("compact_enc_det=" + jni_detect(octets)); - - int offset = 0; - UniversalDetector detector = new UniversalDetector(); - while (offset < octets.length && !detector.isDone()) { - detector.handleData(octets, offset, Math.min(SAMPLE_SIZE, octets.length - offset)); - offset += SAMPLE_SIZE; - } - detector.dataEnd(); - - String detected = detector.getDetectedCharset(); - if (detected == null) - return null; - + String detected = jni_detect(octets); + Log.i("compact_enc_det=" + detected); return Charset.forName(detected); } catch (Throwable ex) { Log.w(ex);