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

View File

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