From e106455953e69cf1b0c19ac947a5ba1712d111b4 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Sat, 25 Oct 2025 22:45:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(message=5Flist):?= =?UTF-8?q?=20allow=20pre/post=20text=20in=20log=5Fmessages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - allow `log_messages` to take `pre` and `post` parameters - this will allow calling functions to format the log output - add documentation for parameters --- src/message_list.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/message_list.rs b/src/message_list.rs index 8dedbc2..fd84166 100644 --- a/src/message_list.rs +++ b/src/message_list.rs @@ -95,6 +95,11 @@ pub trait MessageList { /// This method retrieves the subject line and date for each message currently /// stored in the message list and outputs them to the log. /// + /// # Parameters + /// + /// - `pre` text to display before the date/subject message identifier + /// - `post` text to display after the date/subject message identifier + /// /// # Returns /// /// Returns `Result<()>` on success, or an error if the Gmail API request fails. @@ -106,7 +111,11 @@ pub trait MessageList { /// - Authentication credentials are invalid or expired /// - Network connectivity issues occur /// - Individual message retrieval fails - fn log_messages(&mut self) -> impl std::future::Future> + Send; + fn log_messages( + &mut self, + pre: &str, + post: &str, + ) -> impl std::future::Future> + Send; /// Retrieves a list of messages from Gmail based on current filter settings. /// @@ -543,13 +552,13 @@ impl MessageList for GmailClient { Ok(list) } - async fn log_messages(&mut self) -> Result<()> { + async fn log_messages(&mut self, pre: &str, post: &str) -> Result<()> { for i in 0..self.messages.len() { let id = self.messages[i].id().to_string(); log::trace!("{id}"); let m = self.get_message_metadata(&id).await?; let message = &mut self.messages[i]; - + log::trace!("Got the message: {m:?}"); let Some(payload) = m.payload else { continue }; let Some(headers) = payload.headers else { continue; @@ -566,8 +575,7 @@ impl MessageList for GmailClient { continue; } } - - log::info!("{}", message.list_date_and_subject()); + log::info!("{pre}{}{post}", message.list_date_and_subject()); } Ok(()) @@ -601,7 +609,7 @@ mod tests { } impl MessageList for MockList { - async fn log_messages(&mut self) -> Result<()> { + async fn log_messages(&mut self, _pre: &str, _post: &str) -> Result<()> { Ok(()) } async fn list_messages( @@ -761,7 +769,7 @@ mod tests { Ok(list) } - async fn log_messages(&mut self) -> Result<()> { + async fn log_messages(&mut self, _pre: &str, _post: &str) -> Result<()> { Ok(()) } } @@ -770,7 +778,7 @@ mod tests { fn set_query_updates_state() { let mut ml = MockList::new(); ml.set_query("from:noreply@example.com"); - // not directly accessible; rely on behavior by calling again + // not directly accessible; rely on behaviour by calling again ml.set_query("is:unread"); assert_eq!(ml.query, "is:unread"); }