Browse Source

melib/imap: remove some debug prints

jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
4939a1ad9e
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 25
      melib/src/backends/imap.rs
  2. 16
      melib/src/backends/imap/cache.rs
  3. 27
      melib/src/backends/imap/cache/sync.rs
  4. 11
      melib/src/backends/imap/connection.rs
  5. 4
      melib/src/backends/imap/operations.rs
  6. 1
      melib/src/backends/imap/untagged.rs
  7. 10
      melib/src/backends/imap/watch.rs

25
melib/src/backends/imap.rs

@ -450,11 +450,11 @@ impl MailBackend for ImapType {
match timeout(timeout_dur, connection.lock()).await {
Ok(mut conn) => {
debug!("is_online");
match debug!(timeout(timeout_dur, conn.connect()).await) {
match timeout(timeout_dur, conn.connect()).await {
Ok(Ok(())) => Ok(()),
Err(err) | Ok(Err(err)) => {
conn.stream = Err(err.clone());
debug!(conn.connect().await)
conn.connect().await
}
}
}
@ -481,7 +481,6 @@ impl MailBackend for ImapType {
_ => false,
};
Ok(Box::pin(async move {
debug!(has_idle);
while let Err(err) = if has_idle {
idle(ImapWatchKit {
conn: ImapConnection::new_connection(&server_conf, uid_store.clone()),
@ -501,16 +500,16 @@ impl MailBackend for ImapType {
if err.kind.is_network() {
uid_store.is_online.lock().unwrap().1 = Err(err.clone());
}
debug!("failure: {}", err.to_string());
debug!("Watch failure: {}", err.to_string());
match timeout(uid_store.timeout, main_conn_lck.connect())
.await
.and_then(|res| res)
{
Err(err2) => {
debug!("reconnect attempt failed: {}", err2.to_string());
debug!("Watch reconnect attempt failed: {}", err2.to_string());
}
Ok(()) => {
debug!("reconnect attempt succesful");
debug!("Watch reconnect attempt succesful");
continue;
}
}
@ -1420,7 +1419,7 @@ impl ImapType {
conn.read_response(&mut res, RequiredResponses::LIST_REQUIRED)
.await?;
}
debug!("out: {}", String::from_utf8_lossy(&res));
debug!("LIST reply: {}", String::from_utf8_lossy(&res));
let mut lines = res.split_rn();
/* Remove "M__ OK .." line */
lines.next_back();
@ -1472,7 +1471,7 @@ impl ImapType {
conn.read_response(&mut res, RequiredResponses::LSUB_REQUIRED)
.await?;
let mut lines = res.split_rn();
debug!("out: {}", String::from_utf8_lossy(&res));
debug!("LSUB reply: {}", String::from_utf8_lossy(&res));
/* Remove "M__ OK .." line */
lines.next_back();
for l in lines {
@ -1489,7 +1488,7 @@ impl ImapType {
debug!("parse error for {:?}", l);
}
}
Ok(debug!(mailboxes))
Ok(mailboxes)
}
pub fn validate_config(s: &AccountSettings) -> Result<()> {
@ -1663,7 +1662,7 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
FetchStage::ResyncCache => {
let mailbox_hash = state.mailbox_hash;
let mut conn = state.connection.lock().await;
let res = debug!(conn.resync(mailbox_hash).await);
let res = conn.resync(mailbox_hash).await;
if let Ok(Some(payload)) = res {
state.stage = FetchStage::Finished;
return Ok(payload);
@ -1740,7 +1739,7 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
} in v.iter_mut()
{
if uid.is_none() || envelope.is_none() || flags.is_none() {
debug!("in fetch is none");
debug!("BUG? in fetch is none");
debug!(uid);
debug!(envelope);
debug!(flags);
@ -1782,14 +1781,14 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
}
}
if let Some(ref mut cache_handle) = cache_handle {
if let Err(err) = debug!(cache_handle
if let Err(err) = cache_handle
.insert_envelopes(mailbox_hash, &v)
.chain_err_summary(|| {
format!(
"Could not save envelopes in cache for mailbox {}",
mailbox_path
)
}))
})
{
(state.uid_store.event_consumer)(
state.uid_store.account_hash,

16
melib/src/backends/imap/cache.rs

@ -365,7 +365,7 @@ mod sqlite3_m {
fn envelopes(&mut self, mailbox_hash: MailboxHash) -> Result<Option<Vec<EnvelopeHash>>> {
debug!("envelopes mailbox_hash {}", mailbox_hash);
if debug!(self.mailbox_state(mailbox_hash)?.is_none()) {
if self.mailbox_state(mailbox_hash)?.is_none() {
return Ok(None);
}
@ -429,7 +429,6 @@ mod sqlite3_m {
.cloned()
.unwrap_or_default();
if self.mailbox_state(mailbox_hash)?.is_none() {
debug!(self.mailbox_state(mailbox_hash)?.is_none());
return Err(MeliError::new("Mailbox is not in cache").set_kind(ErrorKind::Bug));
}
let Self {
@ -471,13 +470,7 @@ mod sqlite3_m {
mailbox_hash: MailboxHash,
refresh_events: &[(UID, RefreshEvent)],
) -> Result<()> {
debug!(
"update with refresh_events mailbox_hash {} len {}",
mailbox_hash,
refresh_events.len()
);
if self.mailbox_state(mailbox_hash)?.is_none() {
debug!(self.mailbox_state(mailbox_hash)?.is_none());
return Err(MeliError::new("Mailbox is not in cache").set_kind(ErrorKind::Bug));
}
let Self {
@ -488,7 +481,7 @@ mod sqlite3_m {
let tx = connection.transaction()?;
let mut hash_index_lck = uid_store.hash_index.lock().unwrap();
for (uid, event) in refresh_events {
match debug!(&event.kind) {
match &event.kind {
RefreshEventKind::Remove(env_hash) => {
hash_index_lck.remove(&env_hash);
tx.execute(
@ -655,14 +648,13 @@ pub(super) async fn fetch_cached_envs(state: &mut FetchState) -> Result<Option<V
ref uid_store,
cache_handle: _,
} = state;
debug!(uid_store.keep_offline_cache);
let mailbox_hash = *mailbox_hash;
if !uid_store.keep_offline_cache {
return Ok(None);
}
{
let mut conn = connection.lock().await;
match debug!(conn.load_cache(mailbox_hash).await) {
match conn.load_cache(mailbox_hash).await {
None => return Ok(None),
Some(Ok(env_hashes)) => {
let env_lck = uid_store.envelopes.lock().unwrap();
@ -675,7 +667,7 @@ pub(super) async fn fetch_cached_envs(state: &mut FetchState) -> Result<Option<V
.collect::<Vec<Envelope>>(),
));
}
Some(Err(err)) => return debug!(Err(err)),
Some(Err(err)) => return Err(err),
}
}
}

27
melib/src/backends/imap/cache/sync.rs

@ -63,14 +63,14 @@ impl ImapConnection {
Ok(v) => v,
Err(err) => return Some(Err(err)),
};
match debug!(cache_handle.mailbox_state(mailbox_hash)) {
match cache_handle.mailbox_state(mailbox_hash) {
Err(err) => return Some(Err(err)),
Ok(Some(())) => {}
Ok(None) => {
return None;
}
};
match debug!(cache_handle.envelopes(mailbox_hash)) {
match cache_handle.envelopes(mailbox_hash) {
Ok(Some(envs)) => Some(Ok(envs)),
Ok(None) => None,
Err(err) => Some(Err(err)),
@ -116,16 +116,10 @@ impl ImapConnection {
)
};
let mut new_unseen = BTreeSet::default();
debug!("current_uidvalidity is {}", current_uidvalidity);
debug!("max_uid is {}", max_uid);
let select_response = self
.select_mailbox(mailbox_hash, &mut response, true)
.await?
.unwrap();
debug!(
"select_response.uidvalidity is {}",
select_response.uidvalidity
);
// 1. check UIDVALIDITY. If fail, discard cache and rebuild
if select_response.uidvalidity != current_uidvalidity {
cache_handle.clear(mailbox_hash, &select_response)?;
@ -193,14 +187,14 @@ impl ImapConnection {
}
}
{
debug!(cache_handle
cache_handle
.insert_envelopes(mailbox_hash, &v)
.chain_err_summary(|| {
format!(
"Could not save envelopes in cache for mailbox {}",
mailbox_path
)
}))?;
})?;
}
for FetchResponse {
@ -352,9 +346,6 @@ impl ImapConnection {
.unwrap()
.get(&mailbox_hash)
.cloned();
debug!(&cached_uidvalidity);
debug!(&cached_max_uid);
debug!(&cached_highestmodseq);
if cached_uidvalidity.is_none()
|| cached_max_uid.is_none()
|| cached_highestmodseq.is_none()
@ -381,17 +372,11 @@ impl ImapConnection {
)
};
let mut new_unseen = BTreeSet::default();
debug!("current_uidvalidity is {}", cached_uidvalidity);
debug!("max_uid is {}", cached_max_uid);
// 1. check UIDVALIDITY. If fail, discard cache and rebuild
let select_response = self
.select_mailbox(mailbox_hash, &mut response, true)
.await?
.unwrap();
debug!(
"select_response.uidvalidity is {}",
select_response.uidvalidity
);
if select_response.uidvalidity != cached_uidvalidity {
// 1a) Check the mailbox UIDVALIDITY (see section 4.1 for more
//details) with SELECT/EXAMINE/STATUS.
@ -497,14 +482,14 @@ impl ImapConnection {
}
}
{
debug!(cache_handle
cache_handle
.insert_envelopes(mailbox_hash, &v)
.chain_err_summary(|| {
format!(
"Could not save envelopes in cache for mailbox {}",
mailbox_path
)
}))?;
})?;
}
for FetchResponse { uid, envelope, .. } in v {

11
melib/src/backends/imap/connection.rs

@ -467,7 +467,6 @@ impl ImapStream {
if !termination_string.is_empty()
&& ret[last_line_idx..].starts_with(termination_string)
{
debug!(String::from_utf8_lossy(&ret[last_line_idx..]));
if !keep_termination_string {
ret.splice(last_line_idx.., std::iter::empty::<u8>());
}
@ -595,7 +594,7 @@ impl ImapConnection {
self.stream = Err(err);
}
}
if debug!(self.stream.is_ok()) {
if self.stream.is_ok() {
let mut ret = Vec::new();
if let Err(err) = try_await(async {
self.send_command(b"NOOP").await?;
@ -613,7 +612,7 @@ impl ImapConnection {
return Ok(());
}
}
let new_stream = debug!(ImapStream::new_connection(&self.server_conf).await);
let new_stream = ImapStream::new_connection(&self.server_conf).await;
if let Err(err) = new_stream.as_ref() {
self.uid_store.is_online.lock().unwrap().1 = Err(err.clone());
} else {
@ -727,7 +726,6 @@ impl ImapConnection {
);
}
ImapResponse::No(ref response_code) => {
//FIXME return error
debug!(
"Received NO response: {:?} {:?}",
response_code,
@ -745,7 +743,6 @@ impl ImapConnection {
return r.into();
}
ImapResponse::Bad(ref response_code) => {
//FIXME return error
debug!(
"Received BAD response: {:?} {:?}",
response_code,
@ -1087,7 +1084,6 @@ impl ImapBlockingConnection {
let mut prev_failure = None;
async move {
if self.conn.stream.is_err() {
debug!(&self.conn.stream);
return None;
}
loop {
@ -1121,7 +1117,6 @@ async fn read(
}
Ok(b) => {
result.extend_from_slice(&buf[0..b]);
debug!(unsafe { std::str::from_utf8_unchecked(result) });
if let Some(pos) = result.find(b"\r\n") {
*prev_res_length = pos + b"\r\n".len();
return Some(result[0..*prev_res_length].to_vec());
@ -1129,8 +1124,6 @@ async fn read(
*prev_failure = None;
}
Err(_err) => {
debug!(&conn.stream);
debug!(&_err);
*err = Some(Into::<MeliError>::into(_err).set_kind(crate::error::ErrorKind::Network));
*break_flag = true;
*prev_failure = Some(SystemTime::now());

4
melib/src/backends/imap/operations.rs

@ -144,9 +144,9 @@ impl BackendOp for ImapOp {
.map_err(MeliError::from)?;
if v.len() != 1 {
debug!("responses len is {}", v.len());
debug!(&response);
debug!(String::from_utf8_lossy(&response));
/* TODO: Trigger cache invalidation here. */
debug!(format!("message with UID {} was not found", uid));
debug!("message with UID {} was not found", uid);
return Err(MeliError::new(format!(
"Invalid/unexpected response: {:?}",
response

1
melib/src/backends/imap/untagged.rs

@ -486,7 +486,6 @@ impl ImapConnection {
self.read_response(&mut response, RequiredResponses::SEARCH)
.await,
);
debug!(to_str!(&response));
match super::protocol_parser::search_results(
response.split_rn().next().unwrap_or(b""),
)

10
melib/src/backends/imap/watch.rs

@ -79,7 +79,6 @@ pub async fn idle(kit: ImapWatchKit) -> Result<()> {
.examine_mailbox(mailbox_hash, &mut response, true)
.await?
.unwrap();
debug!("select response {}", String::from_utf8_lossy(&response));
{
let mut uidvalidities = uid_store.uidvalidity.lock().unwrap();
@ -219,7 +218,6 @@ pub async fn examine_updates(
.examine_mailbox(mailbox_hash, &mut response, true)
.await?
.unwrap();
debug!(&select_response);
{
let mut uidvalidities = uid_store.uidvalidity.lock().unwrap();
@ -311,7 +309,7 @@ pub async fn examine_updates(
return Ok(());
}
if debug!(select_response.recent > 0) {
if select_response.recent > 0 {
/* UID SEARCH RECENT */
conn.send_command(b"UID SEARCH RECENT").await?;
conn.read_response(&mut response, RequiredResponses::SEARCH)
@ -340,7 +338,7 @@ pub async fn examine_updates(
conn.send_command(cmd.as_bytes()).await?;
conn.read_response(&mut response, RequiredResponses::FETCH_REQUIRED)
.await?;
} else if debug!(select_response.exists > mailbox.exists.lock().unwrap().len()) {
} else if select_response.exists > mailbox.exists.lock().unwrap().len() {
conn.send_command(
format!(
"FETCH {}:* (UID FLAGS ENVELOPE BODY.PEEK[HEADER.FIELDS (REFERENCES)] BODYSTRUCTURE)",
@ -404,14 +402,14 @@ pub async fn examine_updates(
}
}
if uid_store.keep_offline_cache {
debug!(cache_handle
cache_handle
.insert_envelopes(mailbox_hash, &v)
.chain_err_summary(|| {
format!(
"Could not save envelopes in cache for mailbox {}",
mailbox.imap_path()
)
}))?;
})?;
}
for FetchResponse { uid, envelope, .. } in v {

Loading…
Cancel
Save