mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 00:06:30 +03:00
Remove C pointer manipulation from do_DC_JOB_SEND()
This change removes several `unsafe' blocks by using safe version of
`dc_read_file' function.
Note, that logic is changed slightly: if get(Param::File) returns
Some(""), it no longer triggers "missing filename warnings".
This commit is contained in:
committed by
holger krekel
parent
46520edd87
commit
0391aebaeb
20
src/job.rs
20
src/job.rs
@@ -112,9 +112,6 @@ impl Job {
|
|||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn do_DC_JOB_SEND(&mut self, context: &Context) {
|
fn do_DC_JOB_SEND(&mut self, context: &Context) {
|
||||||
let ok_to_continue;
|
let ok_to_continue;
|
||||||
let mut filename = ptr::null_mut();
|
|
||||||
let mut buf = ptr::null_mut();
|
|
||||||
let mut buf_bytes = 0;
|
|
||||||
|
|
||||||
/* connect to SMTP server, if not yet done */
|
/* connect to SMTP server, if not yet done */
|
||||||
if !context.smtp.lock().unwrap().is_connected() {
|
if !context.smtp.lock().unwrap().is_connected() {
|
||||||
@@ -131,11 +128,8 @@ impl Job {
|
|||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
}
|
}
|
||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
let filename_s = self.param.get(Param::File).unwrap_or_default();
|
if let Some(filename) = self.param.get(Param::File) {
|
||||||
filename = unsafe { filename_s.strdup() };
|
if let Some(body) = dc_read_file_safe(context, filename) {
|
||||||
if unsafe { strlen(filename) } == 0 {
|
|
||||||
warn!(context, 0, "Missing file name for job {}", self.job_id,);
|
|
||||||
} else if 0 != unsafe { dc_read_file(context, filename, &mut buf, &mut buf_bytes) } {
|
|
||||||
if let Some(recipients) = self.param.get(Param::Recipients) {
|
if let Some(recipients) = self.param.get(Param::Recipients) {
|
||||||
let recipients_list = recipients
|
let recipients_list = recipients
|
||||||
.split("\x1e")
|
.split("\x1e")
|
||||||
@@ -168,11 +162,6 @@ impl Job {
|
|||||||
ok_to_continue1 = true;
|
ok_to_continue1 = true;
|
||||||
}
|
}
|
||||||
if ok_to_continue1 {
|
if ok_to_continue1 {
|
||||||
/* send message */
|
|
||||||
let body = unsafe {
|
|
||||||
std::slice::from_raw_parts(buf as *const u8, buf_bytes).to_vec()
|
|
||||||
};
|
|
||||||
|
|
||||||
// hold the smtp lock during sending of a job and
|
// hold the smtp lock during sending of a job and
|
||||||
// its ok/error response processing. Note that if a message
|
// its ok/error response processing. Note that if a message
|
||||||
// was sent we need to mark it in the database as we
|
// was sent we need to mark it in the database as we
|
||||||
@@ -182,7 +171,7 @@ impl Job {
|
|||||||
sock.disconnect();
|
sock.disconnect();
|
||||||
self.try_again_later(-1i32, Some(as_str(sock.error)));
|
self.try_again_later(-1i32, Some(as_str(sock.error)));
|
||||||
} else {
|
} else {
|
||||||
dc_delete_file(context, filename_s);
|
dc_delete_file(context, filename);
|
||||||
if 0 != self.foreign_id {
|
if 0 != self.foreign_id {
|
||||||
dc_update_msg_state(
|
dc_update_msg_state(
|
||||||
context,
|
context,
|
||||||
@@ -211,8 +200,7 @@ impl Job {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { free(buf) };
|
}
|
||||||
unsafe { free(filename.cast()) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this value does not increase the number of tries
|
// this value does not increase the number of tries
|
||||||
|
|||||||
Reference in New Issue
Block a user