Remove inline images on send only

This commit is contained in:
M66B
2019-11-16 18:56:03 +01:00
parent 3b1a10497d
commit c81d4bdad2
2 changed files with 20 additions and 20 deletions

View File

@@ -3027,25 +3027,6 @@ public class FragmentCompose extends FragmentBase {
db.message().setMessageReceived(draft.id, draft.received);
}
// Remove unused inline images
StringBuilder sb = new StringBuilder();
sb.append(body);
File rfile = draft.getRefFile(context);
if (rfile.exists())
sb.append(Helper.readText(rfile));
List<String> cids = new ArrayList<>();
for (Element element : JsoupEx.parse(sb.toString()).select("img")) {
String src = element.attr("src");
if (src.startsWith("cid:"))
cids.add("<" + src.substring(4) + ">");
}
for (EntityAttachment attachment : new ArrayList<>(attachments))
if (attachment.isInline() && !cids.contains(attachment.cid)) {
Log.i("Removing unused inline attachment cid=" + attachment.cid);
db.attachment().deleteAttachment(attachment.id);
}
// Execute action
if (action == R.id.action_save ||
action == R.id.action_undo ||
@@ -3112,6 +3093,25 @@ public class FragmentCompose extends FragmentBase {
}
} else if (action == R.id.action_send) {
// Remove unused inline images
StringBuilder sb = new StringBuilder();
sb.append(body);
File rfile = draft.getRefFile(context);
if (rfile.exists())
sb.append(Helper.readText(rfile));
List<String> cids = new ArrayList<>();
for (Element element : JsoupEx.parse(sb.toString()).select("img")) {
String src = element.attr("src");
if (src.startsWith("cid:"))
cids.add("<" + src.substring(4) + ">");
}
for (EntityAttachment attachment : new ArrayList<>(attachments))
if (attachment.isInline() && !cids.contains(attachment.cid)) {
Log.i("Removing unused inline attachment cid=" + attachment.cid);
db.attachment().deleteAttachment(attachment.id);
}
// Delete draft (cannot move to outbox)
EntityOperation.queue(context, draft, EntityOperation.DELETE);