mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
update
This commit is contained in:
@@ -239,11 +239,15 @@ impl DownloadState {
|
|||||||
pub fn append_session_error(account_id: u64, error: String) -> BichonResult<()> {
|
pub fn append_session_error(account_id: u64, error: String) -> BichonResult<()> {
|
||||||
Self::update_state(account_id, move |current| {
|
Self::update_state(account_id, move |current| {
|
||||||
let mut updated = current.clone();
|
let mut updated = current.clone();
|
||||||
if let Some(ref mut session) = updated.active_session {
|
|
||||||
let new_error = AccountError {
|
let new_error = AccountError {
|
||||||
error,
|
error,
|
||||||
at: utc_now!(),
|
at: utc_now!(),
|
||||||
};
|
};
|
||||||
|
let target = updated
|
||||||
|
.active_session
|
||||||
|
.as_mut()
|
||||||
|
.or_else(|| updated.history.last_mut());
|
||||||
|
if let Some(session) = target {
|
||||||
session.errors.push(new_error);
|
session.errors.push(new_error);
|
||||||
let to_remove = session.errors.len().saturating_sub(30);
|
let to_remove = session.errors.len().saturating_sub(30);
|
||||||
if to_remove > 0 {
|
if to_remove > 0 {
|
||||||
|
|||||||
+15
-6
@@ -53,10 +53,12 @@ pub async fn process_imap_download(
|
|||||||
let mut session = match ImapExecutor::create_connection(account_id).await {
|
let mut session = match ImapExecutor::create_connection(account_id).await {
|
||||||
Ok(session) => session,
|
Ok(session) => session,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
let err_msg = format!("Failed to connect to IMAP server: {:#?}", e);
|
||||||
|
DownloadState::append_session_error(account_id, err_msg.clone())?;
|
||||||
DownloadState::update_session_status(
|
DownloadState::update_session_status(
|
||||||
account_id,
|
account_id,
|
||||||
DownloadStatus::Failed,
|
DownloadStatus::Failed,
|
||||||
Some(format!("Failed to connect to IMAP server: {}", e)),
|
Some(err_msg),
|
||||||
)?;
|
)?;
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
@@ -64,8 +66,9 @@ pub async fn process_imap_download(
|
|||||||
let remote_mailboxes = match get_download_folders(account, &mut session).await {
|
let remote_mailboxes = match get_download_folders(account, &mut session).await {
|
||||||
Ok(mailboxes) => mailboxes,
|
Ok(mailboxes) => mailboxes,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let err_msg = format!("Failed to fetch mailboxes: {}", err);
|
let err_msg = format!("Failed to fetch mailboxes: {:#?}", err);
|
||||||
warn!(account_id = account.id, error = %err, "{}", err_msg);
|
warn!(account_id = account.id, error = %err, "{}", err_msg);
|
||||||
|
DownloadState::append_session_error(account_id, err_msg.clone())?;
|
||||||
DownloadState::update_session_status(
|
DownloadState::update_session_status(
|
||||||
account_id,
|
account_id,
|
||||||
DownloadStatus::Failed,
|
DownloadStatus::Failed,
|
||||||
@@ -106,10 +109,12 @@ pub async fn process_imap_download(
|
|||||||
DownloadState::update_session_status(account_id, DownloadStatus::Success, None)?;
|
DownloadState::update_session_status(account_id, DownloadStatus::Success, None)?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
let err_msg = format!("Email Download interrupted: {:#?}", e);
|
||||||
|
DownloadState::append_session_error(account_id, err_msg.clone())?;
|
||||||
DownloadState::update_session_status(
|
DownloadState::update_session_status(
|
||||||
account_id,
|
account_id,
|
||||||
DownloadStatus::Failed,
|
DownloadStatus::Failed,
|
||||||
Some(format!("Email Download interrupted: {:#?}", e)),
|
Some(err_msg),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,11 +124,15 @@ pub async fn process_imap_download(
|
|||||||
let local_mailboxes = MailBox::list_all(account_id)?;
|
let local_mailboxes = MailBox::list_all(account_id)?;
|
||||||
match reconcile_mailboxes(account, &remote_mailboxes, &local_mailboxes, token).await {
|
match reconcile_mailboxes(account, &remote_mailboxes, &local_mailboxes, token).await {
|
||||||
Ok(_) => DownloadState::update_session_status(account_id, DownloadStatus::Success, None)?,
|
Ok(_) => DownloadState::update_session_status(account_id, DownloadStatus::Success, None)?,
|
||||||
Err(e) => DownloadState::update_session_status(
|
Err(e) => {
|
||||||
|
let err_msg = format!("Email Download interrupted: {:#?}", e);
|
||||||
|
DownloadState::append_session_error(account_id, err_msg.clone())?;
|
||||||
|
DownloadState::update_session_status(
|
||||||
account_id,
|
account_id,
|
||||||
DownloadStatus::Failed,
|
DownloadStatus::Failed,
|
||||||
Some(format!("Email Download interrupted: {:#?}", e)),
|
Some(err_msg),
|
||||||
)?,
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let elapsed_time = start_time.elapsed().as_secs();
|
let elapsed_time = start_time.elapsed().as_secs();
|
||||||
debug!(
|
debug!(
|
||||||
|
|||||||
Reference in New Issue
Block a user