Plain text: always attach images

This commit is contained in:
M66B 2020-04-08 09:12:36 +02:00
parent c009f1c4bf
commit 50bea656ea
2 changed files with 24 additions and 9 deletions

View File

@ -87,6 +87,11 @@ public interface DaoAttachment {
" WHERE id = :id")
void setError(long id, String error);
@Query("UPDATE attachment" +
" SET disposition = :disposition" +
" WHERE id = :id")
void setDisposition(long id, String disposition);
@Query("UPDATE attachment" +
" SET cid = :cid" +
" WHERE id = :id")

View File

@ -4098,20 +4098,30 @@ public class FragmentCompose extends FragmentBase {
}
} else if (action == R.id.action_send) {
// Remove unused inline images
List<String> cids = new ArrayList<>();
if (draft.plain_only == null || !draft.plain_only)
for (Element element : JsoupEx.parse(body).select("img")) {
if (draft.plain_only == null || !draft.plain_only) {
// Remove unused inline images
List<String> cids = new ArrayList<>();
Document d = JsoupEx.parse(body);
for (Element element : d.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);
}
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);
}
} else {
// Convert inline images to attachments
for (EntityAttachment attachment : new ArrayList<>(attachments))
if (attachment.isInline()) {
Log.i("Converting to attachment cid=" + attachment.cid);
attachment.disposition = Part.ATTACHMENT;
db.attachment().setDisposition(attachment.id, attachment.disposition);
}
}
// Delete draft (cannot move to outbox)
EntityOperation.queue(context, draft, EntityOperation.DELETE);