From 3145768feda072c4fa22c7a986d732a1bc42fffc Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 14 Feb 2023 01:51:46 +0000 Subject: [PATCH] Use the message text as the initial subject --- CHANGELOG.md | 1 + spec.md | 3 --- src/mimefactory.rs | 12 ++++-------- src/stock_str.rs | 8 -------- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a141a535..1012e0d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Changes +- Use message text as the initial subject for 1:1 contacts. #4036 ### Fixes diff --git a/spec.md b/spec.md index 2a9e675be..02a1b9af0 100644 --- a/spec.md +++ b/spec.md @@ -38,9 +38,6 @@ by the [Protected Headers](https://tools.ietf.org/id/draft-autocrypt-lamps-prote # Outgoing messages Messengers MUST add a `Chat-Version: 1.0` header to outgoing messages. -For filtering and smart appearance of the messages in normal MUAs, -the `Subject` header SHOULD be `Message from `. -Replies to messages MAY follow the typical `Re:`-format. The body MAY contain text which MUST have the content type `text/plain` or `mulipart/alternative` containing `text/plain`. diff --git a/src/mimefactory.rs b/src/mimefactory.rs index e67b0aace..4f91025db 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -28,7 +28,7 @@ use crate::stock_str; use crate::tools::IsNoneOrEmpty; use crate::tools::{ create_outgoing_rfc724_mid, create_smeared_timestamp, get_filebytes, remove_subject_prefix, - time, + time, truncate, }; // attachments of 25 mb brutto should work on the majority of providers @@ -435,11 +435,7 @@ impl<'a> MimeFactory<'a> { } } - let self_name = &match context.get_config(Config::Displayname).await? { - Some(name) => name, - None => context.get_config(Config::Addr).await?.unwrap_or_default(), - }; - stock_str::subject_for_new_contact(context, self_name).await + truncate(self.msg.text.as_deref().unwrap_or_default().trim(), 40).to_string() } Loaded::Mdn { .. } => stock_str::read_rcpt(context).await, }; @@ -1669,13 +1665,13 @@ mod tests { // 3. Send the first message to a new contact let t = TestContext::new_alice().await; - assert_eq!(first_subject_str(t).await, "Message from alice@example.org"); + assert_eq!(first_subject_str(t).await, "Hi"); let t = TestContext::new_alice().await; t.set_config(Config::Displayname, Some("Alice")) .await .unwrap(); - assert_eq!(first_subject_str(t).await, "Message from Alice"); + assert_eq!(first_subject_str(t).await, "Hi"); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/src/stock_str.rs b/src/stock_str.rs index f91b5a783..244416677 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -868,14 +868,6 @@ pub(crate) async fn unknown_sender_for_chat(context: &Context) -> String { translated(context, StockMessage::UnknownSenderForChat).await } -/// Stock string: `Message from %1$s`. -// TODO: This can compute `self_name` itself instead of asking the caller to do this. -pub(crate) async fn subject_for_new_contact(context: &Context, self_name: &str) -> String { - translated(context, StockMessage::SubjectForNewContact) - .await - .replace1(self_name) -} - /// Stock string: `Failed to send message to %1$s.`. pub(crate) async fn failed_sending_to(context: &Context, name: &str) -> String { translated(context, StockMessage::FailedSendingTo)