email-db tool: extract-attachment action, streaming, filename decoding, copy path fix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 20:00:45 +00:00
co-authored by Claude Opus 4.6
parent 2752102a7e
commit 192ae63c0e
4 changed files with 118 additions and 24 deletions
+15 -4
View File
@@ -1,5 +1,5 @@
---
version: 3
version: 9
name: email_db
label: Email Database
description: Query, search, aggregate, and manage the user's email database. Use this tool to answer questions about emails, find messages by sender/domain/date/content, get statistics, and delete emails. The database is a local SQLite copy of the user's synced Gmail. All actions default to inbox scope — use folder parameter to query other folders like sent, spam, trash, or 'all' for everything.
@@ -7,7 +7,7 @@ language: typescript
inputs:
action:
type: string
description: "Action to perform: query, search, stats, count, domains, senders, attachments, attachment-types, delete"
description: "Action to perform: query, search, stats, count, domains, senders, attachments, attachment-types, extract-attachment, delete"
sql:
type: string
description: "Raw SQL query for the 'query' action. Only SELECT statements are allowed unless action is 'delete'."
@@ -36,13 +36,21 @@ inputs:
type: string
description: "Attachment content type filter. Full MIME type (e.g. 'image/jpeg') or just the type prefix (e.g. 'image' matches all image types). Used with 'attachments' action."
optional: true
email_id:
type: string
description: "Email ID for extract-attachment action."
optional: true
attachment_idx:
type: number
description: "Attachment index (0-based) for extract-attachment action."
optional: true
folder:
type: string
description: "Gmail folder/label to scope results. Defaults to 'inbox'. Use 'all' for all folders. Common values: inbox, sent, spam, trash."
optional: true
limit:
type: number
description: "Maximum number of results to return (default 20, max 100)."
description: "Maximum number of results to return. No limit by default — all results are returned. If a query could return a very large number of results, ask the user if they'd like to set a limit before running it."
optional: true
---
@@ -60,6 +68,7 @@ Query and manage the user's local email database (SQLite).
- **senders**: List all senders with email counts, sorted by frequency.
- **attachments**: Search attachments by type, filename, sender, etc. Use `content_type` for type filtering (e.g. `image` for all images, `image/jpeg` for specific type). Combine with `domain`, `sender`, `before`, `after`, `search`.
- **attachment-types**: List all attachment content types with counts.
- **extract-attachment**: Extract an attachment file from the database and save it to ~/Downloads/. Requires `email_id` and `attachment_idx`. Use the `attachments` action first to find the email_id and idx. Output filename: `{YYYYMMDD}_{sender}_{email_id}_{idx}_{name}.{ext}` (e.g. `20250115_boss@company.com_abc123_0_invoice.pdf`).
- **delete**: Delete emails matching filters. Requires at least one of: `domain`, `sender`, `before`, `after`, or `sql` (with DELETE statement).
## Database Schema
@@ -90,7 +99,8 @@ attachments (
idx INTEGER,
filename TEXT,
size INTEGER,
content_type TEXT
content_type TEXT,
content TEXT -- base64-encoded binary content (use extract-attachment action to export)
)
```
@@ -106,4 +116,5 @@ attachments (
- List attachment types: `action: "attachment-types"`
- Find image attachments: `action: "attachments", content_type: "image"`
- Find PDFs from a sender: `action: "attachments", content_type: "application/pdf", sender: "boss@company.com"`
- Extract an attachment: `action: "extract-attachment", email_id: "abc123", attachment_idx: 0`
- Custom query: `action: "query", sql: "SELECT from_domain, COUNT(*) as n FROM emails GROUP BY from_domain HAVING n > 50 ORDER BY n DESC"`