diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 02f494a492..7139c3080b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -4399,11 +4399,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. DB db = DB.getInstance(context); - if (EntityMessage.SMIME_SIGNONLY.equals(type)) { - EntityMessage message = db.message().getMessage(id); - if (message == null) - return null; + EntityMessage message = db.message().getMessage(id); + if (message == null) + return null; + if (EntityMessage.SMIME_SIGNONLY.equals(type)) { // Get content/signature File content = null; File signature = null; @@ -4481,7 +4481,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. // Get encrypted message File input = null; - List attachments = db.attachment().getAttachments(id); + List attachments = db.attachment().getAttachments(message.id); for (EntityAttachment attachment : attachments) if (EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption)) { if (!attachment.available) @@ -4539,16 +4539,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. // Write decrypted body String html = parts.getHtml(context); - Helper.writeText(EntityMessage.getFile(context, id), html); + Helper.writeText(message.getFile(context), html); // Remove existing attachments - db.attachment().deleteAttachments(id); + db.attachment().deleteAttachments(message.id); // Add decrypted attachments List remotes = parts.getAttachments(); for (int index = 0; index < remotes.size(); index++) { EntityAttachment remote = remotes.get(index); - remote.message = id; + remote.message = message.id; remote.sequence = index + 1; remote.id = db.attachment().insertAttachment(remote); try { @@ -4558,8 +4558,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } } - db.message().setMessageEncrypt(id, parts.getEncryption()); - db.message().setMessageStored(id, new Date().getTime()); + db.message().setMessageEncrypt(message.id, parts.getEncryption()); + db.message().setMessageStored(message.id, new Date().getTime()); + + if (message.identity != null) + db.identity().setIdentitySignKeyAlias(message.identity, alias); db.setTransactionSuccessful(); } finally {