diff --git a/CHANGELOG.md b/CHANGELOG.md index c645f3c8c..5eabb8177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Remove `MimeMessage::from_bytes()` public interface. #4033 - BREAKING Types: jsonrpc: `get_messages` now returns a map with `MessageLoadResult` instead of failing completely if one of the requested messages could not be loaded. #4038 +- Add dc_msg_set_subject() C-FFI #4057 ## 1.108.0 diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index a24b500df..6148d4198 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4327,6 +4327,18 @@ void dc_msg_set_text (dc_msg_t* msg, const char* text); void dc_msg_set_html (dc_msg_t* msg, const char* html); +/** + * Sets the email's subject. If it's empty, a default subject + * will be used (e.g. `Message from Alice` or `Re: `). + * This does not alter any information in the database. + * + * @memberof dc_msg_t + * @param msg The message object. + * @param subject The new subject. + */ +void dc_msg_set_subject (dc_msg_t* msg, const char* subject); + + /** * Set different sender name for a message. * This overrides the name set by the dc_set_config()-option `displayname`. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index c7cd23bd2..1866a367f 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -3598,6 +3598,16 @@ pub unsafe extern "C" fn dc_msg_set_html(msg: *mut dc_msg_t, html: *const libc:: ffi_msg.message.set_html(to_opt_string_lossy(html)) } +#[no_mangle] +pub unsafe extern "C" fn dc_msg_set_subject(msg: *mut dc_msg_t, subject: *const libc::c_char) { + if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_subject()"); + return; + } + let ffi_msg = &mut *msg; + ffi_msg.message.set_subject(to_string_lossy(subject)); +} + #[no_mangle] pub unsafe extern "C" fn dc_msg_set_override_sender_name( msg: *mut dc_msg_t, diff --git a/src/message.rs b/src/message.rs index 688676253..e4bae9a67 100644 --- a/src/message.rs +++ b/src/message.rs @@ -797,6 +797,12 @@ impl Message { self.text = text; } + /// Sets the email's subject. If it's empty, a default subject + /// will be used (e.g. `Message from Alice` or `Re: `). + pub fn set_subject(&mut self, subject: String) { + self.subject = subject; + } + /// Sets the file associated with a message. /// /// This function does not use the file or check if it exists, diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 2672c203d..43978c112 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1612,6 +1612,22 @@ mod tests { assert_eq!(maybe_encode_words("äöü"), "=?utf-8?b?w6TDtsO8?="); } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_manually_set_subject() -> Result<()> { + let t = TestContext::new_alice().await; + let chat = t.create_chat_with_contact("bob", "bob@example.org").await; + + let mut msg = Message::new(Viewtype::Text); + msg.set_subject("Subjeeeeect".to_string()); + + let sent_msg = t.send_msg(chat.id, &mut msg).await; + let payload = sent_msg.payload(); + + assert_eq!(payload.match_indices("Subject: Subjeeeeect").count(), 1); + + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_subject_from_mua() { // 1.: Receive a mail from an MUA