fix: recognize self addresses in various places (instead of just the "primary")

This commit is contained in:
holger krekel
2026-08-02 17:43:15 +02:00
parent 2ac217ddd4
commit ba35814d34
6 changed files with 44 additions and 25 deletions

View File

@@ -10,7 +10,9 @@ use std::time::Duration;
use anyhow::{Context as _, Result, anyhow, bail, ensure};
use chrono::TimeZone;
use deltachat_contact_tools::{ContactAddress, sanitize_bidi_characters, sanitize_single_line};
use deltachat_contact_tools::{
ContactAddress, addr_cmp, sanitize_bidi_characters, sanitize_single_line,
};
use humansize::{BINARY, format_size};
use mail_builder::mime::MimePart;
use serde::{Deserialize, Serialize};
@@ -2851,10 +2853,8 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
let attach_selfavatar = mimefactory.attach_selfavatar;
let mut recipients = mimefactory.recipients();
let from = context.get_primary_self_addr().await?;
let lowercase_from = from.to_lowercase();
recipients.retain(|x| x.to_lowercase() != lowercase_from);
let self_addrs = context.get_all_self_addrs().await?;
recipients.retain(|x| !self_addrs.iter().any(|a| addr_cmp(a, x)));
// Default Webxdc integrations are hidden messages and must not be sent out:
if (msg.param.get_int(Param::WebxdcIntegration).is_some() && msg.hidden)

View File

@@ -1230,17 +1230,13 @@ ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC
.await?;
if let Some(query) = query {
let self_addr = context
.get_config(Config::ConfiguredAddr)
.await?
.unwrap_or_default();
let self_name = context
.get_config(Config::Displayname)
.await?
.unwrap_or_default();
let self_name2 = stock_str::self_msg(context);
if self_addr.contains(query)
if self_addrs.iter().any(|a| a.contains(query))
|| self_name.contains(query)
|| self_name2.contains(query)
{

View File

@@ -152,6 +152,20 @@ async fn test_get_contacts() -> Result<()> {
assert_eq!(contacts.len(), 1);
let contacts = Contact::get_all(&context, 0, Some("δ")).await?;
assert_eq!(contacts.len(), 1);
// Searching for a secondary self address finds "Me",
// even if the transport is unpublished.
crate::transport::add_pseudo_transport(&context, "bob@second.example").await?;
context
.set_transport_unpublished("bob@second.example", true)
.await?;
let contacts = Contact::get_all(
&context,
constants::DC_GCL_ADD_SELF,
Some("bob@second.example"),
)
.await?;
assert_eq!(contacts, vec![ContactId::SELF]);
Ok(())
}

View File

@@ -1421,12 +1421,7 @@ impl MimeFactory {
let email_to_remove = msg.param.get(Param::Arg).unwrap_or_default();
let fingerprint_to_remove = msg.param.get(Param::Arg4).unwrap_or_default();
if email_to_remove
== context
.get_config(Config::ConfiguredAddr)
.await?
.unwrap_or_default()
{
if context.is_self_addr(email_to_remove).await? {
placeholdertext = Some(format!("{email_to_remove} left the group."));
} else {
placeholdertext = Some(format!("Member {email_to_remove} was removed."));

View File

@@ -747,6 +747,22 @@ async fn test_remove_member_bcc() -> Result<()> {
}
}
// A member whose address became a secondary self address is treated
// as ourselves on removal and rendered as "left the group".
let secondary_self_addr = "alice@second.example";
let secondary_self_id = crate::contact::Contact::create(alice, "", secondary_self_addr).await?;
add_contact_to_chat(alice, alice_chat_id, secondary_self_id).await?;
alice.pop_sent_msg().await;
crate::transport::add_pseudo_transport(alice, secondary_self_addr).await?;
remove_contact_from_chat(alice, alice_chat_id, secondary_self_id).await?;
let remove = alice.pop_sent_msg().await;
assert!(
remove
.payload()
.contains("alice@second.example left the group.")
);
assert!(!remove.payload().contains("was removed"));
Ok(())
}

View File

@@ -3177,15 +3177,13 @@ async fn apply_group_changes(
.await?;
} else {
let mut new_members: BTreeSet<ContactId>;
// True if a Delta Chat client has explicitly and really added our primary address to an
// already existing group.
let self_added =
if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) {
addr_cmp(&context.get_primary_self_addr().await?, added_addr)
&& !chat_contacts.contains(&ContactId::SELF)
} else {
false
};
let self_added = if let Some(added_addr) =
mime_parser.get_header(HeaderDef::ChatGroupMemberAdded)
{
context.is_self_addr(added_addr).await? && !chat_contacts.contains(&ContactId::SELF)
} else {
false
};
if self_added {
new_members = BTreeSet::from_iter(to_ids_flat.iter().copied());
new_members.insert(ContactId::SELF);