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);
EntityMessage message = db.message().getMessage(id);
if (message == null)
throw new FileNotFoundException();
if (message == null || !message.content)
return null;
File file = message.getFile(context);
if (!file.exists())
return null;
String html = Helper.readText(message.getFile(context));
String html = Helper.readText(file);
html = HtmlHelper.getHtmlEmbedded(context, id, html);
html = HtmlHelper.removeTracking(context, html);
@ -1199,6 +1203,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
protected void onExecuted(Bundle args, final String[] data) {
if (data == null)
return;
// https://developer.android.com/training/printing/html-docs.html
printWebView = new WebView(ActivityView.this);
WebSettings settings = printWebView.getSettings();
@ -1299,22 +1306,26 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (encrypted == null) {
EntityMessage message = db.message().getMessage(id);
String body = Helper.readText(message.getFile(context));
// https://tools.ietf.org/html/rfc4880#section-6.2
int begin = body.indexOf(PGP_BEGIN_MESSAGE);
int end = body.indexOf(PGP_END_MESSAGE);
if (begin >= 0 && begin < end) {
String section = body.substring(begin, end + PGP_END_MESSAGE.length());
String[] lines = section.split("<br />");
List<String> disarmored = new ArrayList<>();
for (String line : lines)
if (!TextUtils.isEmpty(line) && !line.contains(": "))
disarmored.add(line);
section = TextUtils.join("\n\r", disarmored);
inline = true;
encrypted = new ByteArrayInputStream(section.getBytes());
if (message != null && message.content) {
File file = message.getFile(context);
if (file.exists()) {
// https://tools.ietf.org/html/rfc4880#section-6.2
String body = Helper.readText(file);
int begin = body.indexOf(PGP_BEGIN_MESSAGE);
int end = body.indexOf(PGP_END_MESSAGE);
if (begin >= 0 && begin < end) {
String section = body.substring(begin, end + PGP_END_MESSAGE.length());
String[] lines = section.split("<br />");
List<String> disarmored = new ArrayList<>();
for (String line : lines)
if (!TextUtils.isEmpty(line) && !line.contains(": "))
disarmored.add(line);
section = TextUtils.join("\n\r", disarmored);
inline = true;
encrypted = new ByteArrayInputStream(section.getBytes());
}
}
}
}

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

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

Loading…
Cancel
Save