diff --git a/CHANGELOG.md b/CHANGELOG.md index e5afb9b74..b9a3bf0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - switch from `async-std` to `tokio` as the async runtime #3449 ### Fixes +- mailing list: remove square-brackets only for first name #3452 ## 1.87.0 diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 15a85ed27..5eee54658 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1739,13 +1739,14 @@ async fn create_or_lookup_mailinglist( } } - // if we have an additional name square brackets in the subject, we prefer that + // additional names in square brackets in the subject are preferred // (as that part is much more visible, we assume, that names is shorter and comes more to the point, // than the sometimes longer part from ListId) let subject = mime_parser.get_subject().unwrap_or_default(); - static SUBJECT: Lazy = Lazy::new(|| Regex::new(r"^.{0,5}\[(.*.)\]").unwrap()); + static SUBJECT: Lazy = + Lazy::new(|| Regex::new(r"^.{0,5}\[(.+?)\](\s*\[.+\])?").unwrap()); // remove square brackets around first name if let Some(cap) = SUBJECT.captures(&subject) { - name = cap[1].to_string(); + name = cap[1].to_string() + cap.get(2).map_or("", |m| m.as_str()); } // if we do not have a name yet and `From` indicates, that this is a notification list, @@ -3165,6 +3166,31 @@ Hello mailinglist!\r\n" assert!(chat.can_send(&t.ctx).await.unwrap()); } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_mailing_list_multiple_names_in_subject() -> Result<()> { + let t = TestContext::new_alice().await; + t.set_config(Config::ShowEmails, Some("2")).await?; + dc_receive_imf( + &t, + b"From: Foo Bar \n\ + To: deltachat/deltachat-core-rust \n\ + Subject: [ola list] [foo][bar] just a subject\n\ + Message-ID: <3333@example.org>\n\ + List-ID: \"looong description of 'ola list', with foo, bar\" \n\ + Date: Sun, 22 Mar 2020 22:37:57 +0000\n\ + \n\ + hello\n", + false, + ) + .await + .unwrap(); + let msg = t.get_last_msg().await; + let chat_id = msg.get_chat_id(); + let chat = Chat::load_from_db(&t, chat_id).await?; + assert_eq!(chat.name, "ola list [foo][bar]"); + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_majordomo_mailing_list() { let t = TestContext::new_alice().await;