diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 9826b959b..9f730fd45 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -96,16 +96,7 @@ pub unsafe fn dc_reset_tables(context: &Context, bits: i32) -> i32 { fn dc_poke_eml_file(context: &Context, filename: impl AsRef) -> Result<(), Error> { let data = dc_read_file(context, filename)?; - unsafe { - dc_receive_imf( - context, - data.as_ptr() as *const _, - data.len(), - "import", - 0, - 0, - ) - }; + unsafe { dc_receive_imf(context, &data, "import", 0, 0) }; Ok(()) } diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 16be9aaa9..e52c1364d 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -39,8 +39,7 @@ enum CreateEvent { /// Receive a message and add it to the database. pub unsafe fn dc_receive_imf( context: &Context, - imf_raw_not_terminated: *const libc::c_char, - imf_raw_bytes: libc::size_t, + imf_raw: &[u8], server_folder: impl AsRef, server_uid: u32, flags: u32, @@ -61,9 +60,8 @@ pub unsafe fn dc_receive_imf( // we use mailmime_parse() through dc_mimeparser (both call mailimf_struct_multiple_parse() // somewhen, I did not found out anything that speaks against this approach yet) - let body = std::slice::from_raw_parts(imf_raw_not_terminated as *const u8, imf_raw_bytes); let mut mime_parser = MimeParser::new(context); - mime_parser.parse(body); + mime_parser.parse(imf_raw); if mime_parser.header.is_empty() { // Error - even adding an empty record won't help as we do not know the message ID @@ -204,8 +202,7 @@ pub unsafe fn dc_receive_imf( if let Err(err) = add_parts( context, &mut mime_parser, - imf_raw_not_terminated, - imf_raw_bytes, + imf_raw, incoming, &mut incoming_origin, server_folder.as_ref(), @@ -292,8 +289,7 @@ pub unsafe fn dc_receive_imf( unsafe fn add_parts( context: &Context, mut mime_parser: &mut MimeParser, - imf_raw_not_terminated: *const libc::c_char, - imf_raw_bytes: libc::size_t, + imf_raw: &[u8], incoming: i32, incoming_origin: &mut Origin, server_folder: impl AsRef, @@ -683,10 +679,7 @@ unsafe fn add_parts( part.bytes, *hidden, if save_mime_headers { - Some(String::from_utf8_lossy(std::slice::from_raw_parts( - imf_raw_not_terminated as *const u8, - imf_raw_bytes, - ))) + Some(String::from_utf8_lossy(imf_raw)) } else { None }, diff --git a/src/imap.rs b/src/imap.rs index 2fde8d25f..7ce12d021 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -953,14 +953,7 @@ impl Imap { if !is_deleted && msg.body().is_some() { let body = msg.body().unwrap(); unsafe { - dc_receive_imf( - context, - body.as_ptr() as *const libc::c_char, - body.len(), - folder.as_ref(), - server_uid, - flags as u32, - ); + dc_receive_imf(context, &body, folder.as_ref(), server_uid, flags as u32); } } }