Skip to content

Add rich metadata access and better error handling#8

Merged
patrick91 merged 1 commit intomainfrom
feat/rich-metadata-and-better-errors
Jan 18, 2026
Merged

Add rich metadata access and better error handling#8
patrick91 merged 1 commit intomainfrom
feat/rich-metadata-and-better-errors

Conversation

@patrick91
Copy link
Copy Markdown
Owner

Summary

Implements two agent-friendly features for gmail-cli from Issue #6:

Note: Data extraction (Issue #9) is intentionally skipped - LLMs can extract structured data from the raw text we provide via JSON output.

Feature 1: Rich Metadata Access

Exposes full headers, RFC822 format, and thread tree structure.

New CLI Options

# Show all headers in readable format
gmail read <id> --headers

# Get raw RFC822 message (fetch from API)
gmail read <id> --format raw

# Show thread as tree structure
gmail thread <id> --tree

Implementation Details

  • read command: Added --headers and --format raw options
  • thread command: Added --tree flag for hierarchical view
  • New module: db/thread_tree.py - Builds thread trees using In-Reply-To headers
  • Client enhancement: GmailClient.get_message_raw() fetches RFC822 format from Gmail API

Feature 2: Better Error Handling

Structured error codes, query validation, dry-run mode, clear error messages.

New CLI Options

# Dry run to see what would be synced
gmail sync full --dry-run

# Validation errors shown in structured format
gmail read invalid_id --json

Implementation Details

  • New exception classes with error codes:

    • GmailCliException (base class)
    • InvalidQueryError, RateLimitError, MessageNotFoundError
    • SyncError, AuthenticationError, ValidationError
  • Centralized error handler (error_handler.py):

    • Supports both JSON and pretty output
    • Consistent error formatting across commands
  • Input validators (validators.py):

    • Message ID validation
    • Date range validation
    • FTS5 query syntax validation
  • Dry-run support in sync command:

    • Shows current count, total messages, estimated size/time
    • No actual syncing performed

Files Changed

New Files (5)

  • src/gmail_cli/error_handler.py - Centralized error handling
  • src/gmail_cli/validators.py - Input validation functions
  • src/gmail_cli/db/thread_tree.py - Thread tree builder
  • tests/test_error_handling.py - 11 passing tests
  • tests/test_metadata.py - 6 passing tests

Modified Files (4)

  • src/gmail_cli/exceptions.py - Added 6 exception classes
  • src/gmail_cli/sync/engine.py - Dry-run support
  • src/gmail_cli/sync/client.py - RFC822 format fetch
  • src/gmail_cli/cli.py - Enhanced read/thread commands, error handling

Testing

All tests passing ✓ (47/47)

  • 11 new error handling tests
  • 6 new metadata tests
  • 30 existing tests (still passing)
pytest tests/ -v
# ============================== 47 passed in 0.21s ==============================

Related Issues

Closes #8
Closes #10
Part of #6

Implements two agent-friendly features:

1. Rich Metadata Access (Issue #8)
   - Add --headers flag to show all email headers
   - Add --format raw to fetch RFC822 format from API
   - Add --tree flag to show thread hierarchical structure
   - New thread_tree.py module for building thread trees

2. Better Error Handling (Issue #10)
   - Add structured exception classes with error codes
   - Add centralized error handler with JSON/pretty output
   - Add input validators for message IDs, date ranges, FTS queries
   - Add --dry-run flag to sync command for preview

Changes:
- Modified: exceptions.py, cli.py, sync/engine.py, sync/client.py
- Added: error_handler.py, validators.py, db/thread_tree.py
- Tests: test_error_handling.py (11 tests), test_metadata.py (6 tests)

All 47 tests passing.
@patrick91 patrick91 merged commit edbc294 into main Jan 18, 2026
1 check passed
@patrick91 patrick91 deleted the feat/rich-metadata-and-better-errors branch January 18, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant