mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 00:06:30 +03:00
- simplify inbox-connection-guards and returns
- make dc_msg_exists safe
This commit is contained in:
@@ -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_local_timestamp = ts + cnv_to_local;
|
||||||
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
||||||
if curr_day != last_day {
|
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;
|
last_day = curr_day;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ impl Default for Chattype {
|
|||||||
|
|
||||||
pub const DC_MSG_ID_MARKER1: usize = 1;
|
pub const DC_MSG_ID_MARKER1: usize = 1;
|
||||||
const DC_MSG_ID_DAYMARKER: usize = 9;
|
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()
|
/// approx. max. length returned by dc_msg_get_text()
|
||||||
const DC_MAX_GET_TEXT_LEN: usize = 30000;
|
const DC_MAX_GET_TEXT_LEN: usize = 30000;
|
||||||
|
|||||||
56
src/job.rs
56
src/job.rs
@@ -149,7 +149,7 @@ impl Job {
|
|||||||
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 */
|
||||||
if 0 != self.foreign_id {
|
if 0 != self.foreign_id {
|
||||||
if 0 == unsafe { dc_msg_exists(context, self.foreign_id) } {
|
if !dc_msg_exists(context, self.foreign_id) {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
0, "Message {} for job {} does not exist", self.foreign_id, self.job_id,
|
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) {
|
fn do_DC_JOB_MOVE_MSG(&mut self, context: &Context) {
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
|
|
||||||
if !inbox.is_connected() {
|
if !connect_to_inbox(context, &inbox) {
|
||||||
connect_to_inbox(context, &inbox);
|
self.try_again_later(Delay::Standard, None);
|
||||||
if !inbox.is_connected() {
|
return;
|
||||||
self.try_again_later(Delay::Standard, None);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
if context
|
if context
|
||||||
@@ -256,12 +253,9 @@ impl Job {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* if this is the last existing part of the message, we delete the message from the server */
|
/* if this is the last existing part of the message, we delete the message from the server */
|
||||||
if !inbox.is_connected() {
|
if !connect_to_inbox(context, &inbox) {
|
||||||
connect_to_inbox(context, &inbox);
|
self.try_again_later(Delay::Standard, None);
|
||||||
if !inbox.is_connected() {
|
return;
|
||||||
self.try_again_later(Delay::Standard, None);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let mid = unsafe { CStr::from_ptr(msg.rfc724_mid).to_str().unwrap() };
|
let mid = unsafe { 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();
|
||||||
@@ -281,12 +275,9 @@ impl Job {
|
|||||||
fn do_DC_JOB_MARKSEEN_MSG_ON_IMAP(&mut self, context: &Context) {
|
fn do_DC_JOB_MARKSEEN_MSG_ON_IMAP(&mut self, context: &Context) {
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
|
|
||||||
if !inbox.is_connected() {
|
if !connect_to_inbox(context, &inbox) {
|
||||||
connect_to_inbox(context, &inbox);
|
self.try_again_later(Delay::Standard, None);
|
||||||
if !inbox.is_connected() {
|
return;
|
||||||
self.try_again_later(Delay::Standard, None);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
let server_folder = msg.server_folder.as_ref().unwrap();
|
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||||
@@ -333,12 +324,9 @@ impl Job {
|
|||||||
let mut dest_uid = 0;
|
let mut dest_uid = 0;
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
|
|
||||||
if !inbox.is_connected() {
|
if !connect_to_inbox(context, &inbox) {
|
||||||
connect_to_inbox(context, &inbox);
|
self.try_again_later(Delay::Standard, None);
|
||||||
if !inbox.is_connected() {
|
return;
|
||||||
self.try_again_later(Delay::Standard, None);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match inbox.set_seen(context, &folder, uid) {
|
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 inbox = context.inbox.read().unwrap();
|
||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
if 0 == connect_to_inbox(context, &inbox) {
|
if !connect_to_inbox(context, &inbox) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if context
|
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 {
|
fn connect_to_inbox(context: &Context, inbox: &Imap) -> bool {
|
||||||
let ret_connected = dc_connect_to_configured_imap(context, inbox);
|
if inbox.is_connected() {
|
||||||
if 0 != ret_connected {
|
true
|
||||||
inbox.set_watch_folder("INBOX".into());
|
} 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) {
|
fn send_mdn(context: &Context, msg_id: uint32_t) {
|
||||||
|
|||||||
@@ -1033,25 +1033,22 @@ The value is also used for CC:-summaries */
|
|||||||
|
|
||||||
// Context functions to work with messages
|
// Context functions to work with messages
|
||||||
|
|
||||||
pub unsafe fn dc_msg_exists(context: &Context, msg_id: u32) -> libc::c_int {
|
pub fn dc_msg_exists(context: &Context, msg_id: u32) -> bool {
|
||||||
if msg_id <= 9 {
|
if msg_id > DC_MSG_ID_LAST_SPECIAL {
|
||||||
return 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,
|
||||||
|
);
|
||||||
|
|
||||||
let chat_id: Option<i32> = context.sql.query_row_col(
|
if let Some(chat_id) = chat_id {
|
||||||
context,
|
if chat_id != 3 {
|
||||||
"SELECT chat_id FROM msgs WHERE id=?;",
|
return true;
|
||||||
params![msg_id as i32],
|
}
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(chat_id) = chat_id {
|
|
||||||
if chat_id != 3 {
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_update_msg_move_state(
|
pub fn dc_update_msg_move_state(
|
||||||
|
|||||||
Reference in New Issue
Block a user