From 7fe8584db342f2d1d4ecd0919fbef03f3cf7d620 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 6 May 2019 11:09:54 +0200 Subject: [PATCH] implment set_seen --- src/dc_imap.rs | 104 +++++++++++++++++++++++++------------------------ src/dc_job.rs | 13 ++++--- 2 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/dc_imap.rs b/src/dc_imap.rs index 7ae3d6482..648f98805 100644 --- a/src/dc_imap.rs +++ b/src/dc_imap.rs @@ -1096,13 +1096,13 @@ impl dc_imap_t { cvar.notify_one(); } - pub fn mv( + pub fn mv, S2: AsRef>( &self, context: &dc_context_t, - folder: *const libc::c_char, - uid: uint32_t, - dest_folder: *const libc::c_char, - dest_uid: *mut uint32_t, + folder: S1, + uid: u32, + dest_folder: S2, + dest_uid: &mut u32, ) -> usize { unimplemented!() // let mut current_block: u64; @@ -1266,51 +1266,55 @@ impl dc_imap_t { } } - pub fn set_seen( - &self, - context: &dc_context_t, - folder: *const libc::c_char, - uid: uint32_t, - ) -> usize { - unimplemented!() - // let mut res: usize = DC_RETRY_LATER; - // if folder.is_null() || uid == 0 as libc::c_uint { - // res = DC_FAILED - // } else if !imap.etpan.is_null() { - // dc_log_info( - // context, - // 0, - // b"Marking message %s/%i as seen...\x00" as *const u8 as *const libc::c_char, - // folder, - // uid as libc::c_int, - // ); - // if select_folder(context, imap, folder) == 0 { - // dc_log_warning( - // context, - // 0, - // b"Cannot select folder %s for setting SEEN flag.\x00" as *const u8 - // as *const libc::c_char, - // folder, - // ); - // } else if add_flag(imap, uid, mailimap_flag_new_seen()) == 0 { - // dc_log_warning( - // context, - // 0, - // b"Cannot mark message as seen.\x00" as *const u8 as *const libc::c_char, - // ); - // } else { - // res = DC_SUCCESS - // } - // } - // return (if res as libc::c_uint == DC_RETRY_LATER as libc::c_int as libc::c_uint { - // (if 0 != imap.should_reconnect { - // DC_RETRY_LATER as libc::c_int - // } else { - // DC_FAILED as libc::c_int - // }) as libc::c_uint - // } else { - // res as libc::c_uint - // }) as usize; + pub fn set_seen>(&self, context: &dc_context_t, folder: S, uid: u32) -> usize { + let mut res = DC_RETRY_LATER; + + if uid == 0 { + res = DC_FAILED + } else if self.is_connected() { + let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); + + unsafe { + dc_log_info( + context, + 0, + b"Marking message %s/%i as seen...\x00" as *const u8 as *const libc::c_char, + folder_c.as_ptr(), + uid as libc::c_int, + ) + }; + if self.select_folder(context, Some(folder)) == 0 { + unsafe { + dc_log_warning( + context, + 0, + b"Cannot select folder %s for setting SEEN flag.\x00" as *const u8 + as *const libc::c_char, + folder_c.as_ptr(), + ) + }; + } else if self.add_flag(uid, "\\Seen") == 0 { + unsafe { + dc_log_warning( + context, + 0, + b"Cannot mark message as seen.\x00" as *const u8 as *const libc::c_char, + ) + }; + } else { + res = DC_SUCCESS + } + } + + if res == DC_RETRY_LATER { + if self.should_reconnect() { + DC_RETRY_LATER + } else { + DC_FAILED + } + } else { + res + } } pub fn set_mdnsent>(&self, context: &dc_context_t, folder: S, uid: u32) -> usize { diff --git a/src/dc_job.rs b/src/dc_job.rs index b8607135f..64445a36f 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -505,11 +505,13 @@ unsafe fn dc_job_do_DC_JOB_MOVE_MSG(mut context: &dc_context_t, mut job: *mut dc b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char, 0 as *const libc::c_char, ); + + let server_folder = CStr::from_ptr((*msg).server_folder).to_str().unwrap(); match inbox.mv( context, - (*msg).server_folder, + server_folder, (*msg).server_uid, - dest_folder, + CStr::from_ptr(dest_folder).to_str().unwrap(), &mut dest_uid, ) as libc::c_uint { @@ -589,6 +591,7 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context: &dc_context_t, job: *mu } match current_block { 11006700562992250127 => { + let folder = CStr::from_ptr(folder).to_str().unwrap(); if inbox.set_seen(context, folder, uid) as libc::c_uint == 0i32 as libc::c_uint { dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char); } @@ -608,6 +611,7 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context: &dc_context_t, job: *mu b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char, 0 as *const libc::c_char, ); + let dest_folder = CStr::from_ptr(dest_folder).to_str().unwrap(); match inbox.mv(context, folder, uid, dest_folder, &mut dest_uid) as libc::c_uint { 1 => { dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char); @@ -643,9 +647,8 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MSG_ON_IMAP( match current_block { 15240798224410183470 => { if !(0 == dc_msg_load_from_db(msg, context, (*job).foreign_id)) { - match inbox.set_seen(context, (*msg).server_folder, (*msg).server_uid) - as libc::c_uint - { + let server_folder = CStr::from_ptr((*msg).server_folder).to_str().unwrap(); + match inbox.set_seen(context, server_folder, (*msg).server_uid) as libc::c_uint { 0 => {} 1 => { current_block = 12392248546350854223;