mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
Add dc_msg_set_subject() C FFI (#4057)
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
- Remove `MimeMessage::from_bytes()` public interface. #4033
|
- 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
|
- 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
|
## 1.108.0
|
||||||
|
|||||||
@@ -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);
|
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: <last subject>`).
|
||||||
|
* 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.
|
* Set different sender name for a message.
|
||||||
* This overrides the name set by the dc_set_config()-option `displayname`.
|
* This overrides the name set by the dc_set_config()-option `displayname`.
|
||||||
|
|||||||
@@ -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))
|
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]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_override_sender_name(
|
pub unsafe extern "C" fn dc_msg_set_override_sender_name(
|
||||||
msg: *mut dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
|
|||||||
@@ -797,6 +797,12 @@ impl Message {
|
|||||||
self.text = text;
|
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: <last subject>`).
|
||||||
|
pub fn set_subject(&mut self, subject: String) {
|
||||||
|
self.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the file associated with a message.
|
/// Sets the file associated with a message.
|
||||||
///
|
///
|
||||||
/// This function does not use the file or check if it exists,
|
/// This function does not use the file or check if it exists,
|
||||||
|
|||||||
@@ -1612,6 +1612,22 @@ mod tests {
|
|||||||
assert_eq!(maybe_encode_words("äöü"), "=?utf-8?b?w6TDtsO8?=");
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_subject_from_mua() {
|
async fn test_subject_from_mua() {
|
||||||
// 1.: Receive a mail from an MUA
|
// 1.: Receive a mail from an MUA
|
||||||
|
|||||||
Reference in New Issue
Block a user