✨ feat(cli): implement trash and delete actions
- add processor struct to handle gmail api interactions - implement trash_messages and delete_messages functions in processor - integrate processor into run_cli to perform actions on messages
This commit is contained in:
committed by
Jeremiah Russell
parent
629c9d2e46
commit
1c2e2da031
@@ -1,5 +1,5 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cull_gmail::{Config, EolAction, Result};
|
use cull_gmail::{Config, EolAction, Processor, Result};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct RunCli {}
|
pub struct RunCli {}
|
||||||
@@ -16,14 +16,32 @@ impl RunCli {
|
|||||||
|
|
||||||
log::info!("Executing rule `#{}` for label `{label}`", rule.describe());
|
log::info!("Executing rule `#{}` for label `{label}`", rule.describe());
|
||||||
|
|
||||||
let Some(action) = rule.action() else {
|
let processor = Processor::new(config.credential_file(), rule);
|
||||||
|
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
EolAction::Trash => log::info!("trashing older messages"),
|
EolAction::Trash => {
|
||||||
EolAction::Delete => log::info!("deleting older messages"),
|
log::info!("trashing older messages");
|
||||||
|
match processor.trash_messages(&label).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("action failed for label {label} with error {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EolAction::Delete => {
|
||||||
|
log::info!("deleting older messages");
|
||||||
|
match processor.delete_messages(&label).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("action failed for label {label} with error {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user