diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index 8a208a5b3..62032fb18 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -123,18 +123,14 @@ unsafe fn dc_mimepart_unref(mut mimepart: dc_mimepart_t) { mimepart.msg_raw = 0 as *mut libc::c_char; } -pub unsafe fn dc_mimeparser_parse( - mimeparser: &mut dc_mimeparser_t, - body_not_terminated: *const libc::c_char, - body_bytes: size_t, -) { +pub unsafe fn dc_mimeparser_parse(mimeparser: &mut dc_mimeparser_t, body: &[u8]) { let r: libc::c_int; let mut index: size_t = 0i32 as size_t; let optional_field: *mut mailimf_optional_field; dc_mimeparser_empty(mimeparser); r = mailmime_parse( - body_not_terminated, - body_bytes, + body.as_ptr() as *const libc::c_char, + body.len(), &mut index, &mut mimeparser.mimeroot, ); diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index d3f5cc7cd..eaaa7358e 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -57,7 +57,8 @@ pub unsafe fn dc_receive_imf( // somewhen, I did not found out anything that speaks against this approach yet) let mut mime_parser = dc_mimeparser_new(context); - dc_mimeparser_parse(&mut mime_parser, imf_raw_not_terminated, imf_raw_bytes); + let body = std::slice::from_raw_parts(imf_raw_not_terminated as *const u8, imf_raw_bytes); + dc_mimeparser_parse(&mut mime_parser, body); if mime_parser.header.is_empty() { // Error - even adding an empty record won't help as we do not know the message ID diff --git a/tests/stress.rs b/tests/stress.rs index 018f98155..55c18843d 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -659,11 +659,9 @@ fn test_dc_mimeparser_with_context() { let context = create_test_context(); let mut mimeparser = dc_mimeparser_new(&context.ctx); - let raw: *const libc::c_char = - b"Content-Type: multipart/mixed; boundary=\"==break==\";\nSubject: outer-subject\nX-Special-A: special-a\nFoo: Bar\nChat-Version: 0.0\n\n--==break==\nContent-Type: text/plain; protected-headers=\"v1\";\nSubject: inner-subject\nX-Special-B: special-b\nFoo: Xy\nChat-Version: 1.0\n\ntest1\n\n--==break==--\n\n\x00" - as *const u8 as *const libc::c_char; + let raw = b"Content-Type: multipart/mixed; boundary=\"==break==\";\nSubject: outer-subject\nX-Special-A: special-a\nFoo: Bar\nChat-Version: 0.0\n\n--==break==\nContent-Type: text/plain; protected-headers=\"v1\";\nSubject: inner-subject\nX-Special-B: special-b\nFoo: Xy\nChat-Version: 1.0\n\ntest1\n\n--==break==--\n\n\x00"; - dc_mimeparser_parse(&mut mimeparser, raw, strlen(raw)); + dc_mimeparser_parse(&mut mimeparser, &raw[..]); assert_eq!( as_str(mimeparser.subject as *const libc::c_char), "inner-subject",