mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
refactor: get rid of ImapActionResult
This commit is contained in:
@@ -3,13 +3,13 @@
|
|||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
use deltachat_derive::{FromSql, ToSql};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::imap::{session::Session, ImapActionResult};
|
use crate::imap::session::Session;
|
||||||
use crate::message::{Message, MsgId, Viewtype};
|
use crate::message::{Message, MsgId, Viewtype};
|
||||||
use crate::mimeparser::{MimeMessage, Part};
|
use crate::mimeparser::{MimeMessage, Part};
|
||||||
use crate::tools::time;
|
use crate::tools::time;
|
||||||
@@ -154,7 +154,7 @@ pub(crate) async fn download_msg(
|
|||||||
return Err(anyhow!("Call download_full() again to try over."));
|
return Err(anyhow!("Call download_full() again to try over."));
|
||||||
};
|
};
|
||||||
|
|
||||||
match session
|
session
|
||||||
.fetch_single_msg(
|
.fetch_single_msg(
|
||||||
context,
|
context,
|
||||||
&server_folder,
|
&server_folder,
|
||||||
@@ -162,13 +162,8 @@ pub(crate) async fn download_msg(
|
|||||||
server_uid,
|
server_uid,
|
||||||
msg.rfc724_mid.clone(),
|
msg.rfc724_mid.clone(),
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
{
|
Ok(())
|
||||||
ImapActionResult::RetryLater | ImapActionResult::Failed => {
|
|
||||||
Err(anyhow!("Call download_full() again to try over."))
|
|
||||||
}
|
|
||||||
ImapActionResult::Success => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
@@ -183,20 +178,19 @@ impl Session {
|
|||||||
uidvalidity: u32,
|
uidvalidity: u32,
|
||||||
uid: u32,
|
uid: u32,
|
||||||
rfc724_mid: String,
|
rfc724_mid: String,
|
||||||
) -> ImapActionResult {
|
) -> Result<()> {
|
||||||
if let Some(imapresult) = self
|
if uid == 0 {
|
||||||
.prepare_imap_operation_on_msg(context, folder, uid)
|
bail!("Attempt to fetch UID 0");
|
||||||
.await
|
|
||||||
{
|
|
||||||
return imapresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.select_folder(context, Some(folder)).await?;
|
||||||
|
|
||||||
// we are connected, and the folder is selected
|
// we are connected, and the folder is selected
|
||||||
info!(context, "Downloading message {}/{} fully...", folder, uid);
|
info!(context, "Downloading message {}/{} fully...", folder, uid);
|
||||||
|
|
||||||
let mut uid_message_ids: BTreeMap<u32, String> = BTreeMap::new();
|
let mut uid_message_ids: BTreeMap<u32, String> = BTreeMap::new();
|
||||||
uid_message_ids.insert(uid, rfc724_mid);
|
uid_message_ids.insert(uid, rfc724_mid);
|
||||||
let (last_uid, _received) = match self
|
let (last_uid, _received) = self
|
||||||
.fetch_many_msgs(
|
.fetch_many_msgs(
|
||||||
context,
|
context,
|
||||||
folder,
|
folder,
|
||||||
@@ -206,16 +200,11 @@ impl Session {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
{
|
|
||||||
Ok(res) => res,
|
|
||||||
Err(_) => return ImapActionResult::Failed,
|
|
||||||
};
|
|
||||||
if last_uid.is_none() {
|
if last_uid.is_none() {
|
||||||
ImapActionResult::Failed
|
bail!("Failed to fetch UID {uid}");
|
||||||
} else {
|
|
||||||
ImapActionResult::Success
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
src/imap.rs
34
src/imap.rs
@@ -54,13 +54,6 @@ use session::Session;
|
|||||||
|
|
||||||
pub(crate) const GENERATED_PREFIX: &str = "GEN_";
|
pub(crate) const GENERATED_PREFIX: &str = "GEN_";
|
||||||
|
|
||||||
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum ImapActionResult {
|
|
||||||
Failed,
|
|
||||||
RetryLater,
|
|
||||||
Success,
|
|
||||||
}
|
|
||||||
|
|
||||||
const RFC724MID_UID: &str = "(UID BODY.PEEK[HEADER.FIELDS (\
|
const RFC724MID_UID: &str = "(UID BODY.PEEK[HEADER.FIELDS (\
|
||||||
MESSAGE-ID \
|
MESSAGE-ID \
|
||||||
X-MICROSOFT-ORIGINAL-MESSAGE-ID\
|
X-MICROSOFT-ORIGINAL-MESSAGE-ID\
|
||||||
@@ -1475,33 +1468,6 @@ impl Session {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn prepare_imap_operation_on_msg(
|
|
||||||
&mut self,
|
|
||||||
context: &Context,
|
|
||||||
folder: &str,
|
|
||||||
uid: u32,
|
|
||||||
) -> Option<ImapActionResult> {
|
|
||||||
if uid == 0 {
|
|
||||||
return Some(ImapActionResult::RetryLater);
|
|
||||||
}
|
|
||||||
|
|
||||||
match self.select_folder(context, Some(folder)).await {
|
|
||||||
Ok(_) => None,
|
|
||||||
Err(select_folder::Error::ConnectionLost) => {
|
|
||||||
warn!(context, "Lost imap connection");
|
|
||||||
Some(ImapActionResult::RetryLater)
|
|
||||||
}
|
|
||||||
Err(select_folder::Error::BadFolderName(folder_name)) => {
|
|
||||||
warn!(context, "invalid folder name: {:?}", folder_name);
|
|
||||||
Some(ImapActionResult::Failed)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
warn!(context, "failed to select folder {:?}: {:#}", folder, err);
|
|
||||||
Some(ImapActionResult::RetryLater)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempts to configure mvbox.
|
/// Attempts to configure mvbox.
|
||||||
///
|
///
|
||||||
/// Tries to find any folder in the given list of `folders`. If none is found, tries to create
|
/// Tries to find any folder in the given list of `folders`. If none is found, tries to create
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ impl ImapSession {
|
|||||||
/// Selects a folder, possibly updating uid_validity and, if needed,
|
/// Selects a folder, possibly updating uid_validity and, if needed,
|
||||||
/// expunging the folder to remove delete-marked messages.
|
/// expunging the folder to remove delete-marked messages.
|
||||||
/// Returns whether a new folder was selected.
|
/// Returns whether a new folder was selected.
|
||||||
pub(super) async fn select_folder(
|
pub(crate) async fn select_folder(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
folder: Option<&str>,
|
folder: Option<&str>,
|
||||||
@@ -256,7 +256,7 @@ impl ImapSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
|
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
|
||||||
pub(super) enum NewlySelected {
|
pub(crate) enum NewlySelected {
|
||||||
/// The folder was newly selected during this call to select_folder().
|
/// The folder was newly selected during this call to select_folder().
|
||||||
Yes,
|
Yes,
|
||||||
/// No SELECT command was run because the folder already was selected
|
/// No SELECT command was run because the folder already was selected
|
||||||
|
|||||||
Reference in New Issue
Block a user