mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
refactor: remove chattype argument from has_verified_encryption()
This commit is contained in:
@@ -788,18 +788,12 @@ async fn add_parts(
|
|||||||
false => None,
|
false => None,
|
||||||
};
|
};
|
||||||
if let Some(chat) = chat {
|
if let Some(chat) = chat {
|
||||||
let mut new_protection = match has_verified_encryption(
|
let mut new_protection =
|
||||||
context,
|
match has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
||||||
mime_parser,
|
{
|
||||||
from_id,
|
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
||||||
to_ids,
|
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
||||||
Chattype::Single,
|
};
|
||||||
)
|
|
||||||
.await?
|
|
||||||
{
|
|
||||||
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
|
||||||
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
|
||||||
};
|
|
||||||
|
|
||||||
if chat.protected != ProtectionStatus::Unprotected
|
if chat.protected != ProtectionStatus::Unprotected
|
||||||
&& new_protection == ProtectionStatus::Unprotected
|
&& new_protection == ProtectionStatus::Unprotected
|
||||||
@@ -1092,7 +1086,7 @@ async fn add_parts(
|
|||||||
|
|
||||||
if chat.is_protected() {
|
if chat.is_protected() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) =
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids, chat.typ).await?
|
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
||||||
{
|
{
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
@@ -1657,7 +1651,7 @@ async fn create_or_lookup_group(
|
|||||||
|
|
||||||
let create_protected = if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
let create_protected = if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) =
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids, Chattype::Group).await?
|
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
||||||
{
|
{
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
@@ -1820,7 +1814,7 @@ async fn apply_group_changes(
|
|||||||
|
|
||||||
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) =
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids, chat.typ).await?
|
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
||||||
{
|
{
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
@@ -2385,12 +2379,19 @@ async fn has_verified_encryption(
|
|||||||
mimeparser: &MimeMessage,
|
mimeparser: &MimeMessage,
|
||||||
from_id: ContactId,
|
from_id: ContactId,
|
||||||
to_ids: &[ContactId],
|
to_ids: &[ContactId],
|
||||||
chat_type: Chattype,
|
|
||||||
) -> Result<VerifiedEncryption> {
|
) -> Result<VerifiedEncryption> {
|
||||||
use VerifiedEncryption::*;
|
use VerifiedEncryption::*;
|
||||||
|
|
||||||
if from_id == ContactId::SELF && chat_type == Chattype::Single {
|
// We do not need to check if we are verified with ourself.
|
||||||
// For outgoing emails in the 1:1 chat, we have an exception that
|
let to_ids = to_ids
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|id| *id != ContactId::SELF)
|
||||||
|
.collect::<Vec<ContactId>>();
|
||||||
|
|
||||||
|
if from_id == ContactId::SELF && to_ids.len() <= 1 {
|
||||||
|
// For outgoing emails in the 1:1 chat and groups with 2 members,
|
||||||
|
// we have an exception that
|
||||||
// they are allowed to be unencrypted:
|
// they are allowed to be unencrypted:
|
||||||
// 1. They can't be an attack (they are outgoing, not incoming)
|
// 1. They can't be an attack (they are outgoing, not incoming)
|
||||||
// 2. Probably the unencryptedness is just a temporary state, after all
|
// 2. Probably the unencryptedness is just a temporary state, after all
|
||||||
@@ -2429,13 +2430,6 @@ async fn has_verified_encryption(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we do not need to check if we are verified with ourself
|
|
||||||
let to_ids = to_ids
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.filter(|id| *id != ContactId::SELF)
|
|
||||||
.collect::<Vec<ContactId>>();
|
|
||||||
|
|
||||||
if to_ids.is_empty() {
|
if to_ids.is_empty() {
|
||||||
return Ok(Verified);
|
return Ok(Verified);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user