From 017d201f88692fbba6761be2e6f364e9982935aa Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 29 Aug 2021 22:02:15 +0200 Subject: [PATCH] Selectively keep encryption parts --- .../java/eu/faircode/email/DaoAttachment.java | 4 ++-- .../java/eu/faircode/email/FragmentMessages.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoAttachment.java b/app/src/main/java/eu/faircode/email/DaoAttachment.java index d13c79421a..ef9d9b7d5e 100644 --- a/app/src/main/java/eu/faircode/email/DaoAttachment.java +++ b/app/src/main/java/eu/faircode/email/DaoAttachment.java @@ -140,6 +140,6 @@ public interface DaoAttachment { @Query("DELETE FROM attachment" + " WHERE message = :message" + - " AND encryption IS NULL") - int deleteAttachments(long message); + " AND (encryption IS NULL OR encryption NOT IN (:keep))") + int deleteAttachments(long message, int[] keep); } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 2facf235ba..eb872ef887 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -5959,7 +5959,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Helper.writeText(file, null); db.message().setMessageContent(message.id, true, null, null, null, null); //db.message().setMessageSubject(id, subject); - db.attachment().deleteAttachments(message.id); + db.attachment().deleteAttachments(message.id, new int[]{ + EntityAttachment.PGP_MESSAGE, + EntityAttachment.SMIME_MESSAGE, + EntityAttachment.SMIME_SIGNED_DATA + }); db.message().setMessageEncrypt(message.id, message.ui_encrypt); db.message().setMessageStored(message.id, new Date().getTime()); @@ -6825,14 +6829,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. message.warning); // Remove existing attachments - db.attachment().deleteAttachments(message.id); + db.attachment().deleteAttachments(message.id, new int[]{EntityAttachment.PGP_MESSAGE}); // Add decrypted attachments List remotes = parts.getAttachments(); for (int index = 0; index < remotes.size(); index++) { EntityAttachment remote = remotes.get(index); - if (remote.encryption != null) - continue; remote.message = message.id; remote.sequence = index + 1; remote.id = db.attachment().insertAttachment(remote); @@ -7486,7 +7488,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. message.warning); // Remove existing attachments - db.attachment().deleteAttachments(message.id); + db.attachment().deleteAttachments(message.id, new int[]{ + EntityAttachment.SMIME_MESSAGE, + EntityAttachment.SMIME_SIGNED_DATA + }); // Add decrypted attachments List remotes = parts.getAttachments();