Initial requirements¶
Overview¶
GmailAutoCleaner is a CLI application (using Python's argparse for simple CLI with verbose console output in the first iteration; Streamlit UI can be added later) designed to automate the cleanup of Gmail (primary target), Google Drive, and Google Photos based on user-defined criteria specified in a YAML configuration file. The tool aims to free up storage space while ensuring data safety through backup mechanisms. Actions include backing up items (with hashable backups for verification), removing items, or backing up without removal for manual review.
The UI (when implemented) should focus on fast, smart indexing and visualization of all backed up emails and attachments, regardless of how they are stored (by timestamp, sender subdir, other methods), with separate indexing for attachments, plus viewing support for standard media types (images/videos/audio/PDFs/text/docs/excel/etc.), both from Gmail archives and future Drive/Photos integrations. The main purpose is to quickly view what has been backed up and search through archived data more efficiently than Google Apps interfaces, which lose semantics due to UUID naming. The CLI remains crucial for cronjob automation, with Roda.
backup operations.
Functional Requirements¶
Core Functionality¶
- YAML Configuration Parsing: The application must read and parse a YAML file containing cleanup criteria, including:
- Target free space quotas for each service (Gmail primary, Drive, Photos).
- Progressive criteria for evaluating data into categories: sensitive data (protect), insensitive but good to save, completely redundant (to delete), and others as needed.
- Specific criteria for Gmail: searches in subject/body, number of attachments, file extensions/MIME types of attachments, attachment sizes, email senders from referenceable pools of important emails (defined generically in YAML), Gmail folders (labels) for targeting specific categories.
- For Google Drive and Photos: analogous criteria like file types, sizes, metadata, labels, etc. (to be defined similarly if possible).
- Per category, action specifications: delete, backup and remove, backup without remove, or ignore.
- Service Integration:
- Authenticate and connect to Google APIs for Gmail, Google Drive, and Google Photos.
- Retrieve and analyze items from each service based on criteria.
- Perform actions (backup, remove) on identified items.
- Backup Mechanism:
- Create hashable backups (e.g., using SHA-256) of items before removal to verify integrity and prevent data loss.
- Store backups in a configurable local or cloud location.
- Support incremental backups to avoid re-backing up unchanged items.
- Cleanup Actions:
- Backup and Remove: Backup item, verify hash, then delete from service.
- Remove Only: Delete item without backup (with confirmation prompts).
- Backup Only: Backup item without deletion for manual review.
- Progress Tracking: Provide real-time progress updates during cleanup operations, including items processed, space freed, and errors encountered.
User Interface (Streamlit for Later Iteration)¶
- Smart Email Indexer: Fast indexing of all backed up emails regardless of storage structure (timestamp dirs, sender subdirs, etc.), focusing on .eml and .json files.
- Attachment Indexing: Separate indexing and access to email attachments.
- Media Visualization: Support for viewing standard file types (images/videos/audio/PDFs/text/docs/excel/etc.) using Streamlit components, both for Gmail attachments and future Drive/Photos content.
- Advanced Search: Search across emails by subject, body, sender, date range, keywords, with pagination for large result sets.
- Backup Overview: Quick view of what has been backed up, overcoming the semantic loss from UUID naming in backups.
- Future Extensions: Support for Drive and Photos visualization with similar search and viewing capabilities.
Error Handling and Safety¶
- Confirmation Prompts: Require user confirmation before performing destructive actions (e.g., removals).
- Rollback Mechanism: Ability to restore backed-up items if needed (though this may require additional tooling).
- Error Recovery: Handle API rate limits, network failures, and partial failures gracefully, with retry logic.
- Data Validation: Ensure YAML criteria are valid and safe (e.g., prevent accidental deletion of all items).
Non-Functional Requirements¶
Performance¶
- Efficiency: Process large volumes of data without excessive API calls or memory usage.
- Scalability: Handle accounts with thousands of emails/files/photos.
- Speed: Complete operations within reasonable time frames (e.g., hours for large cleanups, not days).
Security¶
- Authentication: Secure OAuth2 flow for Google API access, with token storage in encrypted form.
- Data Privacy: Ensure backups are encrypted and access-controlled.
- Audit Trail: Log all actions for compliance and debugging.
Usability¶
- Intuitive UI: Streamlit interface should be user-friendly for non-technical users.
- Documentation: Inline help and tooltips for configuration options.
- Accessibility: Support for keyboard navigation and screen readers.
Reliability¶
- Robustness: Handle edge cases like corrupted files, API changes, or invalid YAML.
- Testing: Include unit tests, integration tests, and end-to-end tests.
- Monitoring: Alert users to issues like failed backups or quota breaches.
Compatibility¶
- Platforms: Run on Windows, macOS, and Linux.
- Dependencies: Use Python with minimal external libraries to avoid conflicts.
- API Versions: Support current Google API versions and handle deprecations.
Additional Professional Requirements (Added by Developer)¶
- Modular Design: Separate concerns into modules for API interactions, YAML parsing, backup logic, and UI.
- Configuration Management: Support environment-specific configs (e.g., dev/prod) and version control for YAML files.
- Logging and Monitoring: Implement structured logging with levels (INFO, WARN, ERROR) and optional integration with tools like ELK stack.
- Internationalization: Support multiple languages for UI and messages.
- Compliance: Adhere to GDPR/CCPA for data handling, especially backups.
- Versioning: Semantic versioning for the application and backups.
- CI/CD Pipeline: Setup for automated testing and deployment.
- Documentation: Auto-generated API docs and user guides.
- Performance Metrics: Track and report on operation times, API usage, and resource consumption.