securemail: sent copies record whether they were actually encrypted
- Commit
1e62496b518036bbb7093a73cdcdaa72e3c6136a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-02 04:09 UTC (1 month ago)
- Parents
90aa2c8
Every message in Sent showed as encrypted, including ones that went out in plaintext. send() splits recipients into encryptedTo (key found) and plainTo (no key -> sent unencrypted), but storeSent() hard-coded unencrypted = false on the Sent-folder copy, so the list never showed the warning icon and the reader said "Encrypted". - storeSent() now takes the real state: the copy is flagged unencrypted when any recipient was in plainTo (one copy per send, so a mixed send is marked unencrypted - the conservative reading). - The reader's trust line uses sent-specific wording: "Sent encrypted", or "Sent unencrypted - no key for a recipient". Previously sent mail fell through to the received-mail branch and read "Encrypted - signature not verified", which is meaningless for your own message. Messages already in Sent keep their old (always-encrypted) flag; the send-time decision was never stored, so they can't be corrected. Verified: :securemail:compileDevKotlin, unit tests, lint clean, detekt unchanged at 40.
Diff
securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.ktindex 2535d47d0c..ae473aafbf 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt@@ -562,7 +562,8 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { } } // Sent-folder copy: plaintext (it is our own composition).- storeSent(allTo, subject, body)+ // Any keyless recipient got plaintext, so the copy is flagged unencrypted.+ storeSent(allTo, subject, body, unencrypted = plainTo.isNotEmpty()) if (queued > 0) "Queued $queued message(s) — retry from Outbox when online." else "Sent." } }@@ -584,7 +585,7 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { * Records our own composition in the Sent folder (plaintext — it is ours). * Runs inside send()'s IO context; failures are swallowed (send succeeded). */- private suspend fun storeSent(to: List<String>, subject: String, body: String) {+ private suspend fun storeSent(to: List<String>, subject: String, body: String, unencrypted: Boolean) { runCatching { repo.messageDao().upsert( StoredMessage(@@ -596,7 +597,7 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { blobBase64 = "", decryptedBody = body, decryptedSubject = subject.ifBlank { "(no subject)" },- unencrypted = false,+ unencrypted = unencrypted, folder = MailFolder.SENT, ), )
securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.ktindex cfe876adaa..7bcd598fcd 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt@@ -165,7 +165,10 @@ private fun MessageBody(msg: StoredMessage, ownAddress: String, onReply: () -> U @Composable private fun TrustLine(msg: StoredMessage) { val colors = MaterialTheme.colorScheme+ val sent = msg.folder == MailFolder.SENT val (label, color) = when {+ sent && msg.unencrypted -> "Sent unencrypted \u00b7 no key for a recipient" to colors.error+ sent -> "Sent encrypted" to colors.primary msg.unencrypted -> "Not encrypted" to colors.error msg.verifiedSigner != null -> "Encrypted \u00b7 signature verified" to colors.primary msg.decryptedBody != null -> "Encrypted \u00b7 signature not verified" to colors.onSurfaceVariant