mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
dc_mimeparser_parse: accept input as slice, not as pointer + length
This commit is contained in:
committed by
Floris Bruynooghe
parent
d3048aa06f
commit
21976b14a6
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user