Resend original

pull/209/head
M66B 3 years ago
parent 7a586a01ea
commit b64c4c6d2a

@ -928,104 +928,110 @@ public class MessageHelper {
// Build html body // Build html body
Document document = JsoupEx.parse(message.getFile(context)); Document document = JsoupEx.parse(message.getFile(context));
boolean resend = false;
if (message.headers != null && Boolean.TRUE.equals(message.resend)) { if (message.headers != null && Boolean.TRUE.equals(message.resend)) {
Element body = document.body(); Element body = document.body();
if (body.children().size() == 1) { if (body.children().size() == 1) {
// Restore original body // Restore original body
Element ref = body.children().get(0); Element ref = body.children().get(0);
body.replaceWith(ref.tagName("body").removeAttr("fairemail")); if ("reference".equals(ref.attr("fairemail"))) {
body.replaceWith(ref.tagName("body").removeAttr("fairemail"));
resend = true;
}
} }
} }
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang if (!resend) {
if (message.language != null) // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang
document.body().attr("lang", message.language); if (message.language != null)
document.body().attr("lang", message.language);
// When sending message
if (identity != null && send) {
if (auto_link) {
HtmlHelper.guessSchemes(document);
HtmlHelper.autoLink(document, true);
}
if (!TextUtils.isEmpty(compose_font)) {
List<Node> childs = new ArrayList<>();
for (Node child : document.body().childNodes())
if (TextUtils.isEmpty(child.attr("fairemail"))) {
childs.add(child);
child.remove();
} else
break;
Element div = document.createElement("div").attr("style",
"font-family:" + StyleHelper.getFamily(compose_font));
for (Node child : childs)
div.appendChild(child);
document.body().prependChild(div);
}
document.select("div[fairemail=signature]").removeAttr("fairemail");
document.select("div[fairemail=reference]").removeAttr("fairemail");
Elements reply = document.select("div[fairemail=reply]");
if (message.isPlainOnly())
reply.select("strong").tagName("span");
reply.removeAttr("fairemail");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (Element img : document.select("img")) {
String source = img.attr("src");
if (!source.startsWith("content:"))
continue;
Uri uri = Uri.parse(source); // When sending message
DocumentFile dfile = DocumentFile.fromSingleUri(context, uri); if (identity != null && send) {
if (dfile == null) if (auto_link) {
continue; HtmlHelper.guessSchemes(document);
HtmlHelper.autoLink(document, true);
}
String name = dfile.getName(); if (!TextUtils.isEmpty(compose_font)) {
String type = dfile.getType(); List<Node> childs = new ArrayList<>();
for (Node child : document.body().childNodes())
if (TextUtils.isEmpty(child.attr("fairemail"))) {
childs.add(child);
child.remove();
} else
break;
if (TextUtils.isEmpty(name)) Element div = document.createElement("div").attr("style",
name = uri.getLastPathSegment(); "font-family:" + StyleHelper.getFamily(compose_font));
if (TextUtils.isEmpty(type)) for (Node child : childs)
type = "image/*"; div.appendChild(child);
document.body().prependChild(div);
}
String cid = BuildConfig.APPLICATION_ID + ".content." + Math.abs(source.hashCode()); document.select("div[fairemail=signature]").removeAttr("fairemail");
String acid = "<" + cid + ">"; document.select("div[fairemail=reference]").removeAttr("fairemail");
if (db.attachment().getAttachment(message.id, acid) == null) { Elements reply = document.select("div[fairemail=reply]");
EntityAttachment attachment = new EntityAttachment(); if (message.isPlainOnly())
attachment.message = message.id; reply.select("strong").tagName("span");
attachment.sequence = db.attachment().getAttachmentSequence(message.id) + 1; reply.removeAttr("fairemail");
attachment.name = name;
attachment.type = type;
attachment.disposition = Part.INLINE;
attachment.cid = acid;
attachment.related = true;
attachment.size = null;
attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment);
attachment.size = Helper.copy(context, uri, attachment.getFile(context)); DB db = DB.getInstance(context);
attachment.progress = null; try {
attachment.available = true; db.beginTransaction();
db.attachment().setDownloaded(attachment.id, attachment.size);
for (Element img : document.select("img")) {
String source = img.attr("src");
if (!source.startsWith("content:"))
continue;
Uri uri = Uri.parse(source);
DocumentFile dfile = DocumentFile.fromSingleUri(context, uri);
if (dfile == null)
continue;
String name = dfile.getName();
String type = dfile.getType();
if (TextUtils.isEmpty(name))
name = uri.getLastPathSegment();
if (TextUtils.isEmpty(type))
type = "image/*";
String cid = BuildConfig.APPLICATION_ID + ".content." + Math.abs(source.hashCode());
String acid = "<" + cid + ">";
if (db.attachment().getAttachment(message.id, acid) == null) {
EntityAttachment attachment = new EntityAttachment();
attachment.message = message.id;
attachment.sequence = db.attachment().getAttachmentSequence(message.id) + 1;
attachment.name = name;
attachment.type = type;
attachment.disposition = Part.INLINE;
attachment.cid = acid;
attachment.related = true;
attachment.size = null;
attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment);
attachment.size = Helper.copy(context, uri, attachment.getFile(context));
attachment.progress = null;
attachment.available = true;
db.attachment().setDownloaded(attachment.id, attachment.size);
attachments.add(attachment);
}
attachments.add(attachment); img.attr("src", "cid:" + cid);
} }
img.attr("src", "cid:" + cid); db.setTransactionSuccessful();
} catch (Throwable ex) {
Log.w(ex);
} finally {
db.endTransaction();
} }
db.setTransactionSuccessful();
} catch (Throwable ex) {
Log.w(ex);
} finally {
db.endTransaction();
} }
} }

Loading…
Cancel
Save