mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
Pass slice to dc_receive_imf
instead of pointer and length
This commit is contained in:
@@ -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<Path>) -> Result<(), Error> {
|
fn dc_poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<(), Error> {
|
||||||
let data = dc_read_file(context, filename)?;
|
let data = dc_read_file(context, filename)?;
|
||||||
|
|
||||||
unsafe {
|
unsafe { dc_receive_imf(context, &data, "import", 0, 0) };
|
||||||
dc_receive_imf(
|
|
||||||
context,
|
|
||||||
data.as_ptr() as *const _,
|
|
||||||
data.len(),
|
|
||||||
"import",
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ enum CreateEvent {
|
|||||||
/// Receive a message and add it to the database.
|
/// Receive a message and add it to the database.
|
||||||
pub unsafe fn dc_receive_imf(
|
pub unsafe fn dc_receive_imf(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
imf_raw_not_terminated: *const libc::c_char,
|
imf_raw: &[u8],
|
||||||
imf_raw_bytes: libc::size_t,
|
|
||||||
server_folder: impl AsRef<str>,
|
server_folder: impl AsRef<str>,
|
||||||
server_uid: u32,
|
server_uid: u32,
|
||||||
flags: 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()
|
// 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)
|
// 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);
|
let mut mime_parser = MimeParser::new(context);
|
||||||
mime_parser.parse(body);
|
mime_parser.parse(imf_raw);
|
||||||
|
|
||||||
if mime_parser.header.is_empty() {
|
if mime_parser.header.is_empty() {
|
||||||
// Error - even adding an empty record won't help as we do not know the message ID
|
// 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(
|
if let Err(err) = add_parts(
|
||||||
context,
|
context,
|
||||||
&mut mime_parser,
|
&mut mime_parser,
|
||||||
imf_raw_not_terminated,
|
imf_raw,
|
||||||
imf_raw_bytes,
|
|
||||||
incoming,
|
incoming,
|
||||||
&mut incoming_origin,
|
&mut incoming_origin,
|
||||||
server_folder.as_ref(),
|
server_folder.as_ref(),
|
||||||
@@ -292,8 +289,7 @@ pub unsafe fn dc_receive_imf(
|
|||||||
unsafe fn add_parts(
|
unsafe fn add_parts(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mut mime_parser: &mut MimeParser,
|
mut mime_parser: &mut MimeParser,
|
||||||
imf_raw_not_terminated: *const libc::c_char,
|
imf_raw: &[u8],
|
||||||
imf_raw_bytes: libc::size_t,
|
|
||||||
incoming: i32,
|
incoming: i32,
|
||||||
incoming_origin: &mut Origin,
|
incoming_origin: &mut Origin,
|
||||||
server_folder: impl AsRef<str>,
|
server_folder: impl AsRef<str>,
|
||||||
@@ -683,10 +679,7 @@ unsafe fn add_parts(
|
|||||||
part.bytes,
|
part.bytes,
|
||||||
*hidden,
|
*hidden,
|
||||||
if save_mime_headers {
|
if save_mime_headers {
|
||||||
Some(String::from_utf8_lossy(std::slice::from_raw_parts(
|
Some(String::from_utf8_lossy(imf_raw))
|
||||||
imf_raw_not_terminated as *const u8,
|
|
||||||
imf_raw_bytes,
|
|
||||||
)))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -953,14 +953,7 @@ impl Imap {
|
|||||||
if !is_deleted && msg.body().is_some() {
|
if !is_deleted && msg.body().is_some() {
|
||||||
let body = msg.body().unwrap();
|
let body = msg.body().unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
dc_receive_imf(
|
dc_receive_imf(context, &body, folder.as_ref(), server_uid, flags as u32);
|
||||||
context,
|
|
||||||
body.as_ptr() as *const libc::c_char,
|
|
||||||
body.len(),
|
|
||||||
folder.as_ref(),
|
|
||||||
server_uid,
|
|
||||||
flags as u32,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user