last method in imap

This commit is contained in:
dignifiedquire
2019-05-06 13:46:31 +02:00
parent 7fe8584db3
commit 693c0e0fc0
2 changed files with 248 additions and 262 deletions

View File

@@ -250,6 +250,28 @@ impl Session {
Session::Insecure(i) => i.uid_store(uid_set, query), Session::Insecure(i) => i.uid_store(uid_set, query),
} }
} }
pub fn uid_mv<S1: AsRef<str>, S2: AsRef<str>>(
&mut self,
uid_set: S1,
mailbox_name: S2,
) -> imap::error::Result<()> {
match self {
Session::Secure(i) => i.uid_mv(uid_set, mailbox_name),
Session::Insecure(i) => i.uid_mv(uid_set, mailbox_name),
}
}
pub fn uid_copy<S1: AsRef<str>, S2: AsRef<str>>(
&mut self,
uid_set: S1,
mailbox_name: S2,
) -> imap::error::Result<()> {
match self {
Session::Secure(i) => i.uid_copy(uid_set, mailbox_name),
Session::Insecure(i) => i.uid_copy(uid_set, mailbox_name),
}
}
} }
pub struct ImapConfig { pub struct ImapConfig {
@@ -1104,147 +1126,129 @@ impl dc_imap_t {
dest_folder: S2, dest_folder: S2,
dest_uid: &mut u32, dest_uid: &mut u32,
) -> usize { ) -> usize {
unimplemented!() let mut res = DC_RETRY_LATER;
// let mut current_block: u64; let set = format!("{}", uid);
// let mut res: usize = DC_RETRY_LATER;
// let mut r: libc::c_int = 0; if uid == 0 {
// let mut set: *mut mailimap_set = mailimap_set_new_single(uid); res = DC_FAILED;
// let mut res_uid: uint32_t = 0 as uint32_t; } else if folder.as_ref() == dest_folder.as_ref() {
// let mut res_setsrc: *mut mailimap_set = 0 as *mut mailimap_set; unsafe {
// let mut res_setdest: *mut mailimap_set = 0 as *mut mailimap_set; dc_log_info(
// if folder.is_null() context,
// || uid == 0 as libc::c_uint 0,
// || dest_folder.is_null() b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8
// || dest_uid.is_null() as *const libc::c_char,
// || set.is_null() CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
// { uid as libc::c_int,
// res = DC_FAILED CString::new(dest_folder.as_ref().to_owned())
// } else if strcasecmp(folder, dest_folder) == 0 { .unwrap()
// dc_log_info( .as_ptr(),
// context, )
// 0, };
// b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8 res = DC_ALREADY_DONE;
// as *const libc::c_char, } else {
// folder, unsafe {
// uid as libc::c_int, dc_log_info(
// dest_folder, context,
// ); 0,
// res = DC_ALREADY_DONE b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char,
// } else { CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
// dc_log_info( uid as libc::c_int,
// context, CString::new(dest_folder.as_ref().to_owned())
// 0, .unwrap()
// b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char, .as_ptr(),
// folder, )
// uid as libc::c_int, };
// dest_folder, if self.select_folder(context, Some(folder.as_ref())) == 0 {
// ); unsafe {
// if select_folder(context, imap, folder) == 0 { dc_log_warning(
// dc_log_warning( context,
// context, 0,
// 0, b"Cannot select folder %s for moving message.\x00" as *const u8
// b"Cannot select folder %s for moving message.\x00" as *const u8 as *const libc::c_char,
// as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
// folder, )
// ); };
// } else { } else {
// r = mailimap_uidplus_uid_move( let moved = if let Some(ref mut session) = *self.session.lock().unwrap() {
// imap.etpan, match session.uid_mv(&set, &dest_folder) {
// set, Ok(_) => {
// dest_folder, res = DC_SUCCESS;
// &mut res_uid, true
// &mut res_setsrc, }
// &mut res_setdest, Err(err) => {
// ); eprintln!("move error: {:?}", err);
// if 0 != dc_imap_is_error(context, imap, r) { unsafe {
// if !res_setsrc.is_null() { dc_log_info(
// mailimap_set_free(res_setsrc); context,
// res_setsrc = 0 as *mut mailimap_set 0,
// } b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00"
// if !res_setdest.is_null() { as *const u8 as *const libc::c_char,
// mailimap_set_free(res_setdest); CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
// res_setdest = 0 as *mut mailimap_set uid as libc::c_int,
// } CString::new(dest_folder.as_ref().to_owned()).unwrap().as_ptr(),
// dc_log_info( )
// context, };
// 0, false
// b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" }
// as *const u8 as *const libc::c_char, }
// folder, } else {
// uid as libc::c_int, unreachable!();
// dest_folder, };
// );
// r = mailimap_uidplus_uid_copy( if !moved {
// imap.etpan, let copied = if let Some(ref mut session) = *self.session.lock().unwrap() {
// set, match session.uid_copy(&set, &dest_folder) {
// dest_folder, Ok(_) => true,
// &mut res_uid, Err(err) => {
// &mut res_setsrc, eprintln!("error copy: {:?}", err);
// &mut res_setdest, unsafe {
// ); dc_log_info(
// if 0 != dc_imap_is_error(context, imap, r) { context,
// dc_log_info( 0,
// context, b"Cannot copy message.\x00" as *const u8
// 0, as *const libc::c_char,
// b"Cannot copy message.\x00" as *const u8 as *const libc::c_char, )
// ); };
// current_block = 14415637129417834392; false
// } else { }
// if add_flag(imap, uid, mailimap_flag_new_deleted()) == 0 { }
// dc_log_warning( } else {
// context, unreachable!();
// 0, };
// b"Cannot mark message as \"Deleted\".\x00" as *const u8
// as *const libc::c_char, if copied {
// ); if self.add_flag(uid, "\\Deleted") == 0 {
// } unsafe {
// imap.selected_folder_needs_expunge = 1; dc_log_warning(
// current_block = 1538046216550696469; context,
// } 0,
// } else { b"Cannot mark message as \"Deleted\".\x00" as *const u8
// current_block = 1538046216550696469; as *const libc::c_char,
// } )
// match current_block { };
// 14415637129417834392 => {} }
// _ => { self.config.write().unwrap().selected_folder_needs_expunge = true;
// if !res_setdest.is_null() { res = DC_SUCCESS;
// let mut cur: *mut clistiter = (*(*res_setdest).set_list).first; }
// if !cur.is_null() { }
// let mut item: *mut mailimap_set_item = 0 as *mut mailimap_set_item; }
// item = (if !cur.is_null() { }
// (*cur).data
// } else { if res == DC_SUCCESS {
// 0 as *mut libc::c_void // TODO: is this correct?
// }) as *mut mailimap_set_item; *dest_uid = uid;
// *dest_uid = (*item).set_first }
// }
// } if res == DC_RETRY_LATER {
// res = DC_SUCCESS if self.should_reconnect() {
// } DC_RETRY_LATER
// } } else {
// } DC_FAILED
// } }
// if !set.is_null() { } else {
// mailimap_set_free(set); res
// set = 0 as *mut mailimap_set }
// }
// if !res_setsrc.is_null() {
// mailimap_set_free(res_setsrc);
// res_setsrc = 0 as *mut mailimap_set
// }
// if !res_setdest.is_null() {
// mailimap_set_free(res_setdest);
// res_setdest = 0 as *mut mailimap_set
// }
// 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;
} }
fn add_flag<S: AsRef<str>>(&self, server_uid: u32, flag: S) -> usize { fn add_flag<S: AsRef<str>>(&self, server_uid: u32, flag: S) -> usize {
@@ -1448,124 +1452,109 @@ impl dc_imap_t {
} }
// only returns 0 on connection problems; we should try later again in this case * // only returns 0 on connection problems; we should try later again in this case *
pub fn delete_msg( pub fn delete_msg<S1: AsRef<str>, S2: AsRef<str>>(
&self, &self,
context: &dc_context_t, context: &dc_context_t,
rfc724_mid: *const libc::c_char, message_id: S1,
folder: *const libc::c_char, folder: S2,
mut server_uid: uint32_t, server_uid: &mut u32,
) -> libc::c_int { ) -> usize {
unimplemented!() let mut success = false;
// let mut success: libc::c_int = 0; if *server_uid == 0 {
// let mut r: libc::c_int = 0; success = true
// let mut fetch_result: *mut clist = 0 as *mut clist; } else {
// let mut is_rfc724_mid: *mut libc::c_char = 0 as *mut libc::c_char; unsafe {
// let mut new_folder: *mut libc::c_char = 0 as *mut libc::c_char; dc_log_info(
// if rfc724_mid.is_null() context,
// || folder.is_null() 0,
// || *folder.offset(0isize) as libc::c_int == 0 b"Marking message \"%s\", %s/%i for deletion...\x00" as *const u8
// || server_uid == 0 as libc::c_uint as *const libc::c_char,
// { &message_id,
// success = 1 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
// } else { *server_uid as libc::c_int,
// dc_log_info( )
// context, };
// 0,
// b"Marking message \"%s\", %s/%i for deletion...\x00" as *const u8
// as *const libc::c_char,
// rfc724_mid,
// folder,
// server_uid as libc::c_int,
// );
// if select_folder(context, imap, folder) == 0 {
// dc_log_warning(
// context,
// 0,
// b"Cannot select folder %s for deleting message.\x00" as *const u8
// as *const libc::c_char,
// folder,
// );
// } else {
// let mut cur: *mut clistiter = 0 as *mut clistiter;
// let mut is_quoted_rfc724_mid: *const libc::c_char = 0 as *const libc::c_char;
// let mut set: *mut mailimap_set = mailimap_set_new_single(server_uid);
// r = mailimap_uid_fetch(
// imap.etpan,
// set,
// imap.fetch_type_prefetch,
// &mut fetch_result,
// );
// if !set.is_null() {
// mailimap_set_free(set);
// set = 0 as *mut mailimap_set
// }
// if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
// fetch_result = 0 as *mut clist;
// dc_log_warning(
// context,
// 0,
// b"Cannot delete on IMAP, %s/%i not found.\x00" as *const u8
// as *const libc::c_char,
// folder,
// server_uid as libc::c_int,
// );
// server_uid = 0 as uint32_t
// }
// cur = (*fetch_result).first;
// if cur.is_null()
// || {
// is_quoted_rfc724_mid = peek_rfc724_mid(
// (if !cur.is_null() {
// (*cur).data
// } else {
// 0 as *mut libc::c_void
// }) as *mut mailimap_msg_att,
// );
// is_quoted_rfc724_mid.is_null()
// }
// || {
// is_rfc724_mid = unquote_rfc724_mid(is_quoted_rfc724_mid);
// is_rfc724_mid.is_null()
// }
// || strcmp(is_rfc724_mid, rfc724_mid) != 0
// {
// dc_log_warning(
// context,
// 0,
// b"Cannot delete on IMAP, %s/%i does not match %s.\x00" as *const u8
// as *const libc::c_char,
// folder,
// server_uid as libc::c_int,
// rfc724_mid,
// );
// server_uid = 0 as uint32_t
// }
// /* mark the message for deletion */
// if add_flag(imap, server_uid, mailimap_flag_new_deleted()) == 0 {
// dc_log_warning(
// context,
// 0,
// b"Cannot mark message as \"Deleted\".\x00" as *const u8
// as *const libc::c_char,
// );
// } else {
// imap.selected_folder_needs_expunge = 1;
// success = 1
// }
// }
// }
// if !fetch_result.is_null() {
// mailimap_fetch_list_free(fetch_result);
// fetch_result = 0 as *mut clist
// }
// free(is_rfc724_mid as *mut libc::c_void);
// free(new_folder as *mut libc::c_void);
// if 0 != success { if self.select_folder(context, Some(&folder)) == 0 {
// 1 unsafe {
// } else { dc_log_warning(
// dc_imap_is_connected(imap) context,
// } 0,
b"Cannot select folder %s for deleting message.\x00" as *const u8
as *const libc::c_char,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
} else {
let set = format!("{}", server_uid);
if let Some(ref mut session) = *self.session.lock().unwrap() {
match session.uid_fetch(set, PREFETCH_FLAGS) {
Ok(msgs) => {
if msgs.is_empty()
|| msgs
.first()
.unwrap()
.envelope()
.expect("missing envelope")
.message_id
.expect("missing message id")
!= message_id.as_ref()
{
unsafe {
dc_log_warning(
context,
0,
b"Cannot delete on IMAP, %s/%i does not match %s.\x00"
as *const u8
as *const libc::c_char,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
*server_uid as libc::c_int,
message_id,
)
};
*server_uid = 0;
}
}
Err(err) => {
eprintln!("fetch error: {:?}", err);
unsafe {
dc_log_warning(
context,
0,
b"Cannot delete on IMAP, %s/%i not found.\x00" as *const u8
as *const libc::c_char,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
*server_uid as libc::c_int,
)
};
*server_uid = 0;
}
}
}
// mark the message for deletion
if self.add_flag(*server_uid, "\\Deleted") == 0 {
unsafe {
dc_log_warning(
context,
0,
b"Cannot mark message as \"Deleted\".\x00" as *const u8
as *const libc::c_char,
)
};
} else {
self.config.write().unwrap().selected_folder_needs_expunge = true;
success = true
}
}
}
if success {
1
} else {
self.is_connected() as usize
}
} }
pub fn configure_folders(&self, context: &dc_context_t, flags: libc::c_int) { pub fn configure_folders(&self, context: &dc_context_t, flags: libc::c_int) {

View File

@@ -991,12 +991,9 @@ unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(mut context: &dc_context_t, mut jo
match current_block { match current_block {
8913536887710889399 => {} 8913536887710889399 => {}
_ => { _ => {
if 0 == inbox.delete_msg( let mid = CStr::from_ptr((*msg).rfc724_mid).to_str().unwrap();
context, let server_folder = CStr::from_ptr((*msg).server_folder).to_str().unwrap();
(*msg).rfc724_mid, if 0 == inbox.delete_msg(context, mid, server_folder, &mut (*msg).server_uid) {
(*msg).server_folder,
(*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);
current_block = 8913536887710889399; current_block = 8913536887710889399;
} else { } else {