diff --git a/Makefile b/Makefile index 05f541a3..5bc1f1ba 100644 --- a/Makefile +++ b/Makefile @@ -183,10 +183,11 @@ install-bin: meli .NOTPARALLEL: yes install: meli install-bin install-doc @(if [ -z $${NO_MAN+x} ]; then \ - echo "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ;\ + $(PRINTF) "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ;\ + $(PRINTF) "\n or the tutorial in meli(7) (\`man 7 meli\`).\n" ;\ fi) - @echo " - Report bugs in the mailing list or git issue tracker ${UNDERLINE}https://git.meli.delivery${ANSI_RESET}" - @echo " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker." + @$(PRINTF) " - Report bugs in the mailing list or git issue tracker ${UNDERLINE}https://git.meli-email.org${ANSI_RESET}\n" + @$(PRINTF) " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker.\n" .PHONY: dist dist: diff --git a/melib/src/imap/connection.rs b/melib/src/imap/connection.rs index 75bfc4ff..7e48706a 100644 --- a/melib/src/imap/connection.rs +++ b/melib/src/imap/connection.rs @@ -31,9 +31,8 @@ use crate::{ LogLevel, }; extern crate native_tls; -#[cfg(debug_assertions)] -use std::borrow::Cow; use std::{ + borrow::Cow, collections::HashSet, convert::TryFrom, future::Future, @@ -64,17 +63,6 @@ pub use smol::Async as AsyncWrapper; const IMAP_PROTOCOL_TIMEOUT: Duration = Duration::from_secs(60 * 28); -macro_rules! imap_trace { - ($conn:expr, $fmt:literal, $($t:tt)*) => { - #[cfg(debug_assertions)] - log::trace!(std::concat!("{} ", $fmt), $conn.id, $($t)*); - }; - ($conn:expr, $fmt:literal) => { - #[cfg(debug_assertions)] - log::trace!(std::concat!("{} ", $fmt), $conn.id); - }; -} - macro_rules! imap_log { ($fn:ident, $conn:expr, $fmt:literal, $($t:tt)*) => { log::$fn!(std::concat!("{} ", $fmt), $conn.id, $($t)*); @@ -125,7 +113,6 @@ impl Default for ImapExtensionUse { #[derive(Debug)] pub struct ImapStream { pub cmd_id: usize, - #[cfg(debug_assertions)] pub id: Cow<'static, str>, pub stream: AsyncWrapper, pub protocol: ImapProtocol, @@ -152,7 +139,6 @@ async fn try_await(cl: impl Future> + Send) -> Result<()> { #[derive(Debug)] pub struct ImapConnection { - #[cfg(debug_assertions)] pub id: Cow<'static, str>, pub stream: Result, pub server_conf: ImapServerConf, @@ -163,7 +149,7 @@ pub struct ImapConnection { impl ImapStream { pub async fn new_connection( server_conf: &ImapServerConf, - #[cfg(debug_assertions)] id: Cow<'static, str>, + id: Cow<'static, str>, uid_store: &UIDStore, ) -> Result<(Capabilities, Self)> { let path = &server_conf.server_hostname; @@ -310,7 +296,6 @@ impl ImapStream { let mut res = Vec::with_capacity(8 * 1024); let mut ret = Self { cmd_id, - #[cfg(debug_assertions)] id, stream, protocol: server_conf.protocol, @@ -527,7 +512,7 @@ impl ImapStream { } } } - //imap_trace!(self, "returning IMAP response:\n{:?}", &ret); + //imap_log!(trace, self, "returning IMAP response:\n{:?}", &ret); Ok(()) } @@ -548,9 +533,9 @@ impl ImapStream { match self.protocol { ImapProtocol::IMAP { .. } => { if matches!(command.body, CommandBody::Login { .. }) { - imap_trace!(self, "sent: M{} LOGIN ..", self.cmd_id - 1); + imap_log!(trace, self, "sent: M{} LOGIN ..", self.cmd_id - 1); } else { - imap_trace!(self, "sent: M{} {:?}", self.cmd_id - 1, command.body); + imap_log!(trace, self, "sent: M{} {:?}", self.cmd_id - 1, command.body); } } ImapProtocol::ManageSieve => {} @@ -604,11 +589,11 @@ impl ImapStream { match self.protocol { ImapProtocol::IMAP { .. } => { if !command.starts_with(b"LOGIN") { - imap_trace!(self, "sent: M{} {}", self.cmd_id - 1, unsafe { + imap_log!(trace, self, "sent: M{} {}", self.cmd_id - 1, unsafe { std::str::from_utf8_unchecked(command) }); } else { - imap_trace!(self, "sent: M{} LOGIN ..", self.cmd_id - 1); + imap_log!(trace, self, "sent: M{} LOGIN ..", self.cmd_id - 1); } } ImapProtocol::ManageSieve => {} @@ -638,12 +623,11 @@ impl ImapStream { impl ImapConnection { pub fn new_connection( server_conf: &ImapServerConf, - #[cfg(debug_assertions)] id: Cow<'static, str>, + id: Cow<'static, str>, uid_store: Arc, ) -> Self { Self { stream: Err(Error::new("Offline".to_string())), - #[cfg(debug_assertions)] id, server_conf: server_conf.clone(), sync_policy: if *uid_store.keep_offline_cache.lock().unwrap() { @@ -679,9 +663,15 @@ impl ImapConnection { }) .await { - imap_trace!(self, "connect(): connection is probably dead: {:?}", &_err); + imap_log!( + trace, + self, + "connect(): connection is probably dead: {:?}", + &_err + ); } else { - imap_trace!( + imap_log!( + trace, self, "connect(): connection is probably alive, NOOP returned {:?}", &String::from_utf8_lossy(&ret) @@ -689,13 +679,9 @@ impl ImapConnection { return Ok(()); } } - let new_stream = ImapStream::new_connection( - &self.server_conf, - #[cfg(debug_assertions)] - self.id.clone(), - &self.uid_store, - ) - .await; + let new_stream = + ImapStream::new_connection(&self.server_conf, self.id.clone(), &self.uid_store) + .await; if let Err(err) = new_stream.as_ref() { self.uid_store.is_online.lock().unwrap().1 = Err(err.clone()); } else { @@ -769,7 +755,6 @@ impl ImapConnection { ImapResponse::Ok(_) => { let ImapStream { cmd_id, - #[cfg(debug_assertions)] id, stream, protocol, @@ -779,7 +764,6 @@ impl ImapConnection { let stream = stream.into_inner()?; self.stream = Ok(ImapStream { cmd_id, - #[cfg(debug_assertions)] id, stream: AsyncWrapper::new(stream.deflate())?, protocol, @@ -823,7 +807,8 @@ impl ImapConnection { ImapResponse::No(ref _response_code) if required_responses.intersects(RequiredResponses::NO_REQUIRED) => { - imap_trace!( + imap_log!( + trace, self, "Received expected NO response: {:?} {:?}", _response_code, @@ -831,7 +816,8 @@ impl ImapConnection { ); } ImapResponse::No(ref response_code) => { - imap_trace!( + imap_log!( + trace, self, "Received NO response: {:?} {:?}", response_code, @@ -849,7 +835,8 @@ impl ImapConnection { return r.into(); } ImapResponse::Bad(ref response_code) => { - imap_trace!( + imap_log!( + trace, self, "Received BAD response: {:?} {:?}", response_code, @@ -868,12 +855,12 @@ impl ImapConnection { } _ => {} } - /* imap_trace!(self, + /* imap_log!(trace, self, "check every line for required_responses: {:#?}", &required_responses );*/ for l in response.split_rn() { - /* imap_trace!(self, "check line: {}", &l); */ + /* imap_log!(trace, self, "check line: {}", &l); */ if required_responses.check(l) || !self.process_untagged(l).await? { ret.extend_from_slice(l); } @@ -992,7 +979,8 @@ impl ImapConnection { .await?; self.read_response(ret, RequiredResponses::SELECT_REQUIRED) .await?; - imap_trace!( + imap_log!( + trace, self, "{} SELECT response {}", imap_path, @@ -1076,7 +1064,12 @@ impl ImapConnection { self.read_response(ret, RequiredResponses::EXAMINE_REQUIRED) .await?; - imap_trace!(self, "EXAMINE response {}", String::from_utf8_lossy(ret)); + imap_log!( + trace, + self, + "EXAMINE response {}", + String::from_utf8_lossy(ret) + ); let select_response = protocol_parser::select_response(ret).chain_err_summary(|| { format!("Could not parse select response for mailbox {}", imap_path) })?; diff --git a/melib/src/imap/managesieve.rs b/melib/src/imap/managesieve.rs index da49a778..2a6c2c2d 100644 --- a/melib/src/imap/managesieve.rs +++ b/melib/src/imap/managesieve.rs @@ -95,7 +95,6 @@ impl ManageSieveConnection { Ok(Self { inner: ImapConnection::new_connection( &server_conf, - #[cfg(debug_assertions)] "ManageSieveConnection::new()".into(), uid_store, ), diff --git a/melib/src/imap/mod.rs b/melib/src/imap/mod.rs index 483d6c68..76c6cb57 100644 --- a/melib/src/imap/mod.rs +++ b/melib/src/imap/mod.rs @@ -381,7 +381,6 @@ impl MailBackend for ImapType { } }; Ok(Box::pin(async_stream::try_stream! { - #[cfg(debug_assertions)] let id = state.connection.lock().await.id.clone(); { let f = &state.uid_store.mailboxes.lock().await[&mailbox_hash]; @@ -393,7 +392,6 @@ impl MailBackend for ImapType { }; loop { let res = fetch_hlpr(&mut state).await.map_err(|err| { - #[cfg(debug_assertions)] log::trace!("{} fetch_hlpr at stage {:?} err {:?}", id, state.stage, &err); err })?; @@ -476,7 +474,7 @@ impl MailBackend for ImapType { Ok(Box::pin(async move { match timeout(timeout_dur, connection.lock()).await { Ok(mut conn) => { - imap_trace!(conn, "is_online"); + imap_log!(trace, conn, "is_online"); match timeout(timeout_dur, conn.connect()).await { Ok(Ok(())) => Ok(()), Err(err) | Ok(Err(err)) => { @@ -512,7 +510,6 @@ impl MailBackend for ImapType { idle(ImapWatchKit { conn: ImapConnection::new_connection( &server_conf, - #[cfg(debug_assertions)] "watch()::idle".into(), uid_store.clone(), ), @@ -524,7 +521,6 @@ impl MailBackend for ImapType { poll_with_examine(ImapWatchKit { conn: ImapConnection::new_connection( &server_conf, - #[cfg(debug_assertions)] "watch()::poll_with_examine".into(), uid_store.clone(), ), @@ -901,7 +897,8 @@ impl MailBackend for ImapType { conn.send_command(CommandBody::Expunge).await?; conn.read_response(&mut response, RequiredResponses::empty()) .await?; - imap_trace!( + imap_log!( + trace, conn, "EXPUNGE response: {}", &String::from_utf8_lossy(&response) @@ -1227,7 +1224,8 @@ impl MailBackend for ImapType { .await?; conn.read_response(&mut response, RequiredResponses::SEARCH) .await?; - imap_trace!( + imap_log!( + trace, conn, "searching for {} returned: {}", query_str, @@ -1323,12 +1321,8 @@ impl ImapType { server_conf.timeout, ) }); - let connection = ImapConnection::new_connection( - &server_conf, - #[cfg(debug_assertions)] - "ImapType::new".into(), - uid_store.clone(), - ); + let connection = + ImapConnection::new_connection(&server_conf, "ImapType::new".into(), uid_store.clone()); Ok(Box::new(Self { server_conf, @@ -1341,7 +1335,6 @@ impl ImapType { pub fn shell(&mut self) { let mut conn = ImapConnection::new_connection( &self.server_conf, - #[cfg(debug_assertions)] "ImapType::shell".into(), self.uid_store.clone(), ); @@ -1389,7 +1382,7 @@ impl ImapType { if input.trim() == "IDLE" { let mut iter = ImapBlockingConnection::from(conn); while let Some(line) = iter.next() { - imap_trace!("out: {}", unsafe { std::str::from_utf8_unchecked(&line) }); + imap_log!(trace, "out: {}", unsafe { std::str::from_utf8_unchecked(&line) }); } conn = iter.into_conn(); } @@ -1428,7 +1421,7 @@ impl ImapType { conn.read_response(&mut res, RequiredResponses::LIST_REQUIRED) .await?; } - imap_trace!(conn, "LIST reply: {}", String::from_utf8_lossy(&res)); + imap_log!(trace, conn, "LIST reply: {}", String::from_utf8_lossy(&res)); for l in res.split_rn() { if !l.starts_with(b"*") { continue; @@ -1470,14 +1463,14 @@ impl ImapType { } } } else { - imap_trace!(conn, "parse error for {:?}", l); + imap_log!(trace, conn, "parse error for {:?}", l); } } mailboxes.retain(|_, v| !v.hash.is_null()); conn.send_command(CommandBody::lsub("", "*")?).await?; conn.read_response(&mut res, RequiredResponses::LSUB_REQUIRED) .await?; - imap_trace!(conn, "LSUB reply: {}", String::from_utf8_lossy(&res)); + imap_log!(trace, conn, "LSUB reply: {}", String::from_utf8_lossy(&res)); for l in res.split_rn() { if !l.starts_with(b"*") { continue; @@ -1492,7 +1485,7 @@ impl ImapType { f.is_subscribed = true; } } else { - imap_trace!(conn, "parse error for {:?}", l); + imap_log!(trace, conn, "parse error for {:?}", l); } } Ok(mailboxes) @@ -1624,7 +1617,8 @@ struct FetchState { } async fn fetch_hlpr(state: &mut FetchState) -> Result> { - imap_trace!( + imap_log!( + trace, state.connection.lock().await, "fetch_hlpr mailbox: {:?} stage: {:?}", state.mailbox_hash, @@ -1686,7 +1680,8 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { } Ok(Some(cached_payload)) => { state.stage = FetchStage::ResyncCache; - imap_trace!( + imap_log!( + trace, state.connection.lock().await, "fetch_hlpr fetch_cached_envs payload {} len for mailbox_hash {}", cached_payload.len(), @@ -1758,7 +1753,13 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { conn.examine_mailbox(mailbox_hash, &mut response, false) .await?; if max_uid_left > 0 { - imap_trace!(conn, "{} max_uid_left= {}", mailbox_hash, max_uid_left); + imap_log!( + trace, + conn, + "{} max_uid_left= {}", + mailbox_hash, + max_uid_left + ); let sequence_set = if max_uid_left == 1 { SequenceSet::from(ONE) } else { @@ -1782,7 +1783,8 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { ) })?; let (_, mut v, _) = protocol_parser::fetch_responses(&response)?; - imap_trace!( + imap_log!( + trace, conn, "fetch response is {} bytes and {} lines and has {} parsed Envelopes", response.len(), @@ -1799,7 +1801,8 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { } in v.iter_mut() { if uid.is_none() || envelope.is_none() || flags.is_none() { - imap_trace!( + imap_log!( + trace, conn, "BUG? something in fetch is none. UID: {:?}, envelope: {:?} \ flags: {:?}", @@ -1807,7 +1810,8 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { envelope, flags ); - imap_trace!( + imap_log!( + trace, conn, "response was: {}", String::from_utf8_lossy(&response) @@ -1861,7 +1865,7 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { let uid = uid.unwrap(); let env = envelope.unwrap(); /* - imap_trace!( + imap_log!(trace, "env hash {} {} UID = {} MSN = {}", env.hash(), env.subject(), diff --git a/melib/src/imap/untagged.rs b/melib/src/imap/untagged.rs index 35d8e632..e149a6b2 100644 --- a/melib/src/imap/untagged.rs +++ b/melib/src/imap/untagged.rs @@ -46,7 +46,7 @@ impl ImapConnection { ($mailbox_hash: expr, $($result:expr $(,)*)+) => { $(if let Err(err) = $result { self.uid_store.is_online.lock().unwrap().1 = Err(err.clone()); - imap_trace!(self, "failure: {}", err.to_string()); + imap_log!(trace, self, "failure: {}", err.to_string()); log::debug!("failure: {}", err.to_string()); self.add_refresh_event(RefreshEvent { account_hash: self.uid_store.account_hash, @@ -176,7 +176,7 @@ impl ImapConnection { .entry(mailbox_hash) .or_default() .remove(TryInto::::try_into(n).unwrap().saturating_sub(1)); - imap_trace!(self, "expunge {}, UID = {}", n, deleted_uid); + imap_log!(trace, self, "expunge {}, UID = {}", n, deleted_uid); let deleted_hash: crate::email::EnvelopeHash = match self .uid_store .uid_index @@ -224,7 +224,7 @@ impl ImapConnection { } } UntaggedResponse::Exists(n) => { - imap_trace!(self, "exists {}", n); + imap_log!(trace, self, "exists {}", n); try_fail!( mailbox_hash, self.send_command(CommandBody::fetch(n, common_attributes(), false)?).await @@ -233,7 +233,8 @@ impl ImapConnection { let mut v = match super::protocol_parser::fetch_responses(&response) { Ok((_, v, _)) => v, Err(err) => { - imap_trace!( + imap_log!( + trace, self, "Error when parsing FETCH response after untagged exists {:?}", err @@ -241,7 +242,7 @@ impl ImapConnection { return Ok(true); } }; - imap_trace!(self, "responses len is {}", v.len()); + imap_log!(trace, self, "responses len is {}", v.len()); for FetchResponse { ref uid, ref mut envelope, @@ -297,7 +298,8 @@ impl ImapConnection { .lock() .unwrap() .insert((mailbox_hash, uid), env.hash()); - imap_trace!( + imap_log!( + trace, self, "Create event {} {} {}", env.hash(), @@ -343,7 +345,7 @@ impl ImapConnection { .map_err(Error::from) { Ok(&[]) => { - imap_trace!(self, "UID SEARCH RECENT returned no results"); + imap_log!(trace, self, "UID SEARCH RECENT returned no results"); } Ok(v) => { let command = { @@ -377,7 +379,7 @@ impl ImapConnection { return Ok(true); } }; - imap_trace!(self, "responses len is {}", v.len()); + imap_log!(trace, self, "responses len is {}", v.len()); for FetchResponse { ref uid, ref mut envelope,