Skip to content

Commit dc41101

Browse files
gortavoherjerusdp
authored andcommitted
♻️ refactor(rules): execute rules by action
- executes rules by action: `Trash` first, then `Delete` - a label may have a `trash` and `delete` rule applied
1 parent 0d670d3 commit dc41101

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/cli/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,13 @@ fn get_config() -> Result<(Config, ClientConfig)> {
452452
))
453453
}
454454

455-
/// Executes automated message retention rules across Gmail labels.
455+
/// Executes automated message retention rules across Gmail labels by action.
456456
///
457457
/// This function orchestrates the rule-based message processing workflow by:
458-
/// 1. Organizing rules by their target labels
459-
/// 2. Processing each label according to its configured rule
460-
/// 3. Executing or simulating actions based on execution mode
458+
/// 1. Executing rules by action: `Trash` first, then `Delete`
459+
/// 2. Organizing rules by their target labels
460+
/// 3. Processing each label according to its configured rule
461+
/// 4. Executing or simulating actions based on execution mode
461462
///
462463
/// # Arguments
463464
///
@@ -506,6 +507,7 @@ async fn run_rules(client: &mut GmailClient, rules: Rules, execute: bool) -> Res
506507
/// * `client` - Mutable Gmail client for API operations
507508
/// * `rules` - Loaded rules configuration containing all retention policies
508509
/// * `execute` - Whether to actually perform actions (true) or dry-run (false)
510+
/// * `action` - The action the rule will execute
509511
///
510512
/// # Returns
511513
///

src/rules.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ impl Rules {
247247
self.rules.values().flat_map(|rule| rule.labels()).collect()
248248
}
249249

250-
/// Find the id of the rule that contains a label
250+
/// Find the ids of the rules that contains a label
251+
///
252+
/// A label may have a `trash` and `delete` rule applied to return a
253+
/// maximum of two rules.
254+
///
255+
/// If a label has more than one `trash` or `delete` rules only the id
256+
/// for the last rule will be returned.
251257
fn find_label(&self, label: &str) -> Vec<usize> {
252258
let mut rwl = Vec::new();
253259

0 commit comments

Comments
 (0)