mirror of https://github.com/M66B/FairEmail.git
Prevent Jsoup from throwing up
This commit is contained in:
parent
4afb121fbe
commit
ea4c7fa8f2
|
@ -124,7 +124,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
|
@ -2672,7 +2671,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String body = Helper.readText(file);
|
String body = Helper.readText(file);
|
||||||
Document document = Jsoup.parse(body);
|
Document document = JsoupEx.parse(body);
|
||||||
|
|
||||||
// Check for inline encryption
|
// Check for inline encryption
|
||||||
int begin = body.indexOf(Helper.PGP_BEGIN_MESSAGE);
|
int begin = body.indexOf(Helper.PGP_BEGIN_MESSAGE);
|
||||||
|
@ -2705,7 +2704,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
// Cleanup message
|
// Cleanup message
|
||||||
String html = HtmlHelper.sanitize(context, body, text_color, show_images);
|
String html = HtmlHelper.sanitize(context, body, text_color, show_images);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
Document format = Jsoup.parse(html);
|
Document format = JsoupEx.parse(html);
|
||||||
format.outputSettings().prettyPrint(true).outline(true).indentAmount(1);
|
format.outputSettings().prettyPrint(true).outline(true).indentAmount(1);
|
||||||
String[] lines = format.html().split("\\r?\\n");
|
String[] lines = format.html().split("\\r?\\n");
|
||||||
for (int i = 0; i < lines.length; i++)
|
for (int i = 0; i < lines.length; i++)
|
||||||
|
@ -4225,7 +4224,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
|
|
||||||
String html = Helper.readText(file);
|
String html = Helper.readText(file);
|
||||||
|
|
||||||
Document doc = Jsoup.parse(html);
|
Document doc = JsoupEx.parse(html);
|
||||||
HtmlHelper.removeViewportLimitations(doc);
|
HtmlHelper.removeViewportLimitations(doc);
|
||||||
HtmlHelper.embedImages(context, id, doc);
|
HtmlHelper.embedImages(context, id, doc);
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ import com.sun.mail.util.MessageRemovedIOException;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
@ -2525,7 +2524,7 @@ class Core {
|
||||||
|
|
||||||
private static void fixAttachments(Context context, long id, String body) {
|
private static void fixAttachments(Context context, long id, String body) {
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
for (Element element : Jsoup.parse(body).select("img")) {
|
for (Element element : JsoupEx.parse(body).select("img")) {
|
||||||
String src = element.attr("src");
|
String src = element.attr("src");
|
||||||
if (src.startsWith("cid:")) {
|
if (src.startsWith("cid:")) {
|
||||||
EntityAttachment attachment = db.attachment().getAttachment(id, "<" + src.substring(4) + ">");
|
EntityAttachment attachment = db.attachment().getAttachment(id, "<" + src.substring(4) + ">");
|
||||||
|
|
|
@ -103,7 +103,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.nodes.Node;
|
import org.jsoup.nodes.Node;
|
||||||
|
@ -1799,7 +1798,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmpty() {
|
private boolean isEmpty() {
|
||||||
if (!TextUtils.isEmpty(Jsoup.parse(HtmlHelper.toHtml(etBody.getText())).text().trim()))
|
if (!TextUtils.isEmpty(JsoupEx.parse(HtmlHelper.toHtml(etBody.getText())).text().trim()))
|
||||||
return false;
|
return false;
|
||||||
if (rvAttachment.getAdapter().getItemCount() > 0)
|
if (rvAttachment.getAdapter().getItemCount() > 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -2330,7 +2329,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
boolean usenet = prefs.getBoolean("usenet_signature", false);
|
boolean usenet = prefs.getBoolean("usenet_signature", false);
|
||||||
if (usenet) {
|
if (usenet) {
|
||||||
Document rdoc = Jsoup.parse(refText);
|
Document rdoc = JsoupEx.parse(refText);
|
||||||
|
|
||||||
List<Node> tbd = new ArrayList<>();
|
List<Node> tbd = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -2832,7 +2831,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
if (rfile.exists())
|
if (rfile.exists())
|
||||||
sb.append(Helper.readText(rfile));
|
sb.append(Helper.readText(rfile));
|
||||||
List<String> cids = new ArrayList<>();
|
List<String> cids = new ArrayList<>();
|
||||||
for (Element element : Jsoup.parse(sb.toString()).select("img")) {
|
for (Element element : JsoupEx.parse(sb.toString()).select("img")) {
|
||||||
String src = element.attr("src");
|
String src = element.attr("src");
|
||||||
if (src.startsWith("cid:"))
|
if (src.startsWith("cid:"))
|
||||||
cids.add("<" + src.substring(4) + ">");
|
cids.add("<" + src.substring(4) + ">");
|
||||||
|
|
|
@ -107,7 +107,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.sun.mail.util.FolderClosedIOException;
|
import com.sun.mail.util.FolderClosedIOException;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
|
@ -3870,8 +3869,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
// Write decrypted body
|
// Write decrypted body
|
||||||
Helper.writeText(message.getFile(context),
|
Helper.writeText(message.getFile(context), decrypted.toString());
|
||||||
decrypted.toString().replace("\0", ""));
|
|
||||||
|
|
||||||
db.message().setMessageStored(id, new Date().getTime());
|
db.message().setMessageStored(id, new Date().getTime());
|
||||||
|
|
||||||
|
@ -3894,8 +3892,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
|
|
||||||
// Write decrypted body
|
// Write decrypted body
|
||||||
String html = parts.getHtml(context);
|
String html = parts.getHtml(context);
|
||||||
if (html != null)
|
|
||||||
html = html.replace("\0", "");
|
|
||||||
Helper.writeText(message.getFile(context), html);
|
Helper.writeText(message.getFile(context), html);
|
||||||
|
|
||||||
// Remove previously decrypted attachments
|
// Remove previously decrypted attachments
|
||||||
|
@ -4336,7 +4332,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String html = Helper.readText(file);
|
String html = Helper.readText(file);
|
||||||
Document document = Jsoup.parse(html);
|
Document document = JsoupEx.parse(html);
|
||||||
HtmlHelper.embedImages(context, id, document);
|
HtmlHelper.embedImages(context, id, document);
|
||||||
|
|
||||||
Element body = document.body();
|
Element body = document.body();
|
||||||
|
|
|
@ -49,7 +49,6 @@ import androidx.core.text.HtmlCompat;
|
||||||
import androidx.core.util.PatternsCompat;
|
import androidx.core.util.PatternsCompat;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Attribute;
|
import org.jsoup.nodes.Attribute;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
@ -98,7 +97,7 @@ public class HtmlHelper {
|
||||||
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||||
|
|
||||||
static String sanitize(Context context, String html, boolean text_color, boolean show_images) {
|
static String sanitize(Context context, String html, boolean text_color, boolean show_images) {
|
||||||
Document parsed = Jsoup.parse(html);
|
Document parsed = JsoupEx.parse(html);
|
||||||
|
|
||||||
// <html xmlns:v="urn:schemas-microsoft-com:vml"
|
// <html xmlns:v="urn:schemas-microsoft-com:vml"
|
||||||
// xmlns:o="urn:schemas-microsoft-com:office:office"
|
// xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||||
|
@ -815,7 +814,7 @@ public class HtmlHelper {
|
||||||
if (body == null)
|
if (body == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String text = Jsoup.parse(body).text();
|
String text = JsoupEx.parse(body).text();
|
||||||
|
|
||||||
String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE));
|
String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE));
|
||||||
if (preview.length() < text.length())
|
if (preview.length() < text.length())
|
||||||
|
@ -897,7 +896,7 @@ public class HtmlHelper {
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
nl = true;
|
nl = true;
|
||||||
}
|
}
|
||||||
}, Jsoup.parse(html));
|
}, JsoupEx.parse(html));
|
||||||
|
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
|
|
||||||
|
@ -999,7 +998,7 @@ public class HtmlHelper {
|
||||||
String html = HtmlCompat.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
|
String html = HtmlCompat.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
|
||||||
|
|
||||||
// @Google: why convert size to and from in a different way?
|
// @Google: why convert size to and from in a different way?
|
||||||
Document doc = Jsoup.parse(html);
|
Document doc = JsoupEx.parse(html);
|
||||||
for (Element element : doc.select("span")) {
|
for (Element element : doc.select("span")) {
|
||||||
String style = element.attr("style");
|
String style = element.attr("style");
|
||||||
if (style.startsWith("font-size:")) {
|
if (style.startsWith("font-size:")) {
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
|
public class JsoupEx {
|
||||||
|
static Document parse(String html) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
org.jsoup.UncheckedIOException: java.io.IOException: Input is binary and unsupported
|
||||||
|
at org.jsoup.parser.CharacterReader.<init>(SourceFile:38)
|
||||||
|
at org.jsoup.parser.CharacterReader.<init>(SourceFile:43)
|
||||||
|
at org.jsoup.parser.TreeBuilder.initialiseParse(SourceFile:38)
|
||||||
|
at org.jsoup.parser.HtmlTreeBuilder.initialiseParse(SourceFile:65)
|
||||||
|
at org.jsoup.parser.TreeBuilder.parse(SourceFile:46)
|
||||||
|
at org.jsoup.parser.Parser.parse(SourceFile:107)
|
||||||
|
at org.jsoup.Jsoup.parse(SourceFile:58)
|
||||||
|
*/
|
||||||
|
return Jsoup.parse(html.replace("\0", ""));
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,6 @@ import androidx.preference.PreferenceManager;
|
||||||
import com.sun.mail.util.FolderClosedIOException;
|
import com.sun.mail.util.FolderClosedIOException;
|
||||||
import com.sun.mail.util.MessageRemovedIOException;
|
import com.sun.mail.util.MessageRemovedIOException;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -310,14 +309,14 @@ public class MessageHelper {
|
||||||
StringBuilder body = new StringBuilder();
|
StringBuilder body = new StringBuilder();
|
||||||
body.append("<html><body>");
|
body.append("<html><body>");
|
||||||
|
|
||||||
Document mdoc = Jsoup.parse(Helper.readText(message.getFile(context)));
|
Document mdoc = JsoupEx.parse(Helper.readText(message.getFile(context)));
|
||||||
if (mdoc.body() != null)
|
if (mdoc.body() != null)
|
||||||
body.append(mdoc.body().html());
|
body.append(mdoc.body().html());
|
||||||
|
|
||||||
// When sending message
|
// When sending message
|
||||||
if (identity != null) {
|
if (identity != null) {
|
||||||
if (!TextUtils.isEmpty(identity.signature) && message.signature) {
|
if (!TextUtils.isEmpty(identity.signature) && message.signature) {
|
||||||
Document sdoc = Jsoup.parse(identity.signature);
|
Document sdoc = JsoupEx.parse(identity.signature);
|
||||||
if (sdoc.body() != null) {
|
if (sdoc.body() != null) {
|
||||||
if (usenet) // https://www.ietf.org/rfc/rfc3676.txt
|
if (usenet) // https://www.ietf.org/rfc/rfc3676.txt
|
||||||
body.append("<span>-- <br></span>");
|
body.append("<span>-- <br></span>");
|
||||||
|
@ -1022,8 +1021,6 @@ public class MessageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent Jsoup throwing an exception
|
// Prevent Jsoup throwing an exception
|
||||||
result = result.replace("\0", "");
|
|
||||||
|
|
||||||
if (part == plain) {
|
if (part == plain) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("<span>");
|
sb.append("<span>");
|
||||||
|
|
Loading…
Reference in New Issue