🐛 fix(cli): fix rule execution and client handling
- modify the `run` function to accept a mutable `GmailClient` reference - set the rule and execute flag on the client before executing the action - remove the `RuleProcessor` and directly use the `GmailClient` for actions - this simplifies the code and ensures the client is properly configured for each rule
This commit is contained in:
committed by
Jeremiah Russell
parent
4eea2c6135
commit
35235afc26
@@ -15,7 +15,7 @@ pub struct RunCli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RunCli {
|
impl RunCli {
|
||||||
pub async fn run(&self, client: &GmailClient, config: Config) -> Result<()> {
|
pub async fn run(&self, client: &mut GmailClient, config: Config) -> Result<()> {
|
||||||
let rules = config.get_rules_by_label();
|
let rules = config.get_rules_by_label();
|
||||||
|
|
||||||
for label in config.labels() {
|
for label in config.labels() {
|
||||||
@@ -25,32 +25,26 @@ impl RunCli {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log::info!("Executing rule `#{}` for label `{label}`", rule.describe());
|
log::info!("Executing rule `#{}` for label `{label}`", rule.describe());
|
||||||
|
client.set_rule(rule.clone());
|
||||||
|
client.set_execute(self.execute);
|
||||||
|
|
||||||
let mut builder = RuleProcessor::builder(client, rule);
|
let Some(action) = client.action() else {
|
||||||
let processor = builder.set_execute(self.execute).build();
|
|
||||||
|
|
||||||
let Some(action) = processor.action() else {
|
|
||||||
log::warn!("no valid action specified for rule #{}", rule.id());
|
log::warn!("no valid action specified for rule #{}", rule.id());
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.execute_action(processor, action, &label).await;
|
self.execute_action(client, action, &label).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execute_action<'a>(
|
async fn execute_action(&self, client: &mut GmailClient, action: EolAction, label: &str) {
|
||||||
&self,
|
|
||||||
processor: RuleProcessor<'a>,
|
|
||||||
action: EolAction,
|
|
||||||
label: &str,
|
|
||||||
) {
|
|
||||||
match action {
|
match action {
|
||||||
EolAction::Trash => {
|
EolAction::Trash => {
|
||||||
if !self.skip_trash {
|
if !self.skip_trash {
|
||||||
log::info!("trashing older messages");
|
log::info!("trashing older messages");
|
||||||
match processor.trash_messages(label).await {
|
match client.trash_messages(label).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("action failed for label {label} with error {e}");
|
log::warn!("action failed for label {label} with error {e}");
|
||||||
@@ -63,7 +57,7 @@ impl RunCli {
|
|||||||
EolAction::Delete => {
|
EolAction::Delete => {
|
||||||
if !self.skip_delete {
|
if !self.skip_delete {
|
||||||
log::info!("deleting older messages");
|
log::info!("deleting older messages");
|
||||||
match processor.delete_messages(label).await {
|
match client.delete_messages(label).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("action failed for label {label} with error {e}");
|
log::warn!("action failed for label {label} with error {e}");
|
||||||
|
|||||||
Reference in New Issue
Block a user