From 519f658c07e4ba7d642bcf70f9edfbaf0d31f211 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 9 Dec 2022 17:20:49 +0000 Subject: [PATCH] Make bots automatically accept mailing list chats --- CHANGELOG.md | 1 + src/receive_imf.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df034b6f3..0a766affb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Add read/write timeouts to IMAP sockets #3820 - Add connection timeout to IMAP sockets #3828 - Disable read timeout during IMAP IDLE #3826 +- Bots automatically accept mailing lists #3831 ## 1.102.0 diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f677ee9d8..42fe507cf 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1858,12 +1858,18 @@ async fn create_or_lookup_mailinglist( p.to_string() }); + let is_bot = context.get_config(Config::Bot).await?.is_some(); + let blocked = if is_bot { + Blocked::Not + } else { + Blocked::Request + }; let chat_id = ChatId::create_multiuser_record( context, Chattype::Mailinglist, &listid, &name, - Blocked::Request, + blocked, ProtectionStatus::Unprotected, param, ) @@ -1876,7 +1882,7 @@ async fn create_or_lookup_mailinglist( })?; chat::add_to_chat_contacts_table(context, chat_id, &[ContactId::SELF]).await?; - Ok(Some((chat_id, Blocked::Request))) + Ok(Some((chat_id, blocked))) } else { info!(context, "creating list forbidden by caller"); Ok(None) @@ -3686,6 +3692,27 @@ Hello mailinglist!\r\n" assert_eq!(chat.name, "Test1"); } + /// Tests that bots automatically accept mailing lists. + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_mailing_list_bot() { + let t = TestContext::new_alice().await; + t.set_config(Config::Bot, Some("1")).await.unwrap(); + + receive_imf( + &t, + include_bytes!("../test-data/message/mailinglist_chat_message.eml"), + false, + ) + .await + .unwrap(); + let msg = t.get_last_msg().await; + let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); + assert_eq!(chat.blocked, Blocked::Not); + + // Bot should see the message as fresh and process it. + assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 1); + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_dont_show_tokens_in_contacts_list() { check_dont_show_in_contacts_list(