cargo fmt

This commit is contained in:
Simon Laux
2019-08-12 05:42:02 +02:00
parent 50c592e41f
commit 9e30df4b43

View File

@@ -312,88 +312,81 @@ unsafe fn dc_job_do_DC_JOB_SEND(context: &Context, job: &mut dc_job_t) {
ok_to_continue = true; ok_to_continue = true;
} }
if ok_to_continue { if ok_to_continue {
let filename_s = job.param.get(Param::File).unwrap_or_default(); let filename_s = job.param.get(Param::File).unwrap_or_default();
filename = filename_s.strdup(); filename = filename_s.strdup();
if strlen(filename) == 0 { if strlen(filename) == 0 {
warn!(context, 0, "Missing file name for job {}", job.job_id,); warn!(context, 0, "Missing file name for job {}", job.job_id,);
} else if !(0 == dc_read_file(context, filename, &mut buf, &mut buf_bytes)) { } else if !(0 == dc_read_file(context, filename, &mut buf, &mut buf_bytes)) {
let recipients = job.param.get(Param::Recipients); let recipients = job.param.get(Param::Recipients);
if recipients.is_none() { if recipients.is_none() {
warn!(context, 0, "Missing recipients for job {}", job.job_id,); warn!(context, 0, "Missing recipients for job {}", job.job_id,);
} else { } else {
let recipients_list = recipients let recipients_list = recipients
.unwrap() .unwrap()
.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 != job.foreign_id {
if 0 == dc_msg_exists(context, job.foreign_id) {
warn!(
context,
0,
"Message {} for job {} does not exist",
job.foreign_id,
job.job_id,
);
ok_to_continue1 = false;
} else {
ok_to_continue1 = true;
} }
})
.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 != job.foreign_id {
if 0 == dc_msg_exists(context, job.foreign_id) {
warn!(
context,
0, "Message {} for job {} does not exist", job.foreign_id, job.job_id,
);
ok_to_continue1 = false;
} else { } else {
ok_to_continue1 = true; ok_to_continue1 = true;
} }
if ok_to_continue1 { } else {
/* send message */ ok_to_continue1 = true;
let body = }
std::slice::from_raw_parts(buf as *const u8, buf_bytes).to_vec(); if ok_to_continue1 {
if 0 == context.smtp.lock().unwrap().send( /* send message */
context, let body = std::slice::from_raw_parts(buf as *const u8, buf_bytes).to_vec();
recipients_list, if 0 == context
body, .smtp
) { .lock()
context.smtp.lock().unwrap().disconnect(); .unwrap()
dc_job_try_again_later( .send(context, recipients_list, body)
job, {
-1i32, context.smtp.lock().unwrap().disconnect();
(*&mut context.smtp.clone().lock().unwrap()).error, dc_job_try_again_later(
); job,
} else { -1i32,
dc_delete_file(context, filename_s); (*&mut context.smtp.clone().lock().unwrap()).error,
if 0 != job.foreign_id { );
dc_update_msg_state( } else {
context, dc_delete_file(context, filename_s);
job.foreign_id, if 0 != job.foreign_id {
DC_STATE_OUT_DELIVERED, dc_update_msg_state(context, job.foreign_id, DC_STATE_OUT_DELIVERED);
); let chat_id: i32 = context
let chat_id: i32 = context .sql
.sql .query_row_col(
.query_row_col( context,
context, "SELECT chat_id FROM msgs WHERE id=?",
"SELECT chat_id FROM msgs WHERE id=?", params![job.foreign_id as i32],
params![job.foreign_id as i32], 0,
0, )
) .unwrap_or_default();
.unwrap_or_default(); context.call_cb(
context.call_cb( Event::MSG_DELIVERED,
Event::MSG_DELIVERED, chat_id as uintptr_t,
chat_id as uintptr_t, job.foreign_id as uintptr_t,
job.foreign_id as uintptr_t, );
); }
}
}
} }
} }
} }
}
} }
free(buf); free(buf);
free(filename as *mut libc::c_void); free(filename as *mut libc::c_void);
@@ -430,43 +423,38 @@ unsafe fn dc_job_do_DC_JOB_MOVE_MSG(context: &Context, job: &mut dc_job_t) {
ok_to_continue = true; ok_to_continue = true;
} }
if ok_to_continue { if ok_to_continue {
if dc_msg_load_from_db(msg, context, job.foreign_id) { if dc_msg_load_from_db(msg, context, job.foreign_id) {
if context if context
.sql .sql
.get_config_int(context, "folders_configured") .get_config_int(context, "folders_configured")
.unwrap_or_default() .unwrap_or_default()
< 3 < 3
{
inbox.configure_folders(context, 0x1i32);
}
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
if let Some(dest_folder) = dest_folder {
let server_folder = (*msg).server_folder.as_ref().unwrap();
match inbox.mv(
context,
server_folder,
(*msg).server_uid,
&dest_folder,
&mut dest_uid,
) as libc::c_uint
{ {
inbox.configure_folders(context, 0x1i32); 1 => {
} dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
if let Some(dest_folder) = dest_folder {
let server_folder = (*msg).server_folder.as_ref().unwrap();
match inbox.mv(
context,
server_folder,
(*msg).server_uid,
&dest_folder,
&mut dest_uid,
) as libc::c_uint
{
1 => {
dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
}
3 => {
dc_update_server_uid(
context,
(*msg).rfc724_mid,
&dest_folder,
dest_uid,
);
}
0 | 2 | _ => {}
} }
3 => {
dc_update_server_uid(context, (*msg).rfc724_mid, &dest_folder, dest_uid);
}
0 | 2 | _ => {}
} }
} }
}
} }
dc_msg_unref(msg); dc_msg_unref(msg);
@@ -507,27 +495,25 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context: &Context, job: &mut dc_
ok_to_continue = true; ok_to_continue = true;
} }
if ok_to_continue { if ok_to_continue {
if inbox.set_seen(context, &folder, uid) == 0 { if inbox.set_seen(context, &folder, uid) == 0 {
dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char); dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
}
if 0 != job.param.get_int(Param::AlsoMove).unwrap_or_default() {
if context
.sql
.get_config_int(context, "folders_configured")
.unwrap_or_default()
< 3
{
inbox.configure_folders(context, 0x1i32);
} }
if 0 != job.param.get_int(Param::AlsoMove).unwrap_or_default() { let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
if context if let Some(dest_folder) = dest_folder {
.sql if 1 == inbox.mv(context, folder, uid, dest_folder, &mut dest_uid) as libc::c_uint {
.get_config_int(context, "folders_configured") dc_job_try_again_later(job, 3, 0 as *const libc::c_char);
.unwrap_or_default()
< 3
{
inbox.configure_folders(context, 0x1i32);
}
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
if let Some(dest_folder) = dest_folder {
if 1 == inbox.mv(context, folder, uid, dest_folder, &mut dest_uid)
as libc::c_uint
{
dc_job_try_again_later(job, 3, 0 as *const libc::c_char);
}
} }
} }
}
} }
} }
@@ -549,41 +535,36 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MSG_ON_IMAP(context: &Context, job: &mut dc_
ok_to_continue = true; ok_to_continue = true;
} }
if ok_to_continue { if ok_to_continue {
if dc_msg_load_from_db(msg, context, job.foreign_id) { if dc_msg_load_from_db(msg, context, job.foreign_id) {
let server_folder = (*msg).server_folder.as_ref().unwrap(); let server_folder = (*msg).server_folder.as_ref().unwrap();
match inbox.set_seen(context, server_folder, (*msg).server_uid) as libc::c_uint { match inbox.set_seen(context, server_folder, (*msg).server_uid) as libc::c_uint {
0 => {} 0 => {}
1 => { 1 => {
dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char); dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
} }
_ => { _ => {
if 0 != (*msg).param.get_int(Param::WantsMdn).unwrap_or_default() if 0 != (*msg).param.get_int(Param::WantsMdn).unwrap_or_default()
&& 0 != context && 0 != context
.sql .sql
.get_config_int(context, "mdns_enabled") .get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1) .unwrap_or_else(|| 1)
{ {
let folder = (*msg).server_folder.as_ref().unwrap(); let folder = (*msg).server_folder.as_ref().unwrap();
match inbox.set_mdnsent(context, folder, (*msg).server_uid) match inbox.set_mdnsent(context, folder, (*msg).server_uid) as libc::c_uint
as libc::c_uint {
{ 1 => {
1 => { dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
dc_job_try_again_later( }
job, 3 => {
3i32, dc_send_mdn(context, (*msg).id);
0 as *const libc::c_char, }
); 0 | 2 | _ => {}
} }
3 => {
dc_send_mdn(context, (*msg).id);
}
0 | 2 | _ => {}
}
}
} }
} }
} }
}
} }
dc_msg_unref(msg); dc_msg_unref(msg);
} }
@@ -782,14 +763,14 @@ unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(context: &Context, job: &mut dc_jo
ok_to_continue = true; ok_to_continue = true;
} }
if ok_to_continue { if ok_to_continue {
let mid = CStr::from_ptr((*msg).rfc724_mid).to_str().unwrap(); let mid = CStr::from_ptr((*msg).rfc724_mid).to_str().unwrap();
let server_folder = (*msg).server_folder.as_ref().unwrap(); let server_folder = (*msg).server_folder.as_ref().unwrap();
if 0 == inbox.delete_msg(context, mid, server_folder, &mut (*msg).server_uid) { if 0 == inbox.delete_msg(context, mid, server_folder, &mut (*msg).server_uid) {
dc_job_try_again_later(job, -1i32, 0 as *const libc::c_char); dc_job_try_again_later(job, -1i32, 0 as *const libc::c_char);
ok_to_continue1 = false; ok_to_continue1 = false;
} else { } else {
ok_to_continue1 = true; ok_to_continue1 = true;
} }
} else { } else {
ok_to_continue1 = false; ok_to_continue1 = false;
} }
@@ -797,7 +778,7 @@ unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(context: &Context, job: &mut dc_jo
ok_to_continue1 = true; ok_to_continue1 = true;
} }
if ok_to_continue1 { if ok_to_continue1 {
dc_delete_msg_from_db(context, (*msg).id); dc_delete_msg_from_db(context, (*msg).id);
} }
} }
dc_msg_unref(msg); dc_msg_unref(msg);