mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
more rfc724_mid cleanup
This commit is contained in:
@@ -362,7 +362,7 @@ impl Context {
|
||||
}
|
||||
|
||||
if self.is_mvbox(folder) {
|
||||
dc_update_msg_move_state(self, msg.rfc724_mid, MoveState::Stay);
|
||||
dc_update_msg_move_state(self, &msg.rfc724_mid, MoveState::Stay);
|
||||
}
|
||||
|
||||
// 1 = dc message, 2 = reply to dc message
|
||||
@@ -374,7 +374,7 @@ impl Context {
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
dc_update_msg_move_state(self, msg.rfc724_mid, MoveState::Moving);
|
||||
dc_update_msg_move_state(self, &msg.rfc724_mid, MoveState::Moving);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
|
||||
factory.loaded = DC_MF_MSG_LOADED;
|
||||
factory.timestamp = factory.msg.timestamp_sort;
|
||||
factory.rfc724_mid = as_str(factory.msg.rfc724_mid).to_string();
|
||||
factory.rfc724_mid = factory.msg.rfc724_mid.clone();
|
||||
factory.increation = dc_msg_is_increation(&factory.msg);
|
||||
|
||||
Ok(factory)
|
||||
@@ -950,7 +950,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
||||
version,
|
||||
as_str(factory.from_addr),
|
||||
as_str(factory.from_addr),
|
||||
as_str(factory.msg.rfc724_mid)
|
||||
factory.msg.rfc724_mid
|
||||
).strdup();
|
||||
|
||||
let content_type_0: *mut mailmime_content = mailmime_content_new_with_str(
|
||||
|
||||
@@ -361,14 +361,15 @@ unsafe fn add_parts(
|
||||
let mut old_server_folder = std::ptr::null_mut();
|
||||
let mut old_server_uid = 0;
|
||||
|
||||
let rfc724_mid_s = as_str(rfc724_mid);
|
||||
if 0 != dc_rfc724_mid_exists(
|
||||
context,
|
||||
rfc724_mid,
|
||||
&rfc724_mid_s,
|
||||
&mut old_server_folder,
|
||||
&mut old_server_uid,
|
||||
) {
|
||||
if as_str(old_server_folder) != server_folder.as_ref() || old_server_uid != server_uid {
|
||||
dc_update_server_uid(context, rfc724_mid, server_folder.as_ref(), server_uid);
|
||||
dc_update_server_uid(context, &rfc724_mid_s, server_folder.as_ref(), server_uid);
|
||||
}
|
||||
|
||||
free(old_server_folder.cast());
|
||||
@@ -867,7 +868,7 @@ unsafe fn handle_reports(
|
||||
if 0 != dc_mdn_from_ext(
|
||||
context,
|
||||
from_id,
|
||||
rfc724_mid_0,
|
||||
as_str(rfc724_mid_0),
|
||||
sent_timestamp,
|
||||
&mut chat_id_0,
|
||||
&mut msg_id,
|
||||
|
||||
23
src/imap.rs
23
src/imap.rs
@@ -1,4 +1,3 @@
|
||||
use std::ffi::CString;
|
||||
use std::net;
|
||||
use std::ptr;
|
||||
use std::sync::{
|
||||
@@ -10,7 +9,6 @@ use std::time::{Duration, SystemTime};
|
||||
use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_receive_imf::dc_receive_imf;
|
||||
use crate::dc_tools::CStringExt;
|
||||
use crate::dc_tools::*;
|
||||
use crate::events::Event;
|
||||
use crate::job::{job_add, Action};
|
||||
@@ -821,10 +819,7 @@ impl Imap {
|
||||
.message_id
|
||||
.expect("missing message id");
|
||||
|
||||
if 0 == unsafe {
|
||||
let message_id_c = CString::yolo(message_id);
|
||||
precheck_imf(context, message_id_c.as_ptr(), folder.as_ref(), cur_uid)
|
||||
} {
|
||||
if 0 == unsafe { precheck_imf(context, &message_id, folder.as_ref(), cur_uid) } {
|
||||
// check passed, go fetch the rest
|
||||
if self.fetch_single_msg(context, &folder, cur_uid) == 0 {
|
||||
info!(
|
||||
@@ -1645,7 +1640,7 @@ fn get_folder_meaning(folder_name: &imap::types::Name) -> FolderMeaning {
|
||||
|
||||
unsafe fn precheck_imf(
|
||||
context: &Context,
|
||||
rfc724_mid: *const libc::c_char,
|
||||
rfc724_mid: &str,
|
||||
server_folder: &str,
|
||||
server_uid: u32,
|
||||
) -> libc::c_int {
|
||||
@@ -1656,7 +1651,7 @@ unsafe fn precheck_imf(
|
||||
let mut mark_seen: libc::c_int = 0i32;
|
||||
msg_id = dc_rfc724_mid_exists(
|
||||
context,
|
||||
rfc724_mid,
|
||||
&rfc724_mid,
|
||||
&mut old_server_folder,
|
||||
&mut old_server_uid,
|
||||
);
|
||||
@@ -1665,18 +1660,14 @@ unsafe fn precheck_imf(
|
||||
if *old_server_folder.offset(0isize) as libc::c_int == 0i32
|
||||
&& old_server_uid == 0i32 as libc::c_uint
|
||||
{
|
||||
info!(context, "[move] detected bbc-self {}", as_str(rfc724_mid),);
|
||||
info!(context, "[move] detected bbc-self {}", rfc724_mid,);
|
||||
mark_seen = 1i32
|
||||
} else if as_str(old_server_folder) != server_folder {
|
||||
info!(
|
||||
context,
|
||||
"[move] detected moved message {}",
|
||||
as_str(rfc724_mid),
|
||||
);
|
||||
dc_update_msg_move_state(context, rfc724_mid, MoveState::Stay);
|
||||
info!(context, "[move] detected moved message {}", rfc724_mid,);
|
||||
dc_update_msg_move_state(context, &rfc724_mid, MoveState::Stay);
|
||||
}
|
||||
if as_str(old_server_folder) != server_folder || old_server_uid != server_uid {
|
||||
dc_update_server_uid(context, rfc724_mid, server_folder, server_uid);
|
||||
dc_update_server_uid(context, &rfc724_mid, server_folder, server_uid);
|
||||
}
|
||||
context.do_heuristics_moves(server_folder, msg_id);
|
||||
if 0 != mark_seen {
|
||||
|
||||
14
src/job.rs
14
src/job.rs
@@ -1,4 +1,3 @@
|
||||
use std::ffi::CStr;
|
||||
use std::ptr;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -253,7 +252,7 @@ impl Job {
|
||||
self.try_again_later(3i32, None);
|
||||
}
|
||||
3 => {
|
||||
dc_update_server_uid(context, msg.rfc724_mid, &dest_folder, dest_uid);
|
||||
dc_update_server_uid(context, &msg.rfc724_mid, &dest_folder, dest_uid);
|
||||
}
|
||||
0 | 2 | _ => {}
|
||||
}
|
||||
@@ -268,12 +267,10 @@ impl Job {
|
||||
let inbox = context.inbox.read().unwrap();
|
||||
|
||||
if let Ok(mut msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||
if !(msg.rfc724_mid.is_null()
|
||||
|| unsafe { *msg.rfc724_mid.offset(0isize) as libc::c_int == 0 })
|
||||
{
|
||||
if !msg.rfc724_mid.is_empty() {
|
||||
let ok_to_continue1;
|
||||
/* eg. device messages have no Message-ID */
|
||||
if dc_rfc724_mid_cnt(context, msg.rfc724_mid) != 1 {
|
||||
if dc_rfc724_mid_cnt(context, &msg.rfc724_mid) != 1 {
|
||||
info!(
|
||||
context,
|
||||
"The message is deleted from the server when all parts are deleted.",
|
||||
@@ -295,9 +292,10 @@ impl Job {
|
||||
ok_to_continue = true;
|
||||
}
|
||||
if ok_to_continue {
|
||||
let mid = unsafe { CStr::from_ptr(msg.rfc724_mid).to_str().unwrap() };
|
||||
let mid = msg.rfc724_mid;
|
||||
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)
|
||||
{
|
||||
self.try_again_later(-1i32, None);
|
||||
ok_to_continue1 = false;
|
||||
} else {
|
||||
|
||||
@@ -151,7 +151,7 @@ pub struct Message {
|
||||
pub timestamp_sent: i64,
|
||||
pub timestamp_rcvd: i64,
|
||||
pub text: Option<String>,
|
||||
pub rfc724_mid: *mut libc::c_char,
|
||||
pub rfc724_mid: String,
|
||||
pub in_reply_to: Option<String>,
|
||||
pub server_folder: Option<String>,
|
||||
pub server_uid: u32,
|
||||
@@ -292,8 +292,8 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
|
||||
if !rawtxt.is_empty() {
|
||||
ret += &format!("\n{}\n", rawtxt);
|
||||
}
|
||||
if !msg.rfc724_mid.is_null() && 0 != *msg.rfc724_mid.offset(0) as libc::c_int {
|
||||
ret += &format!("\nMessage-ID: {}", as_str(msg.rfc724_mid));
|
||||
if !msg.rfc724_mid.is_empty() {
|
||||
ret += &format!("\nMessage-ID: {}", msg.rfc724_mid);
|
||||
}
|
||||
if let Some(ref server_folder) = msg.server_folder {
|
||||
if server_folder != "" {
|
||||
@@ -322,7 +322,7 @@ pub fn dc_msg_new(viewtype: Viewtype) -> Message {
|
||||
timestamp_sent: 0,
|
||||
timestamp_rcvd: 0,
|
||||
text: None,
|
||||
rfc724_mid: std::ptr::null_mut(),
|
||||
rfc724_mid: String::default(),
|
||||
in_reply_to: None,
|
||||
server_folder: None,
|
||||
server_uid: 0,
|
||||
@@ -334,14 +334,6 @@ pub fn dc_msg_new(viewtype: Viewtype) -> Message {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Message {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
free(self.rfc724_mid.cast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_msg_get_filemime(msg: &Message) -> String {
|
||||
if let Some(m) = msg.param.get(Param::MimeType) {
|
||||
return m.to_string();
|
||||
@@ -438,7 +430,7 @@ pub fn dc_msg_load_from_db(context: &Context, id: u32) -> Result<Message, Error>
|
||||
unsafe {
|
||||
let mut msg = dc_msg_new_untyped();
|
||||
msg.id = row.get::<_, i32>(0)? as u32;
|
||||
msg.rfc724_mid = row.get::<_, String>(1)?.strdup();
|
||||
msg.rfc724_mid = row.get::<_, String>(1)?;
|
||||
msg.in_reply_to = row.get::<_, Option<String>>(2)?;
|
||||
msg.server_folder = row.get::<_, Option<String>>(3)?;
|
||||
msg.server_uid = row.get(4)?;
|
||||
@@ -996,18 +988,14 @@ pub fn dc_msg_exists(context: &Context, msg_id: u32) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_update_msg_move_state(
|
||||
context: &Context,
|
||||
rfc724_mid: *const libc::c_char,
|
||||
state: MoveState,
|
||||
) -> bool {
|
||||
pub fn dc_update_msg_move_state(context: &Context, rfc724_mid: &str, state: MoveState) -> bool {
|
||||
// we update the move_state for all messages belonging to a given Message-ID
|
||||
// so that the state stay intact when parts are deleted
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET move_state=? WHERE rfc724_mid=?;",
|
||||
params![state as i32, as_str(rfc724_mid)],
|
||||
params![state as i32, rfc724_mid],
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
@@ -1042,13 +1030,13 @@ pub fn dc_set_msg_failed(context: &Context, msg_id: u32, error: Option<impl AsRe
|
||||
pub unsafe fn dc_mdn_from_ext(
|
||||
context: &Context,
|
||||
from_id: u32,
|
||||
rfc724_mid: *const libc::c_char,
|
||||
rfc724_mid: &str,
|
||||
timestamp_sent: i64,
|
||||
ret_chat_id: *mut u32,
|
||||
ret_msg_id: *mut u32,
|
||||
) -> libc::c_int {
|
||||
if from_id <= 9
|
||||
|| rfc724_mid.is_null()
|
||||
|| rfc724_mid.is_empty()
|
||||
|| ret_chat_id.is_null()
|
||||
|| ret_msg_id.is_null()
|
||||
|| *ret_chat_id != 0
|
||||
@@ -1064,7 +1052,7 @@ pub unsafe fn dc_mdn_from_ext(
|
||||
LEFT JOIN chats c ON m.chat_id=c.id \
|
||||
WHERE rfc724_mid=? AND from_id=1 \
|
||||
ORDER BY m.id;",
|
||||
params![as_str(rfc724_mid)],
|
||||
params![rfc724_mid],
|
||||
|row| {
|
||||
Ok((
|
||||
row.get::<_, i32>(0)?,
|
||||
@@ -1168,11 +1156,11 @@ pub fn dc_get_deaddrop_msg_cnt(context: &Context) -> libc::size_t {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_rfc724_mid_cnt(context: &Context, rfc724_mid: *const libc::c_char) -> libc::c_int {
|
||||
pub fn dc_rfc724_mid_cnt(context: &Context, rfc724_mid: &str) -> libc::c_int {
|
||||
/* check the number of messages with the same rfc724_mid */
|
||||
match context.sql.query_row(
|
||||
"SELECT COUNT(*) FROM msgs WHERE rfc724_mid=?;",
|
||||
&[as_str(rfc724_mid)],
|
||||
&[rfc724_mid],
|
||||
|row| row.get(0),
|
||||
) {
|
||||
Ok(res) => res,
|
||||
@@ -1185,16 +1173,16 @@ pub fn dc_rfc724_mid_cnt(context: &Context, rfc724_mid: *const libc::c_char) ->
|
||||
|
||||
pub fn dc_rfc724_mid_exists(
|
||||
context: &Context,
|
||||
rfc724_mid: *const libc::c_char,
|
||||
rfc724_mid: &str,
|
||||
ret_server_folder: *mut *mut libc::c_char,
|
||||
ret_server_uid: *mut u32,
|
||||
) -> u32 {
|
||||
if rfc724_mid.is_null() || unsafe { *rfc724_mid.offset(0) as libc::c_int } == 0 {
|
||||
if rfc724_mid.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
match context.sql.query_row(
|
||||
"SELECT server_folder, server_uid, id FROM msgs WHERE rfc724_mid=?",
|
||||
&[as_str(rfc724_mid)],
|
||||
&[rfc724_mid],
|
||||
|row| {
|
||||
if !ret_server_folder.is_null() {
|
||||
unsafe { *ret_server_folder = row.get::<_, String>(0)?.strdup() };
|
||||
@@ -1221,13 +1209,13 @@ pub fn dc_rfc724_mid_exists(
|
||||
|
||||
pub fn dc_update_server_uid(
|
||||
context: &Context,
|
||||
rfc724_mid: *const libc::c_char,
|
||||
rfc724_mid: &str,
|
||||
server_folder: impl AsRef<str>,
|
||||
server_uid: u32,
|
||||
) {
|
||||
match context.sql.execute(
|
||||
"UPDATE msgs SET server_folder=?, server_uid=? WHERE rfc724_mid=?;",
|
||||
params![server_folder.as_ref(), server_uid, as_str(rfc724_mid)],
|
||||
params![server_folder.as_ref(), server_uid, rfc724_mid],
|
||||
) {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
|
||||
Reference in New Issue
Block a user