imap: add chain_err_summary error descriptions

memfd
Manos Pitsidianakis 2020-06-22 17:21:46 +03:00
parent ca11c8e474
commit af4ad19169
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 39 additions and 9 deletions

View File

@ -44,7 +44,7 @@ use crate::backends::{AccountHash, MailboxHash};
use crate::backends::{BackendMailbox, MailBackend, Mailbox, RefreshEventConsumer};
use crate::conf::AccountSettings;
use crate::email::*;
use crate::error::{MeliError, Result};
use crate::error::{MeliError, Result, ResultIntoMeliError};
use std::collections::{hash_map::DefaultHasher, BTreeMap};
use std::collections::{HashMap, HashSet};
use std::hash::Hasher;
@ -251,9 +251,15 @@ impl MailBackend for ImapType {
return Ok(HashSet::default());
};
let cached_envs: (cache::MaxUID, Vec<(UID, Envelope)>);
cache::save_envelopes(uid_store.account_hash, mailbox_hash, *v, &[])?;
cache::save_envelopes(uid_store.account_hash, mailbox_hash, *v, &[])
.chain_err_summary(|| {
"Could not save envelopes in cache in get()"
})?;
cached_envs =
cache::get_envelopes(uid_store.account_hash, mailbox_hash, *v)?;
cache::get_envelopes(uid_store.account_hash, mailbox_hash, *v)
.chain_err_summary(|| {
"Could not get envelopes in cache in get()"
})?;
let (_max_uid, envelopes) = debug!(cached_envs);
*max_uid = _max_uid;
let ret = envelopes.iter().map(|(_, env)| env.hash()).collect();
@ -290,8 +296,17 @@ impl MailBackend for ImapType {
/* first SELECT the mailbox to get READ/WRITE permissions (because EXAMINE only
* returns READ-ONLY for both cases) */
conn.select_mailbox(mailbox_hash, &mut response)?;
let examine_response = protocol_parser::select_response(&response)?;
conn.select_mailbox(mailbox_hash, &mut response)
.chain_err_summary(|| {
format!("Could not select mailbox {}", mailbox_path)
})?;
let examine_response = protocol_parser::select_response(&response)
.chain_err_summary(|| {
format!(
"Could not parse select response for mailbox {}",
mailbox_path
)
})?;
*can_create_flags.lock().unwrap() = examine_response.can_create_flags;
debug!(
"mailbox: {} examine_response: {:?}",
@ -347,7 +362,13 @@ impl MailBackend for ImapType {
.as_bytes(),
)?
};
conn.read_response(&mut response, RequiredResponses::FETCH_REQUIRED)?;
conn.read_response(&mut response, RequiredResponses::FETCH_REQUIRED)
.chain_err_summary(|| {
format!(
"Could not parse fetch response for mailbox {}",
mailbox_path
)
})?;
debug!(
"fetch response is {} bytes and {} lines",
response.len(),
@ -407,7 +428,13 @@ impl MailBackend for ImapType {
.iter()
.map(|(uid, env)| (*uid, env))
.collect::<SmallVec<[(UID, &Envelope); 1024]>>(),
)?;
)
.chain_err_summary(|| {
format!(
"Could not save envelopes in cache for mailbox {}",
mailbox_path
)
})?;
}
for &env_hash in cached_hash_set.difference(&valid_hash_set) {
conn.add_refresh_event(RefreshEvent {

View File

@ -21,6 +21,7 @@
use super::*;
use crate::email::parser::{BytesExt, IResult};
use crate::error::ResultIntoMeliError;
use crate::get_path_hash;
use nom::{
branch::{alt, permutation},
@ -242,8 +243,10 @@ impl Into<Result<()>> for ImapResponse {
Self::No(ResponseCode::Alert(msg)) | Self::Bad(ResponseCode::Alert(msg)) => {
Err(MeliError::new(msg))
}
Self::No(_) => Err(MeliError::new("IMAP NO Response.")),
Self::Bad(_) => Err(MeliError::new("IMAP BAD Response.")),
Self::No(err) => Err(MeliError::new(format!("{:?}", err)))
.chain_err_summary(|| "IMAP NO Response.".to_string()),
Self::Bad(err) => Err(MeliError::new(format!("{:?}", err)))
.chain_err_summary(|| "IMAP BAD Response.".to_string()),
}
}
}