diff --git a/src/contact.rs b/src/contact.rs index 26271c5b5..4b750803f 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1182,7 +1182,9 @@ VALUES (?, ?, ?, ?, ?, ?) let mut ret = Vec::new(); let flag_add_self = (listflags & constants::DC_GCL_ADD_SELF) != 0; let flag_address = (listflags & constants::DC_GCL_ADDRESS) != 0; - let minimal_origin = if context.get_config_bool(Config::Bot).await? { + let minimal_origin = if context.get_config_bool(Config::Bot).await? + || query.is_some_and(may_be_valid_addr) + { Origin::Unknown } else { Origin::IncomingReplyTo diff --git a/src/contact/contact_tests.rs b/src/contact/contact_tests.rs index ce4be4489..300345438 100644 --- a/src/contact/contact_tests.rs +++ b/src/contact/contact_tests.rs @@ -420,12 +420,16 @@ async fn test_delete() -> Result<()> { Contact::delete(&alice, contact_id).await?; let contact = Contact::get_by_id(&alice, contact_id).await?; assert_eq!(contact.origin, Origin::Hidden); + + // Hidden contacts are found when searching by email address assert_eq!( Contact::get_all(&alice, 0, Some("bob@example.net")) .await? .len(), - 0 + 1 ); + // Hidden contacts are not found by a non-address query + assert_eq!(Contact::get_all(&alice, 0, Some("bob")).await?.len(), 0); // Delete chat. chat.get_id().delete(&alice).await?; @@ -483,7 +487,7 @@ async fn test_delete_and_recreate_contact() -> Result<()> { Contact::get_all(&t, 0, Some("bob@example.net")) .await? .len(), - 0 + 1 ); let contact_id3 = t.add_or_lookup_contact_id(&bob).await; diff --git a/src/sql/migrations/migrations_tests.rs b/src/sql/migrations/migrations_tests.rs index 969b31c80..fe09e21f4 100644 --- a/src/sql/migrations/migrations_tests.rs +++ b/src/sql/migrations/migrations_tests.rs @@ -57,9 +57,9 @@ async fn test_key_contacts_migration_autocrypt() -> Result<()> { ); assert_eq!(pgp_bob.get_verifier_id(&t).await?, None); - // Hidden address-contact can't be looked up. + // Hidden address-contact can't be looked up by name. assert!( - Contact::get_all(&t, constants::DC_GCL_ADDRESS, Some("bob@example.net")) + Contact::get_all(&t, constants::DC_GCL_ADDRESS, Some("bob")) .await? .is_empty() ); @@ -113,12 +113,8 @@ async fn test_key_contacts_migration_email2() -> Result<()> { )?)).await?; t.sql.run_migrations(&t).await?; - // Hidden key-contact can't be looked up. - assert!( - Contact::get_all(&t, 0, Some("bob@example.net")) - .await? - .is_empty() - ); + // Hidden key-contact can't be looked up by name. + assert!(Contact::get_all(&t, 0, Some("bob")).await?.is_empty()); let pgp_bob = Contact::get_by_id(&t, ContactId::new(11001)).await?; assert_eq!(pgp_bob.is_key_contact(), true); assert_eq!(pgp_bob.origin, Origin::Hidden); @@ -156,9 +152,9 @@ async fn test_key_contacts_migration_verified() -> Result<()> { t.sql.run_migrations(&t).await?; - // Hidden address-contact can't be looked up. + // Hidden address-contact can't be looked up by name. assert!( - Contact::get_all(&t, constants::DC_GCL_ADDRESS, Some("bob@example.net")) + Contact::get_all(&t, constants::DC_GCL_ADDRESS, Some("bob")) .await? .is_empty() );