Prevent error

pull/156/head
M66B 6 years ago
parent b882b821a7
commit 50992a49d5

@ -1187,10 +1187,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null) if (message == null || !message.content)
throw new FileNotFoundException(); return null;
String html = Helper.readText(message.getFile(context)); File file = message.getFile(context);
if (!file.exists())
return null;
String html = Helper.readText(file);
html = HtmlHelper.getHtmlEmbedded(context, id, html); html = HtmlHelper.getHtmlEmbedded(context, id, html);
html = HtmlHelper.removeTracking(context, html); html = HtmlHelper.removeTracking(context, html);
@ -1199,6 +1203,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onExecuted(Bundle args, final String[] data) { protected void onExecuted(Bundle args, final String[] data) {
if (data == null)
return;
// https://developer.android.com/training/printing/html-docs.html // https://developer.android.com/training/printing/html-docs.html
printWebView = new WebView(ActivityView.this); printWebView = new WebView(ActivityView.this);
WebSettings settings = printWebView.getSettings(); WebSettings settings = printWebView.getSettings();
@ -1299,9 +1306,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (encrypted == null) { if (encrypted == null) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
String body = Helper.readText(message.getFile(context)); if (message != null && message.content) {
File file = message.getFile(context);
if (file.exists()) {
// https://tools.ietf.org/html/rfc4880#section-6.2 // https://tools.ietf.org/html/rfc4880#section-6.2
String body = Helper.readText(file);
int begin = body.indexOf(PGP_BEGIN_MESSAGE); int begin = body.indexOf(PGP_BEGIN_MESSAGE);
int end = body.indexOf(PGP_END_MESSAGE); int end = body.indexOf(PGP_END_MESSAGE);
if (begin >= 0 && begin < end) { if (begin >= 0 && begin < end) {
@ -1317,6 +1326,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
encrypted = new ByteArrayInputStream(section.getBytes()); encrypted = new ByteArrayInputStream(section.getBytes());
} }
} }
}
}
if (encrypted == null) if (encrypted == null)
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted)); throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));

@ -107,7 +107,6 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.DateFormat; import java.text.DateFormat;
@ -1468,11 +1467,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null) if (message == null || !message.content)
throw new FileNotFoundException(); return null;
File file = message.getFile(context);
if (!file.exists())
return null;
OriginalMessage original = new OriginalMessage(); OriginalMessage original = new OriginalMessage();
original.html = Helper.readText(message.getFile(context)); original.html = Helper.readText(file);
original.html = HtmlHelper.getHtmlEmbedded(context, id, original.html); original.html = HtmlHelper.getHtmlEmbedded(context, id, original.html);
original.html = HtmlHelper.removeTracking(context, original.html); original.html = HtmlHelper.removeTracking(context, original.html);
@ -1484,6 +1487,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
protected void onExecuted(Bundle args, OriginalMessage original) { protected void onExecuted(Bundle args, OriginalMessage original) {
if (original == null)
return;
long id = args.getLong("id"); long id = args.getLong("id");
properties.setHtml(id, original.html); properties.setHtml(id, original.html);
if (!original.has_images) if (!original.has_images)
@ -1730,7 +1736,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean show_quotes = args.getBoolean("show_quotes"); boolean show_quotes = args.getBoolean("show_quotes");
int zoom = args.getInt("zoom"); int zoom = args.getInt("zoom");
String body = Helper.readText(message.getFile(context)); if (message == null || !message.content)
return null;
File file = message.getFile(context);
if (!file.exists())
return null;
String body = Helper.readText(file);
if (!show_quotes) { if (!show_quotes) {
Document document = Jsoup.parse(body); Document document = Jsoup.parse(body);
@ -2452,20 +2465,27 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null || !message.content)
return null;
File file = message.getFile(context);
if (!file.exists())
return null;
String from = null; String from = null;
if (message.from != null && message.from.length > 0) if (message.from != null && message.from.length > 0)
from = ((InternetAddress) message.from[0]).getAddress(); from = ((InternetAddress) message.from[0]).getAddress();
return new String[]{ String html = HtmlHelper.getText(Helper.readText(file));
from,
message.subject, return new String[]{from, message.subject, html};
HtmlHelper.getText(Helper.readText(message.getFile(context)))
};
} }
@Override @Override
protected void onExecuted(Bundle args, String[] text) { protected void onExecuted(Bundle args, String[] text) {
if (text == null)
return;
Intent share = new Intent(); Intent share = new Intent();
share.setAction(Intent.ACTION_SEND); share.setAction(Intent.ACTION_SEND);
share.setType("text/plain"); share.setType("text/plain");
@ -2473,6 +2493,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
share.putExtra(Intent.EXTRA_EMAIL, new String[]{text[0]}); share.putExtra(Intent.EXTRA_EMAIL, new String[]{text[0]});
if (!TextUtils.isEmpty(text[1])) if (!TextUtils.isEmpty(text[1]))
share.putExtra(Intent.EXTRA_SUBJECT, text[1]); share.putExtra(Intent.EXTRA_SUBJECT, text[1]);
if (!TextUtils.isEmpty(text[2]))
share.putExtra(Intent.EXTRA_TEXT, text[2]); share.putExtra(Intent.EXTRA_TEXT, text[2]);
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();

@ -122,7 +122,6 @@ import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -584,8 +583,8 @@ public class FragmentCompose extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage draft = db.message().getMessage(id); EntityMessage draft = db.message().getMessage(id);
if (draft == null) if (draft == null || !draft.content)
throw new FileNotFoundException(); throw new IllegalArgumentException(context.getString(R.string.title_no_body));
File file = draft.getFile(context); File file = draft.getFile(context);
File refFile = draft.getRefFile(context); File refFile = draft.getRefFile(context);
@ -2850,8 +2849,8 @@ public class FragmentCompose extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage draft = db.message().getMessage(id); EntityMessage draft = db.message().getMessage(id);
if (draft == null) if (draft == null || !draft.content)
throw new FileNotFoundException(); throw new IllegalArgumentException(context.getString(R.string.title_no_body));
String body = Helper.readText(draft.getFile(context)); String body = Helper.readText(draft.getFile(context));
Spanned spannedBody = HtmlHelper.fromHtml(body, cidGetter, null); Spanned spannedBody = HtmlHelper.fromHtml(body, cidGetter, null);

Loading…
Cancel
Save