mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 23:16:30 +03:00
feat: Auto-restore 1:1 chat protection after receiving old unverified message
I.e. add the "Messages are guaranteed to be end-to-end encrypted from now on." message and mark the chat as protected again because no user action is required in this case. There are a couple of problems though: - If the program crashes earlier than the protection is restored, the chat remains protection-broken. But this problem already exists because `ChatId::set_protection()` is never retried. - If multiple old unverified messages are received, protection messages added in between don't annihilate, so they clutter the chat.
This commit is contained in:
@@ -762,6 +762,7 @@ async fn add_parts(
|
||||
let state: MessageState;
|
||||
let mut hidden = false;
|
||||
let mut needs_delete_job = false;
|
||||
let mut restore_protection = false;
|
||||
|
||||
// if contact renaming is prevented (for mailinglists and bots),
|
||||
// we use name from From:-header as override name
|
||||
@@ -1006,6 +1007,13 @@ async fn add_parts(
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if let Some(peerstate) = &mime_parser.decryption_info.peerstate {
|
||||
restore_protection = new_protection != ProtectionStatus::Protected
|
||||
&& peerstate.prefer_encrypt == EncryptPreference::Mutual
|
||||
// Check that the contact still has the Autocrypt key same as the
|
||||
// verified key, see also `Peerstate::is_using_verified_key()`.
|
||||
&& contact.is_verified(context).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1741,7 +1749,16 @@ RETURNING id
|
||||
// delete it.
|
||||
needs_delete_job = true;
|
||||
}
|
||||
|
||||
if restore_protection {
|
||||
chat_id
|
||||
.set_protection(
|
||||
context,
|
||||
ProtectionStatus::Protected,
|
||||
mime_parser.timestamp_rcvd,
|
||||
Some(from_id),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(ReceivedMsg {
|
||||
chat_id,
|
||||
state,
|
||||
|
||||
Reference in New Issue
Block a user