Commit Graph

422 Commits

Author SHA1 Message Date
Jeremiah Russell
209b8a6a46 feat(cli): restructure rules config CLI
- 【Refactor】Move label subcommands (add, list, remove) into separate modules for better organization
- 【Refactor】Rename `LabelCli` to `ListLabelCli`, `AddCli` to `AddLabelCli`, and `RemoveCli` to `RemoveLabelCli`
- 【Refactor】Rename `LabelCommands` to `List`, `Add`, and `Remove`
- 【Refactor】Rename `remove-rule` alias to `rm-rule` and `remove-label` alias to `rm-label`
- 【Feat】Add `ListLabelCli`, `AddLabelCli`, and `RemoveLabelCli` to handle label-related operations
- 【Feat】Update `ConfigCli` to use the new label subcommands and modules
- 【Remove】Remove the `label_cli.rs` file as its functionality is now distributed
2025-10-31 14:42:32 +00:00
Jeremiah Russell
9773327e86 ♻️ refactor(cli): rename rule management subcommands for clarity
- rename `add`, `rm`, and `action` subcommands to `add-rule`, `remove-rule`, and `set-action-on-rule` respectively to improve clarity
- update corresponding modules and structs to reflect the renaming, enhancing code readability and maintainability
2025-10-31 14:42:32 +00:00
Jeremiah Russell
b10dcbf8a9 feat(cli): enhance rules configuration
- introduce subcommands for listing, adding, and removing rules
- improve cli structure for better user experience
2025-10-31 12:03:15 +00:00
Jeremiah Russell
a512792774 🐛 fix(client): fix config root parsing
- add debug logging for configurations to aid in troubleshooting
2025-10-31 11:03:38 +00:00
Jeremiah Russell
bf8d1c3cf4 feat(cli): add optional rules path argument to cli
- allow users to specify a rules file path via command line argument
- update run_with_rules_path to prioritize cli argument over config file
2025-10-31 09:40:30 +00:00
Jeremiah Russell
87e9e47395 🐛 fix(rule_processor): enhance logging for chunk processing
- change trace logs to info logs for chunk processing in rule_processor
- improve visibility of chunk processing status and debugging
2025-10-30 13:46:19 +00:00
Jeremiah Russell
e9eccb6ef6 🐛 fix(cli): correct rule execution order for trash and delete
- correct the order of rule execution to delete before trashing
- trashed messages will not be deleted
2025-10-30 13:36:40 +00:00
Jeremiah Russell
dc41101dcb ♻️ refactor(rules): execute rules by action
- executes rules by action: `Trash` first, then `Delete`
- a label may have a `trash` and `delete` rule applied
2025-10-30 12:26:12 +00:00
Jeremiah Russell
cb53faf3b3 feat(rules): support multiple actions per label
- support trash and delete actions for the same label
- add `run_rules_for_action` function to filter rules by action
- update `get_rules_by_label` to `get_rules_by_label_for_action`
- update `find_label` to return a vector of rule ids
- update `remove_rule_by_label` to remove all rules with the label
2025-10-30 12:26:12 +00:00
Jeremiah Russell
afe798dae0 📝 docs(rule_processor): clarify Gmail API scope requirement
- refine the documentation for batch_delete and call_batch_delete functions
- specify the exact `https://mail.google.com/` scope needed
2025-10-30 10:40:29 +00:00
Jeremiah Russell
cc57a6aec8 ♻️ refactor(gmail): consolidate batch processing logic
- introduce process_in_chunks for DRY principle
- remove redundant chunking logic from batch_delete
- update documentation for API scope requirements
2025-10-30 10:40:29 +00:00
Jeremiah Russell
fc85f46e80 ♻️ refactor(rule_processor): enhance Gmail message handling with chunk processing
- introduce `process_in_chunks` for batch operations to respect API limits
- refactor `batch_trash` to use `process_in_chunks` for efficient trashing
- add documentation for `process_in_chunks` explaining chunking and API limits
2025-10-30 10:40:29 +00:00
Jeremiah Russell
01c337d94c 📝 docs(rules): clarify scope usage for Gmail operations
- correct grammar in scope description
2025-10-30 10:40:29 +00:00
Jeremiah Russell
23ea5a82b0 feat(rule_processor): implement batch operations for message deletion and trashing
- introduce `call_batch_delete` to permanently delete messages in chunks
- introduce `call_batch_trash` to move messages to trash in chunks
- refactor `batch_delete` and `batch_trash` to use chunking for large lists
- add constants for `INBOX_LABEL` for clarity
- update documentation to reflect the new chunking approach and api requirements
2025-10-30 10:40:29 +00:00
Jeremiah Russell
83a5c45cb5 🐛 fix(gmail): use GMAIL_DELETE_SCOPE for batch delete
- use GMAIL_DELETE_SCOPE instead of GMAIL_MODIFY_SCOPE for batch delete operation
- GMAIL_DELETE_SCOPE is required for batch delete to work
2025-10-29 13:56:02 +00:00
Jeremiah Russell
a3623d560d 🐛 fix(cli): correct logging level
- remove redundant check for logging level
2025-10-29 13:51:18 +00:00
Jeremiah Russell
357da7f23b 🐛 fix(eol_rule): correct calculate_for_date and add logging
- Fix the EOL date calculation by using checked_sub_signed to prevent panics
- Add debug logging to track message age, delta, and deadline calculations
- Corrected test case to account for new calculation and added logger to test
2025-10-29 13:51:18 +00:00
Jeremiah Russell
4f87647339 🐛 fix(rules): correct grammar and improve date calculation
- correct a grammatical error in a comment
- add logging for debugging date calculations
- add a new test case for 1032 days to ensure correct calculation
2025-10-29 13:51:18 +00:00
Jeremiah Russell
f493dfae04 🐛 fix(gmail): handle batch delete errors
- fix batch delete failure by logging the response before returning
- handle batch delete errors and prevent program termination
2025-10-29 07:20:20 +00:00
Jeremiah Russell
bf65721cec ♻️ refactor(core): rename initialise_message_list to initialise_lists
- rename initialise_message_list to initialise_lists for clarity
- update all references to the function with the new name
- the function now initialises both message and label lists
2025-10-28 16:50:30 +00:00
Jeremiah Russell
4749e83cf3 feat(rule_processor): add initialise_message_list to processor
- add initialise_message_list fn to RuleProcessor trait and impl
- ensure rule is only processed on in-scope messages
- call initialise_message_list before processing any labels
2025-10-28 16:37:31 +00:00
Jeremiah Russell
03b6bdfaa6 📝 docs(cli): improve config subcommand documentation
- clarify the purpose of the config subcommand
- correct spelling error: "behaviour"
2025-10-25 22:58:36 +01:00
Jeremiah Russell
dcfae4517b 🐛 fix(cli): fix log messages with empty arguments
- fix log messages with empty arguments
2025-10-25 22:58:36 +01:00
Jeremiah Russell
50335ca38e 🐛 fix(cli): prevent dry-run from crashing
- prevent dry-run crashing by calling log messages function
2025-10-25 22:58:36 +01:00
Jeremiah Russell
50beaeaef4 🐛 fix(rule_processor): fix batch_trash and batch_delete signatures
- change &self to &mut self for batch_trash and batch_delete functions
- add logging for messages being trashed and deleted
2025-10-25 22:58:36 +01:00
Jeremiah Russell
e106455953 ♻️ refactor(message_list): allow pre/post text in log_messages
- allow `log_messages` to take `pre` and `post` parameters
- this will allow calling functions to format the log output
- add documentation for parameters
2025-10-25 22:58:36 +01:00
Jeremiah Russell
f07f0e8f5b 🐛 fix(config): reduce log verbosity
- change log level from info to trace to reduce verbosity
2025-10-23 13:00:21 +01:00
Jeremiah Russell
6d24a0175c feat(cli): add token and auth uri config options
- allow users to configure token_uri and auth_uri in config file
- add default values for token_uri and auth_uri
2025-10-23 12:09:04 +01:00
Jeremiah Russell
e33c0320a0 Add unit tests for --skip-rules functionality 2025-10-23 11:16:25 +01:00
Jeremiah Russell
c39e64f0ac Implement core logic for --skip-rules in init 2025-10-23 11:16:25 +01:00
Jeremiah Russell
0b24767065 Add --skip-rules flag to init command 2025-10-23 11:16:25 +01:00
Jeremiah Russell
05b4a968f7 🐛 fix(config): improve config logging format
- use pretty format for config logging to enhance readability
2025-10-23 07:37:30 +01:00
Jeremiah Russell
89fce9792e feat(config): load application secret with logging
- add logging to indicate the source of the application secret
- log the configuration root to aid in debugging credential file loading
2025-10-23 06:52:46 +01:00
Jeremiah Russell
c1f7cf859a 🐛 fix(cli): load config file only if it exists
- only load config file if it exists
- prevents error when config file is not present
2025-10-22 17:35:43 +01:00
Jeremiah Russell
2af6df145f 🐛 fix(cli): fix config file loading
- remove unnecessary config_file.required(false)
2025-10-22 17:35:43 +01:00
Jeremiah Russell
825f2de316 🐛 fix(client_config): print config for debugging
- add log to print config for debugging
2025-10-22 17:35:43 +01:00
Jeremiah Russell
4aef4608fc feat(cli): enhance configuration loading with logging
- add logging to display the config file being loaded
2025-10-22 17:35:43 +01:00
Jeremiah Russell
3112e23040 🐛 fix(cli): correct spelling errors in documentation
- correct spelling of "behaviour" to "behavior"
- correct spelling of "dry-run mode"
2025-10-22 17:35:43 +01:00
Jeremiah Russell
60d37dfc41 🐛 fix(cli): load config file as optional
- the config file should not be required
- set required to false
2025-10-22 17:35:43 +01:00
Jeremiah Russell
d92d4ad9c0 ♻️ Refactor duplicated InitCli creation in tests
Extract repeated InitCli instance creation into helper functions:
- create_test_init_cli() for default test instances
- create_test_init_cli_with_force() for force-enabled instances

This reduces code duplication and makes test setup more maintainable.
2025-10-22 06:38:00 +01:00
Jeremiah Russell
2b29382d5e 🎨 Apply cargo fmt formatting 2025-10-22 06:38:00 +01:00
Jeremiah Russell
10a1a1e058 🐛 Fix duplicate CreateDir operation in init planning
Prevent duplicate CreateDir operations when rules directory
is the same as config directory by checking if the directory
creation has already been planned before adding another one.
2025-10-22 06:38:00 +01:00
Jeremiah Russell
d4cc2621db Add configurable rules directory support
- Add rules configuration option to ClientConfig
- Support custom rules file paths via config and CLI
- Add --rules-dir option to init command
- Update Rules struct to accept custom file paths
- Add helper functions for rules path resolution
- Fix doc comment formatting issues
- Add integration tests for custom rules paths
2025-10-22 06:38:00 +01:00
Jeremiah Russell
bcb93fd68f feat: integrate configurable rules path throughout CLI
- Make parse_config_root() public for reuse in main.rs
- Add get_rules_path() helper to extract and resolve rules path from config
- Update main CLI to use configured rules path for default rule execution
- Add run_with_rules_path() method to RulesCli for custom path support
- Update all unit tests to include rules_dir field
- Rules path now supports h:, c:, r: prefixes throughout the application
2025-10-22 06:38:00 +01:00
Jeremiah Russell
20b36a00ed feat: add get_rules_from() to load rules from custom path
- Add get_rules_from(path) function that accepts optional custom path
- Keep get_rules() as backward-compatible wrapper
- Automatically create and save default rules to custom path if not found
2025-10-22 06:38:00 +01:00
Jeremiah Russell
2083c5c5fe feat: add configurable rules directory support to Rules and InitCli
- Add Rules::load_from() and Rules::save_to() methods for custom paths
- Add --rules-dir option to init command
- Support h:, c:, r: path prefixes for rules directory
- Generate config file with correct rules path when using separate directory
- Create rules directory automatically if it doesn't exist
- Maintain backward compatibility with default ~/.cull-gmail/rules.toml
2025-10-22 06:38:00 +01:00
Jeremiah Russell
df9d2b6c8a 🔧 fix: address clippy warnings after refactoring
- Change &PathBuf to &Path parameter in plan_credential_file_operation
- Use inline format string in log message
- Both formatting and linting now clean
2025-10-21 14:48:31 +01:00
Jeremiah Russell
aaa4ebcbde ♻️ refactor: reduce cognitive complexity of plan_operations and execute_operation
## Refactoring Changes

### plan_operations function:
- Split monolithic function into focused single-purpose methods
- Extract plan_config_directory, plan_credential_file_operation, etc.
- Add check_file_conflicts helper to eliminate repetitive error checking
- Fix should_backup logic (was always returning true)

### execute_operation function:
- Replace large match statement with focused execution methods
- Extract execute_create_directory, execute_copy_file, etc.
- Add handle_existing_file helper for backup/interactive logic
- Add prompt_for_overwrite and apply_permissions_if_needed helpers

## Benefits:
- Each function now has single responsibility
- Eliminated code duplication in conflict checking and interactive prompts
- Reduced cyclomatic complexity from ~15 to 2-3 per function
- Improved testability and maintainability
- All tests continue to pass
2025-10-21 14:48:31 +01:00
Jeremiah Russell
5bcfc8fd29 🐛 fix: allow init command to run without existing config file
- Move init command handling before config loading in CLI dispatcher
- Prevents init from failing when no configuration exists yet
- Fixes CircleCI test failures where init was trying to load ~/.cull-gmail/cull-gmail.toml
- All integration tests now pass in CI environment
2025-10-21 14:48:31 +01:00
Jeremiah Russell
b33458cf3e 🎨 style: apply rustfmt formatting to test assertions 2025-10-21 14:48:31 +01:00