diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 03375862f..addabc156 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1217,17 +1217,21 @@ async fn decide_chat_assignment( // // The chat may not exist yet, i.e. there may be // no database row and ChatId yet. - let mut num_recipients = mime_parser.recipients.len(); - if from_id != ContactId::SELF { - let mut has_self_addr = false; - for recipient in &mime_parser.recipients { - if context.is_self_addr(&recipient.addr).await? { - has_self_addr = true; - } + let mut num_recipients = 0; + let mut has_self_addr = false; + for recipient in &mime_parser.recipients { + if addr_cmp(&recipient.addr, &mime_parser.from.addr) { + continue; } - if !has_self_addr { - num_recipients += 1; + + if context.is_self_addr(&recipient.addr).await? { + has_self_addr = true; } + + num_recipients += 1; + } + if from_id != ContactId::SELF && !has_self_addr { + num_recipients += 1; } let chat_assignment = if should_trash { diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 7f777742a..3feb8183f 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5500,6 +5500,38 @@ async fn test_small_unencrypted_group() -> Result<()> { Ok(()) } +/// Tests that if the sender includes self +/// in the `To` field, we do not count +/// it as a third recipient in addition to ourselves +/// and the sender and do not create a group chat. +/// +/// This is a regression test. +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_bcc_not_a_group() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + + let received = receive_imf( + alice, + b"From: \"\"\n\ + To: \n\ + Subject: Hello, this is not a group\n\ + Message-ID: \n\ + Chat-Version: 1.0\n\ + Date: Sun, 22 Mar 2020 22:37:57 +0000\n\ + \n\ + hello\n", + false, + ) + .await? + .unwrap(); + + let received_chat = Chat::load_from_db(alice, received.chat_id).await?; + assert_eq!(received_chat.typ, Chattype::Single); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_lookup_key_contact_by_address_self() -> Result<()> { let mut tcm = TestContextManager::new();