if incoming Sender:-header ist set, renaming of contacts is prevented as for List-Id:-header

This commit is contained in:
B. Petersen
2021-02-14 16:50:09 +01:00
committed by bjoern
parent 1f59b5cd15
commit b505d2666b
2 changed files with 19 additions and 2 deletions

View File

@@ -125,6 +125,8 @@ pub(crate) async fn dc_receive_imf_inner(
sent_timestamp = mailparse::dateparse(value).unwrap_or_default(); sent_timestamp = mailparse::dateparse(value).unwrap_or_default();
} }
let prevent_rename = list_id_header.is_some() || mime_parser.get(HeaderDef::Sender).is_some();
// get From: (it can be an address list!) and check if it is known (for known From:'s we add // get From: (it can be an address list!) and check if it is known (for known From:'s we add
// the other To:/Cc: in the 3rd pass) // the other To:/Cc: in the 3rd pass)
// or if From: is equal to SELF (in this case, it is any outgoing messages, // or if From: is equal to SELF (in this case, it is any outgoing messages,
@@ -134,7 +136,7 @@ pub(crate) async fn dc_receive_imf_inner(
// If this is a mailing list email (i.e. list_id_header is some), don't change the displayname because in // If this is a mailing list email (i.e. list_id_header is some), don't change the displayname because in
// a mailing list the sender displayname sometimes does not belong to the sender email address. // a mailing list the sender displayname sometimes does not belong to the sender email address.
let (from_id, _from_id_blocked, incoming_origin) = let (from_id, _from_id_blocked, incoming_origin) =
from_field_to_contact_id(context, &mime_parser.from, list_id_header.is_some()).await?; from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await?;
let incoming = from_id != DC_CONTACT_ID_SELF; let incoming = from_id != DC_CONTACT_ID_SELF;
@@ -151,7 +153,7 @@ pub(crate) async fn dc_receive_imf_inner(
} else { } else {
Origin::IncomingUnknownTo Origin::IncomingUnknownTo
}, },
list_id_header.is_some(), prevent_rename,
) )
.await?, .await?,
); );
@@ -193,6 +195,7 @@ pub(crate) async fn dc_receive_imf_inner(
&mut created_db_entries, &mut created_db_entries,
&mut create_event_to_send, &mut create_event_to_send,
fetching_existing_messages, fetching_existing_messages,
prevent_rename,
) )
.await .await
{ {
@@ -376,6 +379,7 @@ async fn add_parts(
created_db_entries: &mut Vec<(ChatId, MsgId)>, created_db_entries: &mut Vec<(ChatId, MsgId)>,
create_event_to_send: &mut Option<CreateEvent>, create_event_to_send: &mut Option<CreateEvent>,
fetching_existing_messages: bool, fetching_existing_messages: bool,
prevent_rename: bool,
) -> Result<()> { ) -> Result<()> {
let mut state: MessageState; let mut state: MessageState;
let mut chat_id_blocked = Blocked::Not; let mut chat_id_blocked = Blocked::Not;
@@ -541,6 +545,18 @@ async fn add_parts(
} }
} }
// if contact renaming is prevented (for mailinglists and bots),
// we use name from From:-header as override name
if prevent_rename {
if let Some(from) = mime_parser.from.first() {
if let Some(name) = &from.display_name {
for part in mime_parser.parts.iter_mut() {
part.param.set(Param::OverrideSenderDisplayname, name);
}
}
}
}
if chat_id.is_unset() { if chat_id.is_unset() {
// try to create a normal chat // try to create a normal chat
let create_blocked = if from_id == to_id { let create_blocked = if from_id == to_id {

View File

@@ -43,6 +43,7 @@ pub enum HeaderDef {
SecureJoinFingerprint, SecureJoinFingerprint,
SecureJoinInvitenumber, SecureJoinInvitenumber,
SecureJoinAuth, SecureJoinAuth,
Sender,
EphemeralTimer, EphemeralTimer,
Received, Received,
_TestHeader, _TestHeader,