diff --git a/src/dc_imap.rs b/src/dc_imap.rs index 39a69e6ec..b1883f672 100644 --- a/src/dc_imap.rs +++ b/src/dc_imap.rs @@ -11,7 +11,8 @@ use crate::dc_loginparam::*; use crate::dc_sqlite3::*; use crate::dc_tools::*; use crate::types::*; -use crate::x::*; + +pub const DC_IMAP_SEEN: usize = 0x0001; #[repr(C)] pub struct dc_imap_t { @@ -213,9 +214,9 @@ impl Default for ImapConfig { skip_log_capabilities: 0, }; - // prefetch: UID, Envelope, - // new: body, body_peek_section - // flags: flags + // prefetch: UID, ENVELOPE, + // new: FLAGS BODY.PEEK[] + // flags: FLAGS cfg } @@ -562,41 +563,13 @@ impl dc_imap_t { return 0; } - if let Some(ref mut session) = *self.session.lock().unwrap() { + let list = if let Some(ref mut session) = *self.session.lock().unwrap() { // `FETCH (UID)` let set = format!("{}", mailbox.exists); let query = "(UID ENVELOPE)"; println!("fetching: {} {}", set, query); match session.fetch(set, query) { - Ok(list) => { - println!("fetched {} messages", list.len()); - - last_seen_uid = list[0].uid.unwrap_or_else(|| 0); - - // if the UIDVALIDITY has _changed_, decrease lastseenuid by one to avoid gaps (well add 1 below - if uid_validity > 0 && last_seen_uid > 1 { - last_seen_uid -= 1; - } - - uid_validity = mailbox.uid_validity.unwrap(); - self.set_config_last_seen_uid( - context, - &folder, - uid_validity, - last_seen_uid, - ); - unsafe { - dc_log_info( - context, - 0, - b"lastseenuid initialized to %i for %s@%i\x00" as *const u8 - as *const libc::c_char, - last_seen_uid as libc::c_int, - CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), - uid_validity as libc::c_int, - ); - } - } + Ok(list) => list, Err(err) => { eprintln!("fetch error: {:?}", err); unsafe { @@ -611,6 +584,30 @@ impl dc_imap_t { return 0; } } + } else { + return 0; + }; + println!("fetched {} messages", list.len()); + + last_seen_uid = list[0].uid.unwrap_or_else(|| 0); + + // if the UIDVALIDITY has _changed_, decrease lastseenuid by one to avoid gaps (well add 1 below + if uid_validity > 0 && last_seen_uid > 1 { + last_seen_uid -= 1; + } + + uid_validity = mailbox.uid_validity.unwrap(); + self.set_config_last_seen_uid(context, &folder, uid_validity, last_seen_uid); + unsafe { + dc_log_info( + context, + 0, + b"lastseenuid initialized to %i for %s@%i\x00" as *const u8 + as *const libc::c_char, + last_seen_uid as libc::c_int, + CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), + uid_validity as libc::c_int, + ); } } @@ -618,74 +615,72 @@ impl dc_imap_t { let mut read_errors = 0; let mut new_last_seen_uid = 0; - if let Some(ref mut session) = *self.session.lock().unwrap() { + let list = if let Some(ref mut session) = *self.session.lock().unwrap() { // fetch messages with larger UID than the last one seen // (`UID FETCH lastseenuid+1:*)`, see RFC 4549 let set = format!("{}:*", last_seen_uid + 1); let query = "(UID ENVELOPE)"; println!("fetching: {} {}", set, query); - let list = match session.uid_fetch(set, query) { + match session.uid_fetch(set, query) { Ok(list) => list, Err(err) => { eprintln!("fetch err: {:?}", err); return 0; } - }; - println!("fetched {} messages", list.len()); - // go through all mails in folder (this is typically _fast_ as we already have the whole list) + } + } else { + return 0; + }; - for msg in &list { - let cur_uid = msg.uid.unwrap_or_else(|| 0); - if cur_uid > last_seen_uid { - read_cnt += 1; + println!("fetched {} messages", list.len()); + // go through all mails in folder (this is typically _fast_ as we already have the whole list) - let message_id = msg - .envelope() - .expect("missing envelope") - .message_id - .expect("missing message id"); + for msg in &list { + let cur_uid = msg.uid.unwrap_or_else(|| 0); + if cur_uid > last_seen_uid { + read_cnt += 1; - let message_id_c = CString::new(message_id).unwrap(); - let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); - if 0 == unsafe { - (self.precheck_imf)( - context, - message_id_c.as_ptr(), - folder_c.as_ptr(), - cur_uid, - ) - } { - // check passed, go fetch the rest - if self.fetch_single_msg(context, &folder, cur_uid) == 0 { - unsafe { - dc_log_info( - context, - 0, - b"Read error for message %s from \"%s\", trying over later.\x00" - as *const u8 - as *const libc::c_char, - message_id_c.as_ptr(), - folder_c.as_ptr(), - ) - }; - read_errors += 1; - } - } else { - // check failed + let message_id = msg + .envelope() + .expect("missing envelope") + .message_id + .expect("missing message id"); + + let message_id_c = CString::new(message_id).unwrap(); + let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); + if 0 == unsafe { + (self.precheck_imf)(context, message_id_c.as_ptr(), folder_c.as_ptr(), cur_uid) + } { + // check passed, go fetch the rest + if self.fetch_single_msg(context, &folder, cur_uid) == 0 { unsafe { dc_log_info( context, 0, - b"Skipping message %s from \"%s\" by precheck.\x00" as *const u8 + b"Read error for message %s from \"%s\", trying over later.\x00" + as *const u8 as *const libc::c_char, message_id_c.as_ptr(), folder_c.as_ptr(), ) }; + read_errors += 1; } - if cur_uid > new_last_seen_uid { - new_last_seen_uid = cur_uid - } + } else { + // check failed + unsafe { + dc_log_info( + context, + 0, + b"Skipping message %s from \"%s\" by precheck.\x00" as *const u8 + as *const libc::c_char, + message_id_c.as_ptr(), + folder_c.as_ptr(), + ) + }; + } + if cur_uid > new_last_seen_uid { + new_last_seen_uid = cur_uid } } } @@ -748,266 +743,271 @@ impl dc_imap_t { folder: S, server_uid: u32, ) -> usize { - unimplemented!(); - } - // let mut msg_att: *mut mailimap_msg_att = 0 as *mut mailimap_msg_att; - // /* the function returns: - // 0 the caller should try over again later - // or 1 if the messages should be treated as received, the caller should not try to read the message again (even if no database entries are returned) */ - // let mut msg_content: *mut libc::c_char = 0 as *mut libc::c_char; - // let mut msg_bytes: size_t = 0 as size_t; - // let mut r: libc::c_int = 0; - // let mut retry_later: libc::c_int = 0; - // let mut deleted: libc::c_int = 0; - // let mut flags: uint32_t = 0 as uint32_t; - // let mut fetch_result: *mut clist = 0 as *mut clist; - // let mut cur: *mut clistiter = 0 as *mut clistiter; - // if !imap.etpan.is_null() { - // let mut set: *mut mailimap_set = mailimap_set_new_single(server_uid); - // r = mailimap_uid_fetch(imap.etpan, set, imap.fetch_type_body, &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"Error #%i on fetching message #%i from folder \"%s\"; retry=%i.\x00" - // as *const u8 as *const libc::c_char, - // r as libc::c_int, - // server_uid as libc::c_int, - // folder, - // imap.should_reconnect as libc::c_int, - // ); - // if 0 != imap.should_reconnect { - // retry_later = 1 - // } - // } else { - // /* this is an error that should be recovered; the caller should try over later to fetch the message again (if there is no such message, we simply get an empty result) */ - // cur = (*fetch_result).first; - // if cur.is_null() { - // dc_log_warning( - // context, - // 0, - // b"Message #%i does not exist in folder \"%s\".\x00" as *const u8 - // as *const libc::c_char, - // server_uid as libc::c_int, - // folder, - // ); - // } else { - // /* server response is fine, however, there is no such message, do not try to fetch the message again */ - // msg_att = (if !cur.is_null() { - // (*cur).data - // } else { - // 0 as *mut libc::c_void - // }) as *mut mailimap_msg_att; - // peek_body( - // msg_att, - // &mut msg_content, - // &mut msg_bytes, - // &mut flags, - // &mut deleted, - // ); - // if !(msg_content.is_null() || msg_bytes <= 0 || 0 != deleted) { - // /* dc_log_warning(imap->context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */ - // imap.receive_imf.expect("non-null function pointer")( - // context, - // msg_content, - // msg_bytes, - // folder, - // server_uid, - // flags, - // ); - // } - // } - // } - // } + // /* the function returns: + // 0 the caller should try over again later + // or 1 if the messages should be treated as received, the caller should not try to read the message again (even if no database entries are returned) */ + if !self.is_connected() { + return 0; + } - // if !fetch_result.is_null() { - // mailimap_fetch_list_free(fetch_result); - // fetch_result = 0 as *mut clist - // } - // if 0 != retry_later { - // 0 - // } else { - // 1 - // } - // } + let mut retry_later = false; + + let msgs = if let Some(ref mut session) = *self.session.lock().unwrap() { + let set = format!("{}", server_uid); + let query = "(FLAGS BODY.PEEK[])"; + match session.uid_fetch(set, query) { + Ok(msgs) => msgs, + Err(err) => { + eprintln!("error fetch single: {:?}", err); + unsafe { + dc_log_warning( + context, + 0, + b"Error on fetching message #%i from folder \"%s\"; retry=%i.\x00" + as *const u8 as *const libc::c_char, + server_uid as libc::c_int, + CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), + self.should_reconnect() as libc::c_int, + ) + }; + + if self.should_reconnect() { + retry_later = true; + } + + return if retry_later { 0 } else { 1 }; + } + } + } else { + return if retry_later { 0 } else { 1 }; + }; + + if msgs.is_empty() { + unsafe { + dc_log_warning( + context, + 0, + b"Message #%i does not exist in folder \"%s\".\x00" as *const u8 + as *const libc::c_char, + server_uid as libc::c_int, + CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), + ) + }; + } else { + let msg = &msgs[0]; + + let is_deleted = msg + .flags() + .iter() + .find(|flag| match flag { + imap::types::Flag::Deleted => true, + _ => false, + }) + .is_some(); + let is_seen = msg + .flags() + .iter() + .find(|flag| match flag { + imap::types::Flag::Seen => true, + _ => false, + }) + .is_some(); + + let flags = if is_seen { DC_IMAP_SEEN } else { 0 }; + + if !is_deleted && msg.body().is_some() { + unsafe { + let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); + (self.receive_imf)( + context, + msg.body().unwrap().as_ptr() as *const libc::c_char, + msg.body().unwrap().len(), + folder_c.as_ptr(), + server_uid, + flags as u32, + ); + } + } + } + + if retry_later { + 0 + } else { + 1 + } + } pub fn idle(&self, context: &dc_context_t) { // unimplemented!() println!("starting to idle"); + // let mut current_block: u64; + // let mut r: libc::c_int = 0; + // let mut r2: libc::c_int = 0; + // if 0 != imap.can_idle { + // setup_handle_if_needed(context, imap); + // if imap.idle_set_up == 0 + // && !imap.etpan.is_null() + // && !(*imap.etpan).imap_stream.is_null() + // { + // r = mailstream_setup_idle((*imap.etpan).imap_stream); + // if 0 != dc_imap_is_error(context, imap, r) { + // dc_log_warning( + // context, + // 0, + // b"IMAP-IDLE: Cannot setup.\x00" as *const u8 as *const libc::c_char, + // ); + // fake_idle(context, imap); + // current_block = 14832935472441733737; + // } else { + // imap.idle_set_up = 1; + // current_block = 17965632435239708295; + // } + // } else { + // current_block = 17965632435239708295; + // } + // match current_block { + // 14832935472441733737 => {} + // _ => { + // if 0 == imap.idle_set_up || 0 == select_folder(context, imap, imap.watch_folder) + // { + // dc_log_warning( + // context, + // 0, + // b"IMAP-IDLE not setup.\x00" as *const u8 as *const libc::c_char, + // ); + // fake_idle(context, imap); + // } else { + // r = mailimap_idle(imap.etpan); + // if 0 != dc_imap_is_error(context, imap, r) { + // dc_log_warning( + // context, + // 0, + // b"IMAP-IDLE: Cannot start.\x00" as *const u8 as *const libc::c_char, + // ); + // fake_idle(context, imap); + // } else { + // r = mailstream_wait_idle((*imap.etpan).imap_stream, 23 * 60); + // r2 = mailimap_idle_done(imap.etpan); + // if r == MAILSTREAM_IDLE_ERROR as libc::c_int + // || r == MAILSTREAM_IDLE_CANCELLED as libc::c_int + // { + // dc_log_info( + // context, + // 0, + // b"IMAP-IDLE wait cancelled, r=%i, r2=%i; we\'ll reconnect soon.\x00" + // as *const u8 + // as *const libc::c_char, + // r, + // r2, + // ); + // imap.should_reconnect = 1 + // } else if r == MAILSTREAM_IDLE_INTERRUPTED as libc::c_int { + // dc_log_info( + // context, + // 0, + // b"IMAP-IDLE interrupted.\x00" as *const u8 + // as *const libc::c_char, + // ); + // } else if r == MAILSTREAM_IDLE_HASDATA as libc::c_int { + // dc_log_info( + // context, + // 0, + // b"IMAP-IDLE has data.\x00" as *const u8 as *const libc::c_char, + // ); + // } else if r == MAILSTREAM_IDLE_TIMEOUT as libc::c_int { + // dc_log_info( + // context, + // 0, + // b"IMAP-IDLE timeout.\x00" as *const u8 as *const libc::c_char, + // ); + // } else { + // dc_log_warning( + // context, + // 0, + // b"IMAP-IDLE returns unknown value r=%i, r2=%i.\x00" as *const u8 + // as *const libc::c_char, + // r, + // r2, + // ); + // } + // } + // } + // } + // } + // } else { + // fake_idle(context, imap); + // } + // } } - // let mut current_block: u64; - // let mut r: libc::c_int = 0; - // let mut r2: libc::c_int = 0; - // if 0 != imap.can_idle { - // setup_handle_if_needed(context, imap); - // if imap.idle_set_up == 0 - // && !imap.etpan.is_null() - // && !(*imap.etpan).imap_stream.is_null() - // { - // r = mailstream_setup_idle((*imap.etpan).imap_stream); - // if 0 != dc_imap_is_error(context, imap, r) { - // dc_log_warning( - // context, - // 0, - // b"IMAP-IDLE: Cannot setup.\x00" as *const u8 as *const libc::c_char, - // ); - // fake_idle(context, imap); - // current_block = 14832935472441733737; - // } else { - // imap.idle_set_up = 1; - // current_block = 17965632435239708295; - // } - // } else { - // current_block = 17965632435239708295; - // } - // match current_block { - // 14832935472441733737 => {} - // _ => { - // if 0 == imap.idle_set_up || 0 == select_folder(context, imap, imap.watch_folder) - // { - // dc_log_warning( - // context, - // 0, - // b"IMAP-IDLE not setup.\x00" as *const u8 as *const libc::c_char, - // ); - // fake_idle(context, imap); - // } else { - // r = mailimap_idle(imap.etpan); - // if 0 != dc_imap_is_error(context, imap, r) { - // dc_log_warning( - // context, - // 0, - // b"IMAP-IDLE: Cannot start.\x00" as *const u8 as *const libc::c_char, - // ); - // fake_idle(context, imap); - // } else { - // r = mailstream_wait_idle((*imap.etpan).imap_stream, 23 * 60); - // r2 = mailimap_idle_done(imap.etpan); - // if r == MAILSTREAM_IDLE_ERROR as libc::c_int - // || r == MAILSTREAM_IDLE_CANCELLED as libc::c_int - // { - // dc_log_info( - // context, - // 0, - // b"IMAP-IDLE wait cancelled, r=%i, r2=%i; we\'ll reconnect soon.\x00" - // as *const u8 - // as *const libc::c_char, - // r, - // r2, - // ); - // imap.should_reconnect = 1 - // } else if r == MAILSTREAM_IDLE_INTERRUPTED as libc::c_int { - // dc_log_info( - // context, - // 0, - // b"IMAP-IDLE interrupted.\x00" as *const u8 - // as *const libc::c_char, - // ); - // } else if r == MAILSTREAM_IDLE_HASDATA as libc::c_int { - // dc_log_info( - // context, - // 0, - // b"IMAP-IDLE has data.\x00" as *const u8 as *const libc::c_char, - // ); - // } else if r == MAILSTREAM_IDLE_TIMEOUT as libc::c_int { - // dc_log_info( - // context, - // 0, - // b"IMAP-IDLE timeout.\x00" as *const u8 as *const libc::c_char, - // ); - // } else { - // dc_log_warning( - // context, - // 0, - // b"IMAP-IDLE returns unknown value r=%i, r2=%i.\x00" as *const u8 - // as *const libc::c_char, - // r, - // r2, - // ); - // } - // } - // } - // } - // } - // } else { - // fake_idle(context, imap); - // } - // } fn fake_idle(&self, context: &dc_context_t) { unimplemented!(); + // /* Idle using timeouts. This is also needed if we're not yet configured - + // in this case, we're waiting for a configure job */ + // let mut fake_idle_start_time = SystemTime::now(); + + // dc_log_info( + // context, + // 0, + // b"IMAP-fake-IDLEing...\x00" as *const u8 as *const libc::c_char, + // ); + // let mut do_fake_idle: libc::c_int = 1; + // while 0 != do_fake_idle { + // let seconds_to_wait = + // if fake_idle_start_time.elapsed().unwrap() < Duration::new(3 * 60, 0) { + // Duration::new(5, 0) + // } else { + // Duration::new(60, 0) + // }; + + // let &(ref lock, ref cvar) = &*imap.watch.clone(); + + // let mut watch = lock.lock().unwrap(); + + // loop { + // let res = cvar.wait_timeout(watch, seconds_to_wait).unwrap(); + // watch = res.0; + // if *watch { + // do_fake_idle = 0; + // } + // if *watch || res.1.timed_out() { + // break; + // } + // } + + // *watch = false; + // if do_fake_idle == 0 { + // return; + // } + // if 0 != setup_handle_if_needed(context, imap) { + // if 0 != fetch_from_single_folder(context, imap, imap.watch_folder) { + // do_fake_idle = 0; + // } + // } + // } + // } } - // /* Idle using timeouts. This is also needed if we're not yet configured - - // in this case, we're waiting for a configure job */ - // let mut fake_idle_start_time = SystemTime::now(); - - // dc_log_info( - // context, - // 0, - // b"IMAP-fake-IDLEing...\x00" as *const u8 as *const libc::c_char, - // ); - // let mut do_fake_idle: libc::c_int = 1; - // while 0 != do_fake_idle { - // let seconds_to_wait = - // if fake_idle_start_time.elapsed().unwrap() < Duration::new(3 * 60, 0) { - // Duration::new(5, 0) - // } else { - // Duration::new(60, 0) - // }; - - // let &(ref lock, ref cvar) = &*imap.watch.clone(); - - // let mut watch = lock.lock().unwrap(); - - // loop { - // let res = cvar.wait_timeout(watch, seconds_to_wait).unwrap(); - // watch = res.0; - // if *watch { - // do_fake_idle = 0; - // } - // if *watch || res.1.timed_out() { - // break; - // } - // } - - // *watch = false; - // if do_fake_idle == 0 { - // return; - // } - // if 0 != setup_handle_if_needed(context, imap) { - // if 0 != fetch_from_single_folder(context, imap, imap.watch_folder) { - // do_fake_idle = 0; - // } - // } - // } - // } pub fn interrupt_idle(&self) { // unimplemented!(); println!("interrupt idle"); + + // println!("imap interrupt"); + // if 0 != imap.can_idle { + // if !imap.etpan.is_null() && !(*imap.etpan).imap_stream.is_null() { + // mailstream_interrupt_idle((*imap.etpan).imap_stream); + // } + // } + + // println!("waiting for lock"); + // let &(ref lock, ref cvar) = &*imap.watch.clone(); + // let mut watch = lock.lock().unwrap(); + + // *watch = true; + // println!("notify"); + // cvar.notify_one(); } - // println!("imap interrupt"); - // if 0 != imap.can_idle { - // if !imap.etpan.is_null() && !(*imap.etpan).imap_stream.is_null() { - // mailstream_interrupt_idle((*imap.etpan).imap_stream); - // } - // } - - // println!("waiting for lock"); - // let &(ref lock, ref cvar) = &*imap.watch.clone(); - // let mut watch = lock.lock().unwrap(); - - // *watch = true; - // println!("notify"); - // cvar.notify_one(); - // } - pub fn mv( &self, context: &dc_context_t, @@ -1017,174 +1017,172 @@ impl dc_imap_t { dest_uid: *mut uint32_t, ) -> dc_imap_res { unimplemented!() + // let mut current_block: u64; + // let mut res: dc_imap_res = DC_RETRY_LATER; + // let mut r: libc::c_int = 0; + // let mut set: *mut mailimap_set = mailimap_set_new_single(uid); + // let mut res_uid: uint32_t = 0 as uint32_t; + // let mut res_setsrc: *mut mailimap_set = 0 as *mut mailimap_set; + // let mut res_setdest: *mut mailimap_set = 0 as *mut mailimap_set; + // if folder.is_null() + // || uid == 0 as libc::c_uint + // || dest_folder.is_null() + // || dest_uid.is_null() + // || set.is_null() + // { + // res = DC_FAILED + // } else if strcasecmp(folder, dest_folder) == 0 { + // dc_log_info( + // context, + // 0, + // b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8 + // as *const libc::c_char, + // folder, + // uid as libc::c_int, + // dest_folder, + // ); + // res = DC_ALREADY_DONE + // } else { + // dc_log_info( + // context, + // 0, + // b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char, + // folder, + // uid as libc::c_int, + // dest_folder, + // ); + // if select_folder(context, imap, folder) == 0 { + // dc_log_warning( + // context, + // 0, + // b"Cannot select folder %s for moving message.\x00" as *const u8 + // as *const libc::c_char, + // folder, + // ); + // } else { + // r = mailimap_uidplus_uid_move( + // imap.etpan, + // set, + // dest_folder, + // &mut res_uid, + // &mut res_setsrc, + // &mut res_setdest, + // ); + // if 0 != dc_imap_is_error(context, imap, r) { + // 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 + // } + // dc_log_info( + // context, + // 0, + // b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" + // as *const u8 as *const libc::c_char, + // folder, + // uid as libc::c_int, + // dest_folder, + // ); + // r = mailimap_uidplus_uid_copy( + // imap.etpan, + // set, + // dest_folder, + // &mut res_uid, + // &mut res_setsrc, + // &mut res_setdest, + // ); + // if 0 != dc_imap_is_error(context, imap, r) { + // dc_log_info( + // context, + // 0, + // b"Cannot copy message.\x00" as *const u8 as *const libc::c_char, + // ); + // current_block = 14415637129417834392; + // } else { + // if add_flag(imap, 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, + // ); + // } + // imap.selected_folder_needs_expunge = 1; + // current_block = 1538046216550696469; + // } + // } else { + // current_block = 1538046216550696469; + // } + // match current_block { + // 14415637129417834392 => {} + // _ => { + // if !res_setdest.is_null() { + // 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 { + // 0 as *mut libc::c_void + // }) as *mut mailimap_set_item; + // *dest_uid = (*item).set_first + // } + // } + // res = DC_SUCCESS + // } + // } + // } + // } + // if !set.is_null() { + // mailimap_set_free(set); + // 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 dc_imap_res; } - // let mut current_block: u64; - // let mut res: dc_imap_res = DC_RETRY_LATER; - // let mut r: libc::c_int = 0; - // let mut set: *mut mailimap_set = mailimap_set_new_single(uid); - // let mut res_uid: uint32_t = 0 as uint32_t; - // let mut res_setsrc: *mut mailimap_set = 0 as *mut mailimap_set; - // let mut res_setdest: *mut mailimap_set = 0 as *mut mailimap_set; - // if folder.is_null() - // || uid == 0 as libc::c_uint - // || dest_folder.is_null() - // || dest_uid.is_null() - // || set.is_null() - // { - // res = DC_FAILED - // } else if strcasecmp(folder, dest_folder) == 0 { - // dc_log_info( - // context, - // 0, - // b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8 - // as *const libc::c_char, - // folder, - // uid as libc::c_int, - // dest_folder, - // ); - // res = DC_ALREADY_DONE - // } else { - // dc_log_info( - // context, - // 0, - // b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char, - // folder, - // uid as libc::c_int, - // dest_folder, - // ); - // if select_folder(context, imap, folder) == 0 { - // dc_log_warning( - // context, - // 0, - // b"Cannot select folder %s for moving message.\x00" as *const u8 - // as *const libc::c_char, - // folder, - // ); - // } else { - // r = mailimap_uidplus_uid_move( - // imap.etpan, - // set, - // dest_folder, - // &mut res_uid, - // &mut res_setsrc, - // &mut res_setdest, - // ); - // if 0 != dc_imap_is_error(context, imap, r) { - // 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 - // } - // dc_log_info( - // context, - // 0, - // b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" - // as *const u8 as *const libc::c_char, - // folder, - // uid as libc::c_int, - // dest_folder, - // ); - // r = mailimap_uidplus_uid_copy( - // imap.etpan, - // set, - // dest_folder, - // &mut res_uid, - // &mut res_setsrc, - // &mut res_setdest, - // ); - // if 0 != dc_imap_is_error(context, imap, r) { - // dc_log_info( - // context, - // 0, - // b"Cannot copy message.\x00" as *const u8 as *const libc::c_char, - // ); - // current_block = 14415637129417834392; - // } else { - // if add_flag(imap, 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, - // ); - // } - // imap.selected_folder_needs_expunge = 1; - // current_block = 1538046216550696469; - // } - // } else { - // current_block = 1538046216550696469; - // } - // match current_block { - // 14415637129417834392 => {} - // _ => { - // if !res_setdest.is_null() { - // 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 { - // 0 as *mut libc::c_void - // }) as *mut mailimap_set_item; - // *dest_uid = (*item).set_first - // } - // } - // res = DC_SUCCESS - // } - // } - // } - // } - // if !set.is_null() { - // mailimap_set_free(set); - // 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 dc_imap_res; - // } fn add_flag(&self, server_uid: uint32_t, flag: *mut mailimap_flag) -> usize { unimplemented!() + // let mut flag_list: *mut mailimap_flag_list = 0 as *mut mailimap_flag_list; + // let mut store_att_flags: *mut mailimap_store_att_flags = 0 as *mut mailimap_store_att_flags; + // let mut set: *mut mailimap_set = mailimap_set_new_single(server_uid); + // if !(imap.etpan.is_null()) { + // flag_list = mailimap_flag_list_new_empty(); + // mailimap_flag_list_add(flag_list, flag); + // store_att_flags = mailimap_store_att_flags_new_add_flags(flag_list); + // mailimap_uid_store(imap.etpan, set, store_att_flags); + // } + // if !store_att_flags.is_null() { + // mailimap_store_att_flags_free(store_att_flags); + // } + // if !set.is_null() { + // mailimap_set_free(set); + // set = 0 as *mut mailimap_set + // } + // if 0 != imap.should_reconnect { + // 0 + // } else { + // 1 + // } } - // let mut flag_list: *mut mailimap_flag_list = 0 as *mut mailimap_flag_list; - // let mut store_att_flags: *mut mailimap_store_att_flags = 0 as *mut mailimap_store_att_flags; - // let mut set: *mut mailimap_set = mailimap_set_new_single(server_uid); - // if !(imap.etpan.is_null()) { - // flag_list = mailimap_flag_list_new_empty(); - // mailimap_flag_list_add(flag_list, flag); - // store_att_flags = mailimap_store_att_flags_new_add_flags(flag_list); - // mailimap_uid_store(imap.etpan, set, store_att_flags); - // } - // if !store_att_flags.is_null() { - // mailimap_store_att_flags_free(store_att_flags); - // } - // if !set.is_null() { - // mailimap_set_free(set); - // set = 0 as *mut mailimap_set - // } - // if 0 != imap.should_reconnect { - // 0 - // } else { - // 1 - // } - // } pub fn set_seen( &self, @@ -1193,46 +1191,45 @@ impl dc_imap_t { uid: uint32_t, ) -> dc_imap_res { unimplemented!() + // let mut res: dc_imap_res = 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 dc_imap_res; } - // let mut res: dc_imap_res = 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 dc_imap_res; - // } pub fn set_mdnsent( &self, @@ -1241,166 +1238,164 @@ impl dc_imap_t { uid: uint32_t, ) -> dc_imap_res { unimplemented!(); + // let mut can_create_flag: libc::c_int = 0; + // let mut current_block: u64; + // // returns 0=job should be retried later, 1=job done, 2=job done and flag just set + // let mut res: dc_imap_res = DC_RETRY_LATER; + // let mut set: *mut mailimap_set = mailimap_set_new_single(uid); + // let mut fetch_result: *mut clist = 0 as *mut clist; + // if folder.is_null() || uid == 0 as libc::c_uint || set.is_null() { + // res = DC_FAILED + // } else if !imap.etpan.is_null() { + // dc_log_info( + // context, + // 0, + // b"Marking message %s/%i as $MDNSent...\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 $MDNSent flag.\x00" as *const u8 + // as *const libc::c_char, + // folder, + // ); + // } else { + // /* Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not set: set the flags and return this information. + // If the folder cannot handle the `$MDNSent` flag, we risk duplicated MDNs; it's up to the receiving MUA to handle this then (eg. Delta Chat has no problem with this). */ + // can_create_flag = 0; + // if !(*imap.etpan).imap_selection_info.is_null() + // && !(*(*imap.etpan).imap_selection_info) + // .sel_perm_flags + // .is_null() + // { + // let mut iter: *mut clistiter = 0 as *mut clistiter; + // iter = (*(*(*imap.etpan).imap_selection_info).sel_perm_flags).first; + // while !iter.is_null() { + // let mut fp: *mut mailimap_flag_perm = (if !iter.is_null() { + // (*iter).data + // } else { + // 0 as *mut libc::c_void + // }) + // as *mut mailimap_flag_perm; + // if !fp.is_null() { + // if (*fp).fl_type == MAILIMAP_FLAG_PERM_ALL as libc::c_int { + // can_create_flag = 1; + // break; + // } else if (*fp).fl_type == MAILIMAP_FLAG_PERM_FLAG as libc::c_int + // && !(*fp).fl_flag.is_null() + // { + // let mut fl: *mut mailimap_flag = + // (*fp).fl_flag as *mut mailimap_flag; + // if (*fl).fl_type == MAILIMAP_FLAG_KEYWORD as libc::c_int + // && !(*fl).fl_data.fl_keyword.is_null() + // && strcmp( + // (*fl).fl_data.fl_keyword, + // b"$MDNSent\x00" as *const u8 as *const libc::c_char, + // ) == 0 + // { + // can_create_flag = 1; + // break; + // } + // } + // } + // iter = if !iter.is_null() { + // (*iter).next + // } else { + // 0 as *mut clistcell_s + // } + // } + // } + // if 0 != can_create_flag { + // let mut r: libc::c_int = mailimap_uid_fetch( + // imap.etpan, + // set, + // imap.fetch_type_flags, + // &mut fetch_result, + // ); + // if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() { + // fetch_result = 0 as *mut clist + // } else { + // let mut cur: *mut clistiter = (*fetch_result).first; + // if !cur.is_null() { + // if 0 != peek_flag_keyword( + // (if !cur.is_null() { + // (*cur).data + // } else { + // 0 as *mut libc::c_void + // }) as *mut mailimap_msg_att, + // b"$MDNSent\x00" as *const u8 as *const libc::c_char, + // ) { + // res = DC_ALREADY_DONE; + // current_block = 14832935472441733737; + // } else if add_flag( + // imap, + // uid, + // mailimap_flag_new_flag_keyword(dc_strdup( + // b"$MDNSent\x00" as *const u8 as *const libc::c_char, + // )), + // ) == 0 + // { + // current_block = 17044610252497760460; + // } else { + // res = DC_SUCCESS; + // current_block = 14832935472441733737; + // } + // match current_block { + // 17044610252497760460 => {} + // _ => { + // dc_log_info( + // context, + // 0, + // if res as libc::c_uint + // == DC_SUCCESS as libc::c_int as libc::c_uint + // { + // b"$MDNSent just set and MDN will be sent.\x00" + // as *const u8 + // as *const libc::c_char + // } else { + // b"$MDNSent already set and MDN already sent.\x00" + // as *const u8 + // as *const libc::c_char + // }, + // ); + // } + // } + // } + // } + // } else { + // res = DC_SUCCESS; + // dc_log_info( + // context, + // 0, + // b"Cannot store $MDNSent flags, risk sending duplicate MDN.\x00" as *const u8 + // as *const libc::c_char, + // ); + // } + // } + // } + // if !set.is_null() { + // mailimap_set_free(set); + // set = 0 as *mut mailimap_set + // } + // if !fetch_result.is_null() { + // mailimap_fetch_list_free(fetch_result); + // fetch_result = 0 as *mut clist + // } + + // (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 dc_imap_res } - // let mut can_create_flag: libc::c_int = 0; - // let mut current_block: u64; - // // returns 0=job should be retried later, 1=job done, 2=job done and flag just set - // let mut res: dc_imap_res = DC_RETRY_LATER; - // let mut set: *mut mailimap_set = mailimap_set_new_single(uid); - // let mut fetch_result: *mut clist = 0 as *mut clist; - // if folder.is_null() || uid == 0 as libc::c_uint || set.is_null() { - // res = DC_FAILED - // } else if !imap.etpan.is_null() { - // dc_log_info( - // context, - // 0, - // b"Marking message %s/%i as $MDNSent...\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 $MDNSent flag.\x00" as *const u8 - // as *const libc::c_char, - // folder, - // ); - // } else { - // /* Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not set: set the flags and return this information. - // If the folder cannot handle the `$MDNSent` flag, we risk duplicated MDNs; it's up to the receiving MUA to handle this then (eg. Delta Chat has no problem with this). */ - // can_create_flag = 0; - // if !(*imap.etpan).imap_selection_info.is_null() - // && !(*(*imap.etpan).imap_selection_info) - // .sel_perm_flags - // .is_null() - // { - // let mut iter: *mut clistiter = 0 as *mut clistiter; - // iter = (*(*(*imap.etpan).imap_selection_info).sel_perm_flags).first; - // while !iter.is_null() { - // let mut fp: *mut mailimap_flag_perm = (if !iter.is_null() { - // (*iter).data - // } else { - // 0 as *mut libc::c_void - // }) - // as *mut mailimap_flag_perm; - // if !fp.is_null() { - // if (*fp).fl_type == MAILIMAP_FLAG_PERM_ALL as libc::c_int { - // can_create_flag = 1; - // break; - // } else if (*fp).fl_type == MAILIMAP_FLAG_PERM_FLAG as libc::c_int - // && !(*fp).fl_flag.is_null() - // { - // let mut fl: *mut mailimap_flag = - // (*fp).fl_flag as *mut mailimap_flag; - // if (*fl).fl_type == MAILIMAP_FLAG_KEYWORD as libc::c_int - // && !(*fl).fl_data.fl_keyword.is_null() - // && strcmp( - // (*fl).fl_data.fl_keyword, - // b"$MDNSent\x00" as *const u8 as *const libc::c_char, - // ) == 0 - // { - // can_create_flag = 1; - // break; - // } - // } - // } - // iter = if !iter.is_null() { - // (*iter).next - // } else { - // 0 as *mut clistcell_s - // } - // } - // } - // if 0 != can_create_flag { - // let mut r: libc::c_int = mailimap_uid_fetch( - // imap.etpan, - // set, - // imap.fetch_type_flags, - // &mut fetch_result, - // ); - // if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() { - // fetch_result = 0 as *mut clist - // } else { - // let mut cur: *mut clistiter = (*fetch_result).first; - // if !cur.is_null() { - // if 0 != peek_flag_keyword( - // (if !cur.is_null() { - // (*cur).data - // } else { - // 0 as *mut libc::c_void - // }) as *mut mailimap_msg_att, - // b"$MDNSent\x00" as *const u8 as *const libc::c_char, - // ) { - // res = DC_ALREADY_DONE; - // current_block = 14832935472441733737; - // } else if add_flag( - // imap, - // uid, - // mailimap_flag_new_flag_keyword(dc_strdup( - // b"$MDNSent\x00" as *const u8 as *const libc::c_char, - // )), - // ) == 0 - // { - // current_block = 17044610252497760460; - // } else { - // res = DC_SUCCESS; - // current_block = 14832935472441733737; - // } - // match current_block { - // 17044610252497760460 => {} - // _ => { - // dc_log_info( - // context, - // 0, - // if res as libc::c_uint - // == DC_SUCCESS as libc::c_int as libc::c_uint - // { - // b"$MDNSent just set and MDN will be sent.\x00" - // as *const u8 - // as *const libc::c_char - // } else { - // b"$MDNSent already set and MDN already sent.\x00" - // as *const u8 - // as *const libc::c_char - // }, - // ); - // } - // } - // } - // } - // } else { - // res = DC_SUCCESS; - // dc_log_info( - // context, - // 0, - // b"Cannot store $MDNSent flags, risk sending duplicate MDN.\x00" as *const u8 - // as *const libc::c_char, - // ); - // } - // } - // } - // if !set.is_null() { - // mailimap_set_free(set); - // set = 0 as *mut mailimap_set - // } - // if !fetch_result.is_null() { - // mailimap_fetch_list_free(fetch_result); - // fetch_result = 0 as *mut clist - // } - - // (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 dc_imap_res - // } - // only returns 0 on connection problems; we should try later again in this case * pub fn delete_msg( &self, @@ -1410,118 +1405,117 @@ impl dc_imap_t { mut server_uid: uint32_t, ) -> libc::c_int { unimplemented!() - } - // let mut success: libc::c_int = 0; - // let mut r: libc::c_int = 0; - // let mut fetch_result: *mut clist = 0 as *mut clist; - // let mut is_rfc724_mid: *mut libc::c_char = 0 as *mut libc::c_char; - // let mut new_folder: *mut libc::c_char = 0 as *mut libc::c_char; - // if rfc724_mid.is_null() - // || folder.is_null() - // || *folder.offset(0isize) as libc::c_int == 0 - // || server_uid == 0 as libc::c_uint - // { - // success = 1 - // } else { - // 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); + // let mut success: libc::c_int = 0; + // let mut r: libc::c_int = 0; + // let mut fetch_result: *mut clist = 0 as *mut clist; + // let mut is_rfc724_mid: *mut libc::c_char = 0 as *mut libc::c_char; + // let mut new_folder: *mut libc::c_char = 0 as *mut libc::c_char; + // if rfc724_mid.is_null() + // || folder.is_null() + // || *folder.offset(0isize) as libc::c_int == 0 + // || server_uid == 0 as libc::c_uint + // { + // success = 1 + // } else { + // 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 { - // 1 - // } else { - // dc_imap_is_connected(imap) - // } - // } + // if 0 != success { + // 1 + // } else { + // dc_imap_is_connected(imap) + // } + } pub fn configure_folders(&self, context: &dc_context_t, flags: libc::c_int) { if !self.is_connected() {