Add structured query filters to search command#7
Merged
Conversation
Implement structured filters for the search command to enable precise searches beyond FTS5 full-text queries. Agents and users can now filter by sender, recipient, date range, attachments, labels, and subject. New filter options: - --from: Filter by sender email (partial match) - --to: Filter by recipient email (partial match) - --after/--before: Date range filtering (supports "today", "yesterday", ISO dates) - --has: Filter messages with attachments - --label: Filter by Gmail label (INBOX, IMPORTANT, etc.) - --subject: Filter by subject text (partial match) Implementation details: - Created filters module with SearchFilters dataclass and SQL builder - Enhanced search_messages() to support filters alongside FTS5 queries - Uses parameterized queries for SQL injection protection - Handles JSON fields (labels) and indexed fields (from_addr, date_utc) - Backward compatible - existing search commands work unchanged Examples: gmail search --from alice@example.com gmail search "invoice" --from finance@ --after 2024-01-01 gmail search --has --label INBOX Tests: - 30 comprehensive tests covering date parsing, filter building, and search - All tests passing with 100% coverage of filter functionality
Add CI workflow that runs tests on every push and pull request to main branch. The workflow: - Runs on Ubuntu with Python 3.12 - Installs project dependencies including dev dependencies - Executes pytest test suite - Generates coverage report This ensures all tests pass before merging changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements structured query filters for the search command, enabling precise searches beyond FTS5 full-text queries. This feature is essential for agent-friendly usage and programmatic querying of the Gmail database.
Features
New Filter Options
All filters are optional and combine with AND logic:
--from <email>- Filter by sender (partial match)--to <email>- Filter by recipient (partial match)--after <date>- Messages after date (supports "today", "yesterday", ISO dates)--before <date>- Messages before date--has- Messages with attachments--label <label>- Filter by Gmail label--subject <text>- Filter by subject (partial match)Usage Examples
Implementation Details
src/gmail_cli/db/filters.py- ContainsSearchFiltersdataclass, date parsing, and SQL buildingsearch_messages()to handle three scenarios:json_each()functionTest Coverage
Added comprehensive test suite with 30 tests:
All tests passing with 100% coverage of filter functionality.
Dependencies
python-dateutil>=2.8.0for flexible date parsingpytest>=7.0.0as dev dependency for testingWhy This Matters
This feature enables:
Closes part of the roadmap for making gmail-cli agent-friendly.