- simplify inbox-connection-guards and returns

- make dc_msg_exists safe
This commit is contained in:
holger krekel
2019-08-20 11:15:28 +02:00
parent 287ccb15ba
commit 9227c4b55c
4 changed files with 40 additions and 49 deletions

View File

@@ -1031,7 +1031,7 @@ pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before:
let curr_local_timestamp = ts + cnv_to_local;
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
if curr_day != last_day {
ret.push(DC_MSG_ID_LAST_SPECIAL as u32);
ret.push(DC_MSG_ID_LAST_SPECIAL);
last_day = curr_day;
}
}

View File

@@ -108,7 +108,7 @@ impl Default for Chattype {
pub const DC_MSG_ID_MARKER1: usize = 1;
const DC_MSG_ID_DAYMARKER: usize = 9;
pub const DC_MSG_ID_LAST_SPECIAL: usize = 9;
pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9;
/// approx. max. length returned by dc_msg_get_text()
const DC_MAX_GET_TEXT_LEN: usize = 30000;

View File

@@ -149,7 +149,7 @@ impl Job {
this happends if dc_delete_msgs() was called
before the generated mime was sent out */
if 0 != self.foreign_id {
if 0 == unsafe { dc_msg_exists(context, self.foreign_id) } {
if !dc_msg_exists(context, self.foreign_id) {
warn!(
context,
0, "Message {} for job {} does not exist", self.foreign_id, self.job_id,
@@ -197,12 +197,9 @@ impl Job {
fn do_DC_JOB_MOVE_MSG(&mut self, context: &Context) {
let inbox = context.inbox.read().unwrap();
if !inbox.is_connected() {
connect_to_inbox(context, &inbox);
if !inbox.is_connected() {
self.try_again_later(Delay::Standard, None);
return;
}
if !connect_to_inbox(context, &inbox) {
self.try_again_later(Delay::Standard, None);
return;
}
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
if context
@@ -256,12 +253,9 @@ impl Job {
return;
}
/* if this is the last existing part of the message, we delete the message from the server */
if !inbox.is_connected() {
connect_to_inbox(context, &inbox);
if !inbox.is_connected() {
self.try_again_later(Delay::Standard, None);
return;
}
if !connect_to_inbox(context, &inbox) {
self.try_again_later(Delay::Standard, None);
return;
}
let mid = unsafe { CStr::from_ptr(msg.rfc724_mid).to_str().unwrap() };
let server_folder = msg.server_folder.as_ref().unwrap();
@@ -281,12 +275,9 @@ impl Job {
fn do_DC_JOB_MARKSEEN_MSG_ON_IMAP(&mut self, context: &Context) {
let inbox = context.inbox.read().unwrap();
if !inbox.is_connected() {
connect_to_inbox(context, &inbox);
if !inbox.is_connected() {
self.try_again_later(Delay::Standard, None);
return;
}
if !connect_to_inbox(context, &inbox) {
self.try_again_later(Delay::Standard, None);
return;
}
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
let server_folder = msg.server_folder.as_ref().unwrap();
@@ -333,12 +324,9 @@ impl Job {
let mut dest_uid = 0;
let inbox = context.inbox.read().unwrap();
if !inbox.is_connected() {
connect_to_inbox(context, &inbox);
if !inbox.is_connected() {
self.try_again_later(Delay::Standard, None);
return;
}
if !connect_to_inbox(context, &inbox) {
self.try_again_later(Delay::Standard, None);
return;
}
match inbox.set_seen(context, &folder, uid) {
@@ -388,7 +376,7 @@ pub fn perform_imap_fetch(context: &Context) {
let inbox = context.inbox.read().unwrap();
let start = std::time::Instant::now();
if 0 == connect_to_inbox(context, &inbox) {
if !connect_to_inbox(context, &inbox) {
return;
}
if context
@@ -937,12 +925,18 @@ fn suspend_smtp_thread(context: &Context, suspend: bool) {
}
}
fn connect_to_inbox(context: &Context, inbox: &Imap) -> libc::c_int {
let ret_connected = dc_connect_to_configured_imap(context, inbox);
if 0 != ret_connected {
inbox.set_watch_folder("INBOX".into());
fn connect_to_inbox(context: &Context, inbox: &Imap) -> bool {
if inbox.is_connected() {
true
} else {
let ret_connected = dc_connect_to_configured_imap(context, inbox);
if 0 != ret_connected {
inbox.set_watch_folder("INBOX".into());
true
} else {
false
}
}
ret_connected
}
fn send_mdn(context: &Context, msg_id: uint32_t) {

View File

@@ -1033,25 +1033,22 @@ The value is also used for CC:-summaries */
// Context functions to work with messages
pub unsafe fn dc_msg_exists(context: &Context, msg_id: u32) -> libc::c_int {
if msg_id <= 9 {
return 0;
}
pub fn dc_msg_exists(context: &Context, msg_id: u32) -> bool {
if msg_id > DC_MSG_ID_LAST_SPECIAL {
let chat_id: Option<i32> = context.sql.query_row_col(
context,
"SELECT chat_id FROM msgs WHERE id=?;",
params![msg_id as i32],
0,
);
let chat_id: Option<i32> = context.sql.query_row_col(
context,
"SELECT chat_id FROM msgs WHERE id=?;",
params![msg_id as i32],
0,
);
if let Some(chat_id) = chat_id {
if chat_id != 3 {
return 1;
if let Some(chat_id) = chat_id {
if chat_id != 3 {
return true;
}
}
}
0
false
}
pub fn dc_update_msg_move_state(