mirror of
https://github.com/chatmail/core.git
synced 2026-04-22 07:56:29 +03:00
fix: determine whether a message is an own message by looking at signature. multiple devices can temporarly have different sets of self addresses, and still need to properly recognize incoming versus outgoing messages. Disclaimer: some LLM tooling was initially involved but i went over everything by hand, and also addressed review comments.
This commit is contained in:
@@ -373,7 +373,7 @@ impl MimeMessage {
|
||||
hop_info += "\n\n";
|
||||
hop_info += &dkim_results.to_string();
|
||||
|
||||
let incoming = !context.is_self_addr(&from.addr).await?;
|
||||
let from_is_not_self_addr = !context.is_self_addr(&from.addr).await?;
|
||||
|
||||
let mut aheader_values = mail.headers.get_all_values(HeaderDef::Autocrypt.into());
|
||||
|
||||
@@ -438,7 +438,7 @@ impl MimeMessage {
|
||||
};
|
||||
|
||||
let mut autocrypt_header = None;
|
||||
if incoming {
|
||||
if from_is_not_self_addr {
|
||||
// See `get_all_addresses_from_header()` for why we take the last valid header.
|
||||
for val in aheader_values.iter().rev() {
|
||||
autocrypt_header = match Aheader::from_str(val) {
|
||||
@@ -469,7 +469,7 @@ impl MimeMessage {
|
||||
None
|
||||
};
|
||||
|
||||
let mut public_keyring = if incoming {
|
||||
let mut public_keyring = if from_is_not_self_addr {
|
||||
if let Some(autocrypt_header) = autocrypt_header {
|
||||
vec![autocrypt_header.public_key]
|
||||
} else {
|
||||
@@ -654,6 +654,15 @@ impl MimeMessage {
|
||||
.into_iter()
|
||||
.last()
|
||||
.map(|(fp, recipient_fps)| (fp, recipient_fps.into_iter().collect::<HashSet<_>>()));
|
||||
|
||||
let incoming = if let Some((ref sig_fp, _)) = signature {
|
||||
sig_fp.hex() != key::self_fingerprint(context).await?
|
||||
} else {
|
||||
// rare case of getting a cleartext message
|
||||
// so we determine 'incoming' flag by From-address
|
||||
from_is_not_self_addr
|
||||
};
|
||||
|
||||
let mut parser = MimeMessage {
|
||||
parts: Vec::new(),
|
||||
headers,
|
||||
|
||||
Reference in New Issue
Block a user