pub trait RuleProcessor {
// Required methods
fn find_rule_and_messages_for_label(
&mut self,
label: &str,
) -> impl Future<Output = Result<()>> + Send;
fn set_execute(&mut self, value: bool);
fn initialise_lists(&mut self);
fn set_rule(&mut self, rule: EolRule);
fn action(&self) -> Option<EolAction>;
fn prepare(&mut self, pages: u32) -> impl Future<Output = Result<()>> + Send;
fn batch_delete(&mut self) -> impl Future<Output = Result<()>> + Send;
fn batch_trash(&mut self) -> impl Future<Output = Result<()>> + Send;
fn process_in_chunks(
&self,
message_ids: Vec<String>,
action: EolAction,
) -> impl Future<Output = Result<()>> + Send;
fn call_batch_delete(
&self,
ids: &[String],
) -> impl Future<Output = Result<()>> + Send;
fn call_batch_trash(
&self,
ids: &[String],
) -> impl Future<Output = Result<()>> + Send;
}Expand description
Trait for processing Gmail messages according to configured end-of-life rules.
This trait defines the interface for finding, filtering, and acting upon Gmail messages based on retention rules. Implementations should handle the complete workflow from rule application to message processing.
Required Methods§
Sourcefn find_rule_and_messages_for_label(
&mut self,
label: &str,
) -> impl Future<Output = Result<()>> + Send
fn find_rule_and_messages_for_label( &mut self, label: &str, ) -> impl Future<Output = Result<()>> + Send
Processes all messages for a specific Gmail label according to the configured rule.
This is the main entry point for rule processing. It coordinates the entire workflow:
- Validates that the label exists in the mailbox
- Applies the rule’s query to find matching messages
- Prepares the message list for processing
- Executes the rule’s action (if execute flag is true) or runs in dry-run mode
§Arguments
label- The Gmail label name to process (e.g., “INBOX”, “old-emails”)
§Returns
Ok(())- Processing completed successfullyErr(Error::LabelNotFoundInMailbox)- The specified label doesn’t existErr(Error::RuleNotFound)- No rule has been set viaset_ruleErr(Error::NoQueryStringCalculated)- The rule doesn’t provide a valid query
§Side Effects
When execute flag is true, messages may be moved to trash or permanently deleted. When execute flag is false, runs in dry-run mode with no destructive actions.
Sourcefn set_execute(&mut self, value: bool)
fn set_execute(&mut self, value: bool)
Sets the execution mode for destructive operations.
§Arguments
value-trueto enable destructive operations,falsefor dry-run mode
§Safety
When set to true, subsequent calls to processing methods will perform actual
destructive operations on Gmail messages. Always verify your rules and queries
in dry-run mode (false) before enabling execution.
Sourcefn initialise_lists(&mut self)
fn initialise_lists(&mut self)
Initialises the message and label lists to prepare for application of rule.
§Arguments
- none
§Example
use cull_gmail::{GmailClient, RuleProcessor, ClientConfig};
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::builder()
.with_client_id("your-client-id")
.with_client_secret("your-client-secret")
.build();
let mut client = GmailClient::new_with_config(config).await?;
// Rules would typically be loaded from configuration
// let rule = load_rule_from_config();
// client.initialise_message_list();
// client.set_rule(rule);
Ok(())
}Sourcefn set_rule(&mut self, rule: EolRule)
fn set_rule(&mut self, rule: EolRule)
Configures the end-of-life rule to apply during processing.
§Arguments
rule- TheEolRulecontaining query criteria and action to perform
§Example
use cull_gmail::{GmailClient, RuleProcessor, ClientConfig};
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::builder()
.with_client_id("your-client-id")
.with_client_secret("your-client-secret")
.build();
let mut client = GmailClient::new_with_config(config).await?;
// Rules would typically be loaded from configuration
// let rule = load_rule_from_config();
// client.set_rule(rule);
Ok(())
}Sourcefn prepare(&mut self, pages: u32) -> impl Future<Output = Result<()>> + Send
fn prepare(&mut self, pages: u32) -> impl Future<Output = Result<()>> + Send
Prepares the list of messages for processing by fetching them from Gmail.
This method queries the Gmail API to retrieve messages matching the current query and label filters, up to the specified number of pages.
§Arguments
pages- Maximum number of result pages to fetch (0 = all pages)
§Returns
Ok(())- Messages successfully retrieved and preparedErr(_)- Gmail API error or network failure
§Side Effects
Makes API calls to Gmail to retrieve message metadata. No messages are modified by this operation.
Sourcefn batch_delete(&mut self) -> impl Future<Output = Result<()>> + Send
fn batch_delete(&mut self) -> impl Future<Output = Result<()>> + Send
Permanently deletes all prepared messages from Gmail.
§Returns
Ok(())- All messages successfully deletedErr(_)- Gmail API error, network failure, or insufficient permissions
§Safety
⚠️ DESTRUCTIVE OPERATION - This permanently removes messages from Gmail.
Deleted messages cannot be recovered. Use batch_trash
for recoverable deletion.
§Gmail API Requirements
Requires the https://mail.google.com/ scope.
Sourcefn batch_trash(&mut self) -> impl Future<Output = Result<()>> + Send
fn batch_trash(&mut self) -> impl Future<Output = Result<()>> + Send
Calls the Gmail API to move a slice of the prepared messages to the Gmail trash folder.
Messages moved to trash can be recovered within 30 days through the Gmail web interface or API calls.
§Returns
Ok(())- All messages successfully moved to trashErr(_)- Gmail API error, network failure, or insufficient permissions
§Recovery
Messages can be recovered from trash within 30 days. After 30 days, Gmail automatically purges trashed messages.
§Gmail API Requirements
Requires the https://www.googleapis.com/auth/gmail.modify scope.
Sourcefn process_in_chunks(
&self,
message_ids: Vec<String>,
action: EolAction,
) -> impl Future<Output = Result<()>> + Send
fn process_in_chunks( &self, message_ids: Vec<String>, action: EolAction, ) -> impl Future<Output = Result<()>> + Send
Chunk the message lists to respect API limits and call required action.
§Returns
Ok(())- All messages successfully deletedErr(_)- Gmail API error, network failure, or insufficient permissions
Sourcefn call_batch_delete(
&self,
ids: &[String],
) -> impl Future<Output = Result<()>> + Send
fn call_batch_delete( &self, ids: &[String], ) -> impl Future<Output = Result<()>> + Send
Calls the Gmail API to permanently deletes a slice from the list of messages.
§Returns
Ok(())- All messages successfully deletedErr(_)- Gmail API error, network failure, or insufficient permissions
§Safety
⚠️ DESTRUCTIVE OPERATION - This permanently removes messages from Gmail.
Deleted messages cannot be recovered. Use batch_trash
for recoverable deletion.
§Gmail API Requirements
Requires the https://mail.google.com/ scope.
Sourcefn call_batch_trash(
&self,
ids: &[String],
) -> impl Future<Output = Result<()>> + Send
fn call_batch_trash( &self, ids: &[String], ) -> impl Future<Output = Result<()>> + Send
Moves all prepared messages to the Gmail trash folder.
Messages moved to trash can be recovered within 30 days through the Gmail web interface or API calls.
§Returns
Ok(())- All messages successfully moved to trashErr(_)- Gmail API error, network failure, or insufficient permissions
§Recovery
Messages can be recovered from trash within 30 days. After 30 days, Gmail automatically purges trashed messages.
§Gmail API Requirements
Requires the https://www.googleapis.com/auth/gmail.modify scope.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.