mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
refactor(receive_imf): remove dc_mprintf
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use std::ffi::CString;
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use itertools::join;
|
use itertools::join;
|
||||||
@@ -307,14 +306,10 @@ unsafe fn add_parts(
|
|||||||
let mut rcvd_timestamp = 0;
|
let mut rcvd_timestamp = 0;
|
||||||
let mut mime_in_reply_to = std::ptr::null_mut();
|
let mut mime_in_reply_to = std::ptr::null_mut();
|
||||||
let mut mime_references = std::ptr::null_mut();
|
let mut mime_references = std::ptr::null_mut();
|
||||||
let mut txt_raw = std::ptr::null_mut();
|
|
||||||
|
|
||||||
let cleanup = |mime_in_reply_to: *mut libc::c_char,
|
let cleanup = |mime_in_reply_to: *mut libc::c_char, mime_references: *mut libc::c_char| {
|
||||||
mime_references: *mut libc::c_char,
|
|
||||||
txt_raw: *mut libc::c_char| {
|
|
||||||
free(mime_in_reply_to.cast());
|
free(mime_in_reply_to.cast());
|
||||||
free(mime_references.cast());
|
free(mime_references.cast());
|
||||||
free(txt_raw.cast());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// collect the rest information, CC: is added to the to-list, BCC: is ignored
|
// collect the rest information, CC: is added to the to-list, BCC: is ignored
|
||||||
@@ -353,7 +348,7 @@ unsafe fn add_parts(
|
|||||||
if rfc724_mid.is_null() {
|
if rfc724_mid.is_null() {
|
||||||
rfc724_mid = dc_create_incoming_rfc724_mid(*sent_timestamp, *from_id, to_ids);
|
rfc724_mid = dc_create_incoming_rfc724_mid(*sent_timestamp, *from_id, to_ids);
|
||||||
if rfc724_mid.is_null() {
|
if rfc724_mid.is_null() {
|
||||||
cleanup(mime_in_reply_to, mime_references, txt_raw);
|
cleanup(mime_in_reply_to, mime_references);
|
||||||
bail!("Cannot create Message-ID");
|
bail!("Cannot create Message-ID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,7 +370,7 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(old_server_folder.cast());
|
free(old_server_folder.cast());
|
||||||
cleanup(mime_in_reply_to, mime_references, txt_raw);
|
cleanup(mime_in_reply_to, mime_references);
|
||||||
bail!("Message already in DB");
|
bail!("Message already in DB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,6 +625,8 @@ unsafe fn add_parts(
|
|||||||
// into only one message; mails sent by other clients may result in several messages
|
// into only one message; mails sent by other clients may result in several messages
|
||||||
// (eg. one per attachment))
|
// (eg. one per attachment))
|
||||||
let icnt = mime_parser.parts.len();
|
let icnt = mime_parser.parts.len();
|
||||||
|
let mut txt_raw = None;
|
||||||
|
|
||||||
let is_ok = context
|
let is_ok = context
|
||||||
.sql
|
.sql
|
||||||
.prepare(
|
.prepare(
|
||||||
@@ -657,20 +654,13 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if part.type_0 == Viewtype::Text {
|
if part.type_0 == Viewtype::Text {
|
||||||
let msg_raw =
|
let msg_raw = part.msg_raw.as_ref().cloned().unwrap_or_default();
|
||||||
CString::yolo(part.msg_raw.as_ref().cloned().unwrap_or_default());
|
let subject = mime_parser
|
||||||
let subject_c = CString::yolo(
|
.subject
|
||||||
mime_parser
|
.as_ref()
|
||||||
.subject
|
.map(|s| s.to_string())
|
||||||
.as_ref()
|
.unwrap_or("".into());
|
||||||
.map(|s| s.to_string())
|
txt_raw = Some(format!("{}\n\n{}", subject, msg_raw));
|
||||||
.unwrap_or("".into()),
|
|
||||||
);
|
|
||||||
txt_raw = dc_mprintf(
|
|
||||||
b"%s\n\n%s\x00" as *const u8 as *const libc::c_char,
|
|
||||||
subject_c.as_ptr(),
|
|
||||||
msg_raw.as_ptr(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if 0 != mime_parser.is_system_message {
|
if 0 != mime_parser.is_system_message {
|
||||||
part.param
|
part.param
|
||||||
@@ -692,11 +682,7 @@ unsafe fn add_parts(
|
|||||||
msgrmsg,
|
msgrmsg,
|
||||||
part.msg.as_ref().map_or("", String::as_str),
|
part.msg.as_ref().map_or("", String::as_str),
|
||||||
// txt_raw might contain invalid utf8
|
// txt_raw might contain invalid utf8
|
||||||
if !txt_raw.is_null() {
|
txt_raw.unwrap_or_default(),
|
||||||
to_string_lossy(txt_raw)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
},
|
|
||||||
part.param.to_string(),
|
part.param.to_string(),
|
||||||
part.bytes,
|
part.bytes,
|
||||||
*hidden,
|
*hidden,
|
||||||
@@ -715,8 +701,7 @@ unsafe fn add_parts(
|
|||||||
to_string(mime_references),
|
to_string(mime_references),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
free(txt_raw as *mut libc::c_void);
|
txt_raw = None;
|
||||||
txt_raw = ptr::null_mut();
|
|
||||||
*insert_msg_id = sql::get_rowid_with_conn(
|
*insert_msg_id = sql::get_rowid_with_conn(
|
||||||
context,
|
context,
|
||||||
conn,
|
conn,
|
||||||
@@ -733,7 +718,7 @@ unsafe fn add_parts(
|
|||||||
|
|
||||||
if !is_ok {
|
if !is_ok {
|
||||||
// i/o error - there is nothing more we can do - in other cases, we try to write at least an empty record
|
// i/o error - there is nothing more we can do - in other cases, we try to write at least an empty record
|
||||||
cleanup(mime_in_reply_to, mime_references, txt_raw);
|
cleanup(mime_in_reply_to, mime_references);
|
||||||
bail!("Cannot write DB.");
|
bail!("Cannot write DB.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,7 +741,7 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.do_heuristics_moves(server_folder.as_ref(), *insert_msg_id);
|
context.do_heuristics_moves(server_folder.as_ref(), *insert_msg_id);
|
||||||
cleanup(mime_in_reply_to, mime_references, txt_raw);
|
cleanup(mime_in_reply_to, mime_references);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user