mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
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:
committed by
holger krekel
parent
0391aebaeb
commit
98d6bdb48a
135
src/job.rs
135
src/job.rs
@@ -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,84 +118,71 @@ 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) {
|
||||||
let recipients_list = recipients
|
let recipients_list = recipients
|
||||||
.split("\x1e")
|
.split("\x1e")
|
||||||
.filter_map(|addr| match lettre::EmailAddress::new(addr.to_string()) {
|
.filter_map(|addr| match lettre::EmailAddress::new(addr.to_string()) {
|
||||||
Ok(addr) => Some(addr),
|
Ok(addr) => Some(addr),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("WARNING: invalid recipient: {} {:?}", addr, err);
|
eprintln!("WARNING: invalid recipient: {} {:?}", addr, err);
|
||||||
None
|
None
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
/* if there is a msg-id and it does not exist in the db, cancel sending.
|
|
||||||
this happends if dc_delete_msgs() was called
|
|
||||||
before the generated mime was sent out */
|
|
||||||
let ok_to_continue1;
|
|
||||||
if 0 != self.foreign_id {
|
|
||||||
if 0 == unsafe { dc_msg_exists(context, self.foreign_id) } {
|
|
||||||
warn!(
|
|
||||||
context,
|
|
||||||
0,
|
|
||||||
"Message {} for job {} does not exist",
|
|
||||||
self.foreign_id,
|
|
||||||
self.job_id,
|
|
||||||
);
|
|
||||||
ok_to_continue1 = false;
|
|
||||||
} else {
|
|
||||||
ok_to_continue1 = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
ok_to_continue1 = true;
|
.collect::<Vec<_>>();
|
||||||
}
|
|
||||||
if ok_to_continue1 {
|
/* if there is a msg-id and it does not exist in the db, cancel sending.
|
||||||
// hold the smtp lock during sending of a job and
|
this happends if dc_delete_msgs() was called
|
||||||
// its ok/error response processing. Note that if a message
|
before the generated mime was sent out */
|
||||||
// was sent we need to mark it in the database as we
|
if 0 != self.foreign_id
|
||||||
// otherwise might send it twice.
|
&& 0 == unsafe { dc_msg_exists(context, self.foreign_id) }
|
||||||
let mut sock = context.smtp.lock().unwrap();
|
{
|
||||||
if 0 == sock.send(context, recipients_list, body) {
|
warn!(
|
||||||
sock.disconnect();
|
context,
|
||||||
self.try_again_later(-1i32, Some(as_str(sock.error)));
|
0, "Message {} for job {} does not exist", self.foreign_id, self.job_id,
|
||||||
} else {
|
);
|
||||||
dc_delete_file(context, filename);
|
return;
|
||||||
if 0 != self.foreign_id {
|
};
|
||||||
dc_update_msg_state(
|
|
||||||
context,
|
// hold the smtp lock during sending of a job and
|
||||||
self.foreign_id,
|
// its ok/error response processing. Note that if a message
|
||||||
MessageState::OutDelivered,
|
// was sent we need to mark it in the database as we
|
||||||
);
|
// otherwise might send it twice.
|
||||||
let chat_id: i32 = context
|
let mut sock = context.smtp.lock().unwrap();
|
||||||
.sql
|
if 0 == sock.send(context, recipients_list, body) {
|
||||||
.query_row_col(
|
sock.disconnect();
|
||||||
context,
|
self.try_again_later(-1i32, Some(as_str(sock.error)));
|
||||||
"SELECT chat_id FROM msgs WHERE id=?",
|
|
||||||
params![self.foreign_id as i32],
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
.unwrap_or_default();
|
|
||||||
context.call_cb(
|
|
||||||
Event::MSG_DELIVERED,
|
|
||||||
chat_id as uintptr_t,
|
|
||||||
self.foreign_id as uintptr_t,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
warn!(context, 0, "Missing recipients for job {}", self.job_id,);
|
dc_delete_file(context, filename);
|
||||||
|
if 0 != self.foreign_id {
|
||||||
|
dc_update_msg_state(
|
||||||
|
context,
|
||||||
|
self.foreign_id,
|
||||||
|
MessageState::OutDelivered,
|
||||||
|
);
|
||||||
|
let chat_id: i32 = context
|
||||||
|
.sql
|
||||||
|
.query_row_col(
|
||||||
|
context,
|
||||||
|
"SELECT chat_id FROM msgs WHERE id=?",
|
||||||
|
params![self.foreign_id as i32],
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
.unwrap_or_default();
|
||||||
|
context.call_cb(
|
||||||
|
Event::MSG_DELIVERED,
|
||||||
|
chat_id as uintptr_t,
|
||||||
|
self.foreign_id as uintptr_t,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
warn!(context, 0, "Missing recipients for job {}", self.job_id,);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user