mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
Make return type of Image::mv an enum
Replace named constants with enum to improve type-safety and make exhausiveness checks possible. Note, that since this enum never pass FFI border, its numeric values does not need to be specified explicitly and can be left on compiler's discretion.
This commit is contained in:
28
src/imap.rs
28
src/imap.rs
@@ -19,6 +19,14 @@ use crate::param::Params;
|
|||||||
|
|
||||||
const DC_IMAP_SEEN: usize = 0x0001;
|
const DC_IMAP_SEEN: usize = 0x0001;
|
||||||
|
|
||||||
|
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ImapResult {
|
||||||
|
Failed,
|
||||||
|
RetryLater,
|
||||||
|
AlreadyDone,
|
||||||
|
Success,
|
||||||
|
}
|
||||||
|
|
||||||
pub const DC_SUCCESS: usize = 3;
|
pub const DC_SUCCESS: usize = 3;
|
||||||
pub const DC_ALREADY_DONE: usize = 2;
|
pub const DC_ALREADY_DONE: usize = 2;
|
||||||
pub const DC_RETRY_LATER: usize = 1;
|
pub const DC_RETRY_LATER: usize = 1;
|
||||||
@@ -1130,12 +1138,12 @@ impl Imap {
|
|||||||
uid: u32,
|
uid: u32,
|
||||||
dest_folder: S2,
|
dest_folder: S2,
|
||||||
dest_uid: &mut u32,
|
dest_uid: &mut u32,
|
||||||
) -> usize {
|
) -> ImapResult {
|
||||||
let mut res = DC_RETRY_LATER;
|
let mut res = ImapResult::RetryLater;
|
||||||
let set = format!("{}", uid);
|
let set = format!("{}", uid);
|
||||||
|
|
||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
res = DC_FAILED;
|
res = ImapResult::Failed;
|
||||||
} else if folder.as_ref() == dest_folder.as_ref() {
|
} else if folder.as_ref() == dest_folder.as_ref() {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
@@ -1145,7 +1153,7 @@ impl Imap {
|
|||||||
dest_folder.as_ref()
|
dest_folder.as_ref()
|
||||||
);
|
);
|
||||||
|
|
||||||
res = DC_ALREADY_DONE;
|
res = ImapResult::AlreadyDone;
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
@@ -1165,7 +1173,7 @@ impl Imap {
|
|||||||
let moved = if let Some(ref mut session) = &mut *self.session.lock().unwrap() {
|
let moved = if let Some(ref mut session) = &mut *self.session.lock().unwrap() {
|
||||||
match session.uid_mv(&set, &dest_folder) {
|
match session.uid_mv(&set, &dest_folder) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
res = DC_SUCCESS;
|
res = ImapResult::Success;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -1205,22 +1213,22 @@ impl Imap {
|
|||||||
warn!(context, "Cannot mark message as \"Deleted\".",);
|
warn!(context, "Cannot mark message as \"Deleted\".",);
|
||||||
}
|
}
|
||||||
self.config.write().unwrap().selected_folder_needs_expunge = true;
|
self.config.write().unwrap().selected_folder_needs_expunge = true;
|
||||||
res = DC_SUCCESS;
|
res = ImapResult::Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if res == DC_SUCCESS {
|
if res == ImapResult::Success {
|
||||||
// TODO: is this correct?
|
// TODO: is this correct?
|
||||||
*dest_uid = uid;
|
*dest_uid = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if res == DC_RETRY_LATER {
|
if res == ImapResult::RetryLater {
|
||||||
if self.should_reconnect() {
|
if self.should_reconnect() {
|
||||||
DC_RETRY_LATER
|
ImapResult::RetryLater
|
||||||
} else {
|
} else {
|
||||||
DC_FAILED
|
ImapResult::Failed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res
|
res
|
||||||
|
|||||||
10
src/job.rs
10
src/job.rs
@@ -247,13 +247,13 @@ impl Job {
|
|||||||
&dest_folder,
|
&dest_folder,
|
||||||
&mut dest_uid,
|
&mut dest_uid,
|
||||||
) {
|
) {
|
||||||
DC_RETRY_LATER => {
|
ImapResult::RetryLater => {
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
DC_SUCCESS => {
|
ImapResult::Success => {
|
||||||
dc_update_server_uid(context, &msg.rfc724_mid, &dest_folder, dest_uid);
|
dc_update_server_uid(context, &msg.rfc724_mid, &dest_folder, dest_uid);
|
||||||
}
|
}
|
||||||
DC_FAILED | DC_ALREADY_DONE | _ => {}
|
ImapResult::Failed | ImapResult::AlreadyDone => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,8 +401,8 @@ impl Job {
|
|||||||
}
|
}
|
||||||
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
|
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
|
||||||
if let Some(dest_folder) = dest_folder {
|
if let Some(dest_folder) = dest_folder {
|
||||||
if 1 == inbox.mv(context, folder, uid, dest_folder, &mut dest_uid)
|
if ImapResult::RetryLater
|
||||||
as libc::c_uint
|
== inbox.mv(context, folder, uid, dest_folder, &mut dest_uid)
|
||||||
{
|
{
|
||||||
self.try_again_later(3, None);
|
self.try_again_later(3, None);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user