mirror of
https://github.com/chatmail/core.git
synced 2026-05-15 12:56:30 +03:00
Make return type of Image::mv an enum (#548)
Make return type of Image::mv an enum
This commit is contained in:
65
src/imap.rs
65
src/imap.rs
@@ -19,10 +19,13 @@ use crate::param::Params;
|
|||||||
|
|
||||||
const DC_IMAP_SEEN: usize = 0x0001;
|
const DC_IMAP_SEEN: usize = 0x0001;
|
||||||
|
|
||||||
const DC_SUCCESS: usize = 3;
|
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
|
||||||
const DC_ALREADY_DONE: usize = 2;
|
pub enum ImapResult {
|
||||||
const DC_RETRY_LATER: usize = 1;
|
Failed,
|
||||||
const DC_FAILED: usize = 0;
|
RetryLater,
|
||||||
|
AlreadyDone,
|
||||||
|
Success,
|
||||||
|
}
|
||||||
|
|
||||||
const PREFETCH_FLAGS: &str = "(UID ENVELOPE)";
|
const PREFETCH_FLAGS: &str = "(UID ENVELOPE)";
|
||||||
const BODY_FLAGS: &str = "(FLAGS BODY.PEEK[])";
|
const BODY_FLAGS: &str = "(FLAGS BODY.PEEK[])";
|
||||||
@@ -1130,12 +1133,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 +1148,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 +1168,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 +1208,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
|
||||||
@@ -1254,11 +1257,11 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_seen<S: AsRef<str>>(&self, context: &Context, folder: S, uid: u32) -> usize {
|
pub fn set_seen<S: AsRef<str>>(&self, context: &Context, folder: S, uid: u32) -> ImapResult {
|
||||||
let mut res = DC_RETRY_LATER;
|
let mut res = ImapResult::RetryLater;
|
||||||
|
|
||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
res = DC_FAILED
|
res = ImapResult::Failed
|
||||||
} else if self.is_connected() {
|
} else if self.is_connected() {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
@@ -1276,28 +1279,28 @@ impl Imap {
|
|||||||
} else if self.add_flag(context, uid, "\\Seen") == 0 {
|
} else if self.add_flag(context, uid, "\\Seen") == 0 {
|
||||||
warn!(context, "Cannot mark message as seen.",);
|
warn!(context, "Cannot mark message as seen.",);
|
||||||
} else {
|
} else {
|
||||||
res = DC_SUCCESS
|
res = ImapResult::Success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_mdnsent<S: AsRef<str>>(&self, context: &Context, folder: S, uid: u32) -> usize {
|
pub fn set_mdnsent<S: AsRef<str>>(&self, context: &Context, folder: S, uid: u32) -> ImapResult {
|
||||||
// returns 0=job should be retried later, 1=job done, 2=job done and flag just set
|
// returns 0=job should be retried later, 1=job done, 2=job done and flag just set
|
||||||
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 self.is_connected() {
|
} else if self.is_connected() {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
@@ -1367,21 +1370,21 @@ impl Imap {
|
|||||||
.unwrap_or_else(|| false);
|
.unwrap_or_else(|| false);
|
||||||
|
|
||||||
res = if flag_set {
|
res = if flag_set {
|
||||||
DC_ALREADY_DONE
|
ImapResult::AlreadyDone
|
||||||
} else if self.add_flag(context, uid, "$MDNSent") != 0 {
|
} else if self.add_flag(context, uid, "$MDNSent") != 0 {
|
||||||
DC_SUCCESS
|
ImapResult::Success
|
||||||
} else {
|
} else {
|
||||||
res
|
res
|
||||||
};
|
};
|
||||||
|
|
||||||
if res == DC_SUCCESS {
|
if res == ImapResult::Success {
|
||||||
info!(context, "$MDNSent just set and MDN will be sent.");
|
info!(context, "$MDNSent just set and MDN will be sent.");
|
||||||
} else {
|
} else {
|
||||||
info!(context, "$MDNSent already set and MDN already sent.");
|
info!(context, "$MDNSent already set and MDN already sent.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res = DC_SUCCESS;
|
res = ImapResult::Success;
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Cannot store $MDNSent flags, risk sending duplicate MDN.",
|
"Cannot store $MDNSent flags, risk sending duplicate MDN.",
|
||||||
@@ -1390,11 +1393,11 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
30
src/job.rs
30
src/job.rs
@@ -246,15 +246,14 @@ impl Job {
|
|||||||
msg.server_uid,
|
msg.server_uid,
|
||||||
&dest_folder,
|
&dest_folder,
|
||||||
&mut dest_uid,
|
&mut dest_uid,
|
||||||
) as libc::c_uint
|
) {
|
||||||
{
|
ImapResult::RetryLater => {
|
||||||
1 => {
|
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
3 => {
|
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);
|
||||||
}
|
}
|
||||||
0 | 2 | _ => {}
|
ImapResult::Failed | ImapResult::AlreadyDone => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,9 +332,9 @@ impl Job {
|
|||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
let server_folder = msg.server_folder.as_ref().unwrap();
|
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||||
match inbox.set_seen(context, server_folder, msg.server_uid) as libc::c_uint {
|
match inbox.set_seen(context, server_folder, msg.server_uid) {
|
||||||
0 => {}
|
ImapResult::Failed => {}
|
||||||
1 => {
|
ImapResult::RetryLater => {
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@@ -347,15 +346,14 @@ impl Job {
|
|||||||
{
|
{
|
||||||
let folder = msg.server_folder.as_ref().unwrap();
|
let folder = msg.server_folder.as_ref().unwrap();
|
||||||
|
|
||||||
match inbox.set_mdnsent(context, folder, msg.server_uid) as libc::c_uint
|
match inbox.set_mdnsent(context, folder, msg.server_uid) {
|
||||||
{
|
ImapResult::RetryLater => {
|
||||||
1 => {
|
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
3 => {
|
ImapResult::Success => {
|
||||||
send_mdn(context, msg.id);
|
send_mdn(context, msg.id);
|
||||||
}
|
}
|
||||||
0 | 2 | _ => {}
|
ImapResult::Failed | ImapResult::AlreadyDone => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +386,7 @@ impl Job {
|
|||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
}
|
}
|
||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
if inbox.set_seen(context, &folder, uid) == 0 {
|
if inbox.set_seen(context, &folder, uid) == ImapResult::Failed {
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
if 0 != self.param.get_int(Param::AlsoMove).unwrap_or_default() {
|
if 0 != self.param.get_int(Param::AlsoMove).unwrap_or_default() {
|
||||||
@@ -402,8 +400,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