Remove inline images on send only

pull/168/head
M66B 6 years ago
parent 3b1a10497d
commit c81d4bdad2

@ -3027,25 +3027,6 @@ public class FragmentCompose extends FragmentBase {
db.message().setMessageReceived(draft.id, draft.received); 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 // Execute action
if (action == R.id.action_save || if (action == R.id.action_save ||
action == R.id.action_undo || action == R.id.action_undo ||
@ -3112,6 +3093,25 @@ public class FragmentCompose extends FragmentBase {
} }
} else if (action == R.id.action_send) { } 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) // Delete draft (cannot move to outbox)
EntityOperation.queue(context, draft, EntityOperation.DELETE); EntityOperation.queue(context, draft, EntityOperation.DELETE);

@ -605,7 +605,7 @@
<string name="title_no_format">The originally received message will be included</string> <string name="title_no_format">The originally received message will be included</string>
<string name="title_no_image">Image could not be decoded</string> <string name="title_no_image">Image could not be decoded</string>
<string name="title_no_search">Search on server is not available for this account</string> <string name="title_no_search">Search on server is not available for this account</string>
<string name="title_unused_inline">Unused inline images will be removed on save/send</string> <string name="title_unused_inline">Unused inline images will be removed on send</string>
<string name="title_accross_remark">Messages moved across accounts will be downloaded again resulting in extra data usage</string> <string name="title_accross_remark">Messages moved across accounts will be downloaded again resulting in extra data usage</string>
<string name="title_raw_saved">Raw message saved</string> <string name="title_raw_saved">Raw message saved</string>
<string name="title_attachment_saved">Attachment saved</string> <string name="title_attachment_saved">Attachment saved</string>

Loading…
Cancel
Save