Simplify control flow in dc_DC_JOB_SEND function

Replace `ok_to_continue' control flow variables with early return from
function, since there is no longer need to free memory manually.
This commit is contained in:
Dmitry Bogatov
2019-09-04 14:10:00 +00:00
committed by holger krekel
parent 0391aebaeb
commit 98d6bdb48a

View File

@@ -111,8 +111,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;
/* 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() {
let loginparam = dc_loginparam_read(context, &context.sql, "configured_"); let loginparam = dc_loginparam_read(context, &context.sql, "configured_");
@@ -120,14 +118,10 @@ impl Job {
if !connected { if !connected {
self.try_again_later(3i32, None); self.try_again_later(3i32, None);
ok_to_continue = false; return;
} else {
ok_to_continue = true;
} }
} else {
ok_to_continue = true;
} }
if ok_to_continue {
if let Some(filename) = self.param.get(Param::File) { if let Some(filename) = self.param.get(Param::File) {
if let Some(body) = dc_read_file_safe(context, filename) { if let Some(body) = dc_read_file_safe(context, filename) {
if let Some(recipients) = self.param.get(Param::Recipients) { if let Some(recipients) = self.param.get(Param::Recipients) {
@@ -141,27 +135,20 @@ impl Job {
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
/* if there is a msg-id and it does not exist in the db, cancel sending. /* if there is a msg-id and it does not exist in the db, cancel sending.
this happends if dc_delete_msgs() was called this happends if dc_delete_msgs() was called
before the generated mime was sent out */ before the generated mime was sent out */
let ok_to_continue1; if 0 != self.foreign_id
if 0 != self.foreign_id { && 0 == unsafe { dc_msg_exists(context, self.foreign_id) }
if 0 == unsafe { dc_msg_exists(context, self.foreign_id) } { {
warn!( warn!(
context, context,
0, 0, "Message {} for job {} does not exist", self.foreign_id, self.job_id,
"Message {} for job {} does not exist",
self.foreign_id,
self.job_id,
); );
ok_to_continue1 = false; return;
} else { };
ok_to_continue1 = true;
}
} else {
ok_to_continue1 = true;
}
if ok_to_continue1 {
// 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
@@ -194,14 +181,12 @@ impl Job {
); );
} }
} }
}
} else { } else {
warn!(context, 0, "Missing recipients for job {}", self.job_id,); warn!(context, 0, "Missing recipients for job {}", self.job_id,);
} }
} }
} }
} }
}
// this value does not increase the number of tries // this value does not increase the number of tries
fn try_again_later(&mut self, try_again: libc::c_int, pending_error: Option<&str>) { fn try_again_later(&mut self, try_again: libc::c_int, pending_error: Option<&str>) {