From 739176048e81332b9d32e12f339c83855912991d Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Tue, 14 Oct 2025 06:46:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(core):=20remove?= =?UTF-8?q?=20processor.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove unused processor.rs file --- src/processor.rs | 163 ----------------------------------------------- 1 file changed, 163 deletions(-) delete mode 100644 src/processor.rs diff --git a/src/processor.rs b/src/processor.rs deleted file mode 100644 index 91014b8..0000000 --- a/src/processor.rs +++ /dev/null @@ -1,163 +0,0 @@ -use crate::{ - EolAction, Error, GmailClient, Result, config::EolRule, delete::Delete, - message_list::MessageList, trash::Trash, -}; - -// /// Rule processor -// #[derive()] -// pub struct Processor<'a> { -// client: GmailClient, -// rule: &'a EolRule, -// execute: bool, -// } - -// impl<'a> fmt::Debug for Processor<'a> { -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -// f.debug_struct("Processor") -// .field("rule", &self.rule) -// .field("execute", &self.execute) -// .finish() -// } -// } - -// /// Rule processor builder -// #[derive()] -// pub struct ProcessorBuilder<'a> { -// client: GmailClient, -// rule: &'a EolRule, -// execute: bool, -// } - -// impl<'a> fmt::Debug for ProcessorBuilder<'a> { -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -// f.debug_struct("ProcessorBuilder") -// .field("rule", &self.rule) -// .field("execute", &self.execute) -// .finish() -// } -// } - -// impl<'a> ProcessorBuilder<'a> { -// /// Set the execute flag -// pub fn set_execute(&mut self, value: bool) -> &mut Self { -// self.execute = value; -// self -// } - -// /// Build the Processor -// pub fn build(&'_ self) -> Processor<'_> { -// Processor { -// client: self.client.clone(), -// rule: self.rule, -// execute: self.execute, -// } -// } -// } - -/// Rules processor to apply the configured rules to the mailbox. -pub trait RuleProcessor { - /// Set the execute flag in the client - fn set_execute(&mut self, value: bool); - /// Delete messages - fn delete_messages( - &mut self, - label: &str, - ) -> impl std::future::Future> + Send; - /// Trash Messages - fn trash_messages( - &mut self, - label: &str, - ) -> impl std::future::Future> + Send; - /// Set rule to process - fn set_rule(&mut self, action: EolRule); - /// Report the action from the rule - fn action(&self) -> Option; -} - -impl RuleProcessor for GmailClient { - // /// Initialise a new processor - // pub fn builder(client: &GmailClient, rule: &'a EolRule) -> ProcessorBuilder<'a> { - // ProcessorBuilder { - // client: client.clone(), - // rule, - // execute: false, - // } - // } - - /// Add Action to the Client for processing - fn set_rule(&mut self, value: EolRule) { - self.rule = Some(value); - } - - /// Set the execute flag - fn set_execute(&mut self, value: bool) { - self.execute = value; - } - - /// The action set in the rule - fn action(&self) -> Option { - if let Some(rule) = &self.rule { - return rule.action(); - } - None - } - - /// Trash the messages - async fn trash_messages(&mut self, label: &str) -> Result<()> { - self.add_labels(&[label.to_string()]).await?; - - if self.label_ids().is_empty() { - return Err(Error::LabelNotFoundInMailbox(label.to_string())); - } - - let Some(rule) = &self.rule else { - return Err(Error::RuleNotFound(0)); - }; - - let Some(query) = rule.eol_query() else { - return Err(Error::NoQueryStringCalculated(rule.id())); - }; - self.set_query(&query); - - log::info!("{:?}", self.messages()); - log::info!("Ready to run"); - self.prepare(0).await?; - if self.execute { - log::info!("***executing final delete messages***"); - self.batch_trash().await - } else { - log::warn!("Execution stopped for dry run"); - Ok(()) - } - } - - /// Delete the messages - async fn delete_messages(&mut self, label: &str) -> Result<()> { - self.add_labels(&[label.to_string()]).await?; - - if self.label_ids().is_empty() { - return Err(Error::LabelNotFoundInMailbox(label.to_string())); - } - - let Some(rule) = &self.rule else { - return Err(Error::RuleNotFound(0)); - }; - - let Some(query) = rule.eol_query() else { - return Err(Error::NoQueryStringCalculated(rule.id())); - }; - self.set_query(&query); - - log::info!("{:?}", self.messages()); - log::info!("Ready to run"); - self.prepare(0).await?; - if self.execute { - log::info!("***executing final delete messages***"); - self.batch_delete().await - } else { - log::warn!("Execution stopped for dry run"); - - Ok(()) - } - } -}