From 37462b38012d98c2fb90b04499c903bb33fc1d50 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 16 Apr 2025 00:32:35 +0000 Subject: [PATCH 1/4] api!: deprecate DC_SHOW_EMAILS_ACCEPTED_CONTACTS --- deltachat-ffi/deltachat.h | 8 ++++---- .../src/deltachat_rpc_client/const.py | 1 - src/constants.rs | 13 +++++++------ src/html.rs | 2 +- src/imap.rs | 8 ++------ src/receive_imf.rs | 3 +-- src/receive_imf/receive_imf_tests.rs | 7 ++----- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index adbf816683..b45e3ec5e9 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -436,10 +436,10 @@ char* dc_get_blobdir (const dc_context_t* context); * 0=watch all folders normally (default) * - `show_emails` = DC_SHOW_EMAILS_OFF (0)= * show direct replies to chats only, - * DC_SHOW_EMAILS_ACCEPTED_CONTACTS (1)= - * also show all mails of confirmed contacts, + * DC_SHOW_EMAILS_ALL1 (1)= + * deprecated, same as DC_SHOW_EMAILS_ALL, * DC_SHOW_EMAILS_ALL (2)= - * also show mails of unconfirmed contacts (default). + * show all mails (default). * - `delete_device_after` = 0=do not delete messages from device automatically (default), * >=1=seconds, after which messages are deleted automatically from the device. * Messages in the "saved messages" chat (see dc_chat_is_self_talk()) are skipped. @@ -6582,7 +6582,7 @@ void dc_event_unref(dc_event_t* event); * Values for dc_get|set_config("show_emails") */ #define DC_SHOW_EMAILS_OFF 0 -#define DC_SHOW_EMAILS_ACCEPTED_CONTACTS 1 +#define DC_SHOW_EMAILS_ALL1 1 #define DC_SHOW_EMAILS_ALL 2 diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/const.py b/deltachat-rpc-client/src/deltachat_rpc_client/const.py index 2ca3c9f2c0..cd4974bb4e 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/const.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/const.py @@ -234,7 +234,6 @@ class ShowEmails(IntEnum): """Show emails mode.""" OFF = 0 - ACCEPTED_CONTACTS = 1 ALL = 2 diff --git a/src/constants.rs b/src/constants.rs index d4a1e326f3..a8973a4de6 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -45,8 +45,12 @@ pub enum Blocked { #[repr(u8)] pub enum ShowEmails { Off = 0, - AcceptedContacts = 1, - #[default] // also change Config.ShowEmails props(default) on changes + + /// Deprecated 2025-04-16, same as All. + All1 = 1, + + // also change Config.ShowEmails props(default) on changes + #[default] All = 2, } @@ -253,10 +257,7 @@ mod tests { // values may be written to disk and must not change assert_eq!(ShowEmails::All, ShowEmails::default()); assert_eq!(ShowEmails::Off, ShowEmails::from_i32(0).unwrap()); - assert_eq!( - ShowEmails::AcceptedContacts, - ShowEmails::from_i32(1).unwrap() - ); + assert_eq!(ShowEmails::All1, ShowEmails::from_i32(1).unwrap()); assert_eq!(ShowEmails::All, ShowEmails::from_i32(2).unwrap()); } diff --git a/src/html.rs b/src/html.rs index 5ba94ee6cc..4b4891e45d 100644 --- a/src/html.rs +++ b/src/html.rs @@ -522,7 +522,7 @@ test some special html-characters as < > and & but also " and &#x async fn test_html_forwarding_encrypted() { let mut tcm = TestContextManager::new(); // Alice receives a non-delta html-message - // (`ShowEmails=AcceptedContacts` lets Alice actually receive non-delta messages for known + // (`ShowEmails=All` lets Alice actually receive non-delta messages for known // contacts, the contact is marked as known by creating a chat using `chat_with_contact()`) let alice = &tcm.alice().await; alice diff --git a/src/imap.rs b/src/imap.rs index 40d6a982ed..1462f5c6b9 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -2243,7 +2243,7 @@ pub(crate) async fn prefetch_should_download( Some(f) => f, None => return Ok(false), }; - let (_from_id, blocked_contact, origin) = + let (_from_id, blocked_contact, _origin) = match from_field_to_contact_id(context, &from, true).await? { Some(res) => res, None => return Ok(false), @@ -2257,7 +2257,6 @@ pub(crate) async fn prefetch_should_download( } let is_chat_message = headers.get_header_value(HeaderDef::ChatVersion).is_some(); - let accepted_contact = origin.is_known(); let is_reply_to_chat_message = get_prefetch_parent_message(context, headers) .await? .map(|parent| match parent.is_dc_message { @@ -2272,10 +2271,7 @@ pub(crate) async fn prefetch_should_download( let show = is_autocrypt_setup_message || match show_emails { ShowEmails::Off => is_chat_message || is_reply_to_chat_message, - ShowEmails::AcceptedContacts => { - is_chat_message || is_reply_to_chat_message || accepted_contact - } - ShowEmails::All => true, + ShowEmails::All | ShowEmails::All1 => true, }; let should_download = (show && !blocked_contact) || maybe_ndn; diff --git a/src/receive_imf.rs b/src/receive_imf.rs index d5642db1e5..dfffb66e01 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -775,8 +775,7 @@ async fn add_parts( chat_id = Some(DC_CHAT_ID_TRASH); allow_creation = false; } - ShowEmails::AcceptedContacts => allow_creation = false, - ShowEmails::All => allow_creation = !is_mdn, + ShowEmails::All | ShowEmails::All1 => allow_creation = !is_mdn, } } else { allow_creation = !is_mdn && !is_reaction; diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index c9093eb856..43a638b68a 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -113,11 +113,8 @@ async fn test_adhoc_group_outgoing_show_accepted_contact_unaccepted() -> Result< let mut tcm = TestContextManager::new(); let alice = &tcm.alice().await; let bob = &tcm.bob().await; - bob.set_config( - Config::ShowEmails, - Some(&ShowEmails::AcceptedContacts.to_string()), - ) - .await?; + bob.set_config(Config::ShowEmails, Some(&ShowEmails::All.to_string())) + .await?; tcm.send_recv(alice, bob, "hi").await; receive_imf( bob, From 0754638417004fe126e4685d66c15dd13fa59ba3 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 16 Apr 2025 01:15:38 +0000 Subject: [PATCH 2/4] fix: create past group members with Origin::Hidden --- src/receive_imf.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index dfffb66e01..efbe30d730 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -346,18 +346,9 @@ pub(crate) async fn receive_imf_inner( }, ) .await?; - let past_ids = add_or_lookup_contacts_by_address_list( - context, - &mime_parser.past_members, - if !mime_parser.incoming { - Origin::OutgoingTo - } else if incoming_origin.is_known() { - Origin::IncomingTo - } else { - Origin::IncomingUnknownTo - }, - ) - .await?; + let past_ids = + add_or_lookup_contacts_by_address_list(context, &mime_parser.past_members, Origin::Hidden) + .await?; update_verified_keys(context, &mut mime_parser, from_id).await?; From 32b6a14c71f90557f12232ccc89f226c146ee4ee Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 16 Apr 2025 00:32:35 +0000 Subject: [PATCH 3/4] feat: create all contacts from the To field with IncomingUnknownTo origin Contacts are created with IncomingUnknownTo origin instead of IncomingTo now even if the message is from a known contact. Removed IncomingTo, IncomingCc, OutgoingBcc, OutgoingCc, IncomingUnknownCc origins. --- src/contact.rs | 16 +------------ src/imap.rs | 36 +++++++++++++--------------- src/receive_imf.rs | 19 +++++++-------- src/receive_imf/receive_imf_tests.rs | 8 +++---- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/src/contact.rs b/src/contact.rs index 08174f9e00..679ac6a4a1 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -501,14 +501,12 @@ pub enum Origin { MailinglistAddress = 0x2, /// Hidden on purpose, e.g. addresses with the word "noreply" in it + /// or past members of the groups. Hidden = 0x8, /// From: of incoming messages of unknown sender IncomingUnknownFrom = 0x10, - /// Cc: of incoming messages of unknown sender - IncomingUnknownCc = 0x20, - /// To: of incoming messages of unknown sender IncomingUnknownTo = 0x40, @@ -522,21 +520,9 @@ pub enum Origin { /// Contacts with at least this origin value are shown in the contact list. IncomingReplyTo = 0x100, - /// Cc: of incoming message of known sender - IncomingCc = 0x200, - - /// additional To:'s of incoming message of known sender - IncomingTo = 0x400, - /// a chat was manually created for this user, but no message yet sent CreateChat = 0x800, - /// message sent by us - OutgoingBcc = 0x1000, - - /// message sent by us - OutgoingCc = 0x2000, - /// message sent by us OutgoingTo = 0x4000, diff --git a/src/imap.rs b/src/imap.rs index 1462f5c6b9..fc06a1e82c 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -1885,20 +1885,19 @@ async fn should_move_out_of_spam( None => return Ok(false), }; // No chat found. - let (from_id, blocked_contact, _origin) = - match from_field_to_contact_id(context, &from, true) - .await - .context("from_field_to_contact_id")? - { - Some(res) => res, - None => { - warn!( - context, - "Contact with From address {:?} cannot exist, not moving out of spam", from - ); - return Ok(false); - } - }; + let (from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true) + .await + .context("from_field_to_contact_id")? + { + Some(res) => res, + None => { + warn!( + context, + "Contact with From address {:?} cannot exist, not moving out of spam", from + ); + return Ok(false); + } + }; if blocked_contact { // Contact is blocked, leave the message in spam. return Ok(false); @@ -2243,11 +2242,10 @@ pub(crate) async fn prefetch_should_download( Some(f) => f, None => return Ok(false), }; - let (_from_id, blocked_contact, _origin) = - match from_field_to_contact_id(context, &from, true).await? { - Some(res) => res, - None => return Ok(false), - }; + let (_from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true).await? { + Some(res) => res, + None => return Ok(false), + }; // prevent_rename=true as this might be a mailing list message and in this case it would be bad if we rename the contact. // (prevent_rename is the last argument of from_field_to_contact_id()) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index efbe30d730..3a0d010957 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -322,7 +322,7 @@ pub(crate) async fn receive_imf_inner( // For example, GitHub sends messages from `notifications@github.com`, // but uses display name of the user whose action generated the notification // as the display name. - let (from_id, _from_id_blocked, incoming_origin) = + let (from_id, _from_id_blocked) = match from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await? { Some(contact_id_res) => contact_id_res, None => { @@ -337,12 +337,10 @@ pub(crate) async fn receive_imf_inner( let to_ids = add_or_lookup_contacts_by_address_list( context, &mime_parser.recipients, - if !mime_parser.incoming { - Origin::OutgoingTo - } else if incoming_origin.is_known() { - Origin::IncomingTo - } else { + if mime_parser.incoming { Origin::IncomingUnknownTo + } else { + Origin::OutgoingTo }, ) .await?; @@ -646,7 +644,7 @@ pub(crate) async fn receive_imf_inner( /// Converts "From" field to contact id. /// -/// Also returns whether it is blocked or not and its origin. +/// Also returns whether it is blocked or not. /// /// * `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for /// mailing lists: In some mailing lists, many users write from the same address but with different @@ -658,7 +656,7 @@ pub async fn from_field_to_contact_id( context: &Context, from: &SingleInfo, prevent_rename: bool, -) -> Result> { +) -> Result> { let display_name = if prevent_rename { Some("") } else { @@ -684,12 +682,11 @@ pub async fn from_field_to_contact_id( .await?; if from_id == ContactId::SELF { - Ok(Some((ContactId::SELF, false, Origin::OutgoingBcc))) + Ok(Some((ContactId::SELF, false))) } else { let contact = Contact::get_by_id(context, from_id).await?; let from_id_blocked = contact.blocked; - let incoming_origin = contact.origin; - Ok(Some((from_id, from_id_blocked, incoming_origin))) + Ok(Some((from_id, from_id_blocked))) } } diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 43a638b68a..766a3341c4 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -137,7 +137,7 @@ async fn test_adhoc_group_outgoing_show_accepted_contact_unaccepted() -> Result< #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_adhoc_group_show_accepted_contact_known() { let t = TestContext::new_alice().await; - t.set_config(Config::ShowEmails, Some("1")).await.unwrap(); + t.set_config(Config::ShowEmails, Some("2")).await.unwrap(); Contact::create(&t, "Bob", "bob@example.com").await.unwrap(); receive_imf(&t, GRP_MAIL, false).await.unwrap(); @@ -150,7 +150,7 @@ async fn test_adhoc_group_show_accepted_contact_known() { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_adhoc_group_show_accepted_contact_accepted() { let t = TestContext::new_alice().await; - t.set_config(Config::ShowEmails, Some("1")).await.unwrap(); + t.set_config(Config::ShowEmails, Some("2")).await.unwrap(); // accept Bob by accepting a delta-message from Bob receive_imf(&t, MSGRMSG, false).await.unwrap(); @@ -2319,7 +2319,7 @@ async fn test_ignore_footer_status_from_mailinglist() -> Result<()> { &t, "", &ContactAddress::new("bob@example.net").unwrap(), - Origin::IncomingUnknownCc, + Origin::IncomingUnknownTo, ) .await? .0; @@ -3985,7 +3985,7 @@ async fn test_mua_user_adds_recipient_to_single_chat() -> Result<()> { chat::get_chat_contacts(&alice, group_chat.id).await?.len(), 4 ); - let fiona = Contact::lookup_id_by_addr(&alice, "fiona@example.net", Origin::IncomingTo) + let fiona = Contact::lookup_id_by_addr(&alice, "fiona@example.net", Origin::IncomingUnknownTo) .await? .unwrap(); assert!(chat::is_contact_in_chat(&alice, group_chat.id, fiona).await?); From bce13b3bfdbff0b2df25450c20c73fdfb9e27cdd Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 17 May 2025 18:26:36 +0000 Subject: [PATCH 4/4] remove allow_creation override --- src/receive_imf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 3a0d010957..1abc9df291 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -867,7 +867,7 @@ async fn add_parts( &parent, to_ids, from_id, - allow_creation || test_normal_chat.is_some(), + allow_creation, create_blocked, is_partial_download.is_some(), )