Skip to content

feat: add email integration (read, send, manage) - #800

Merged
avoidwork merged 16 commits into
mainfrom
feat/email-integration
Aug 17, 2026
Merged

feat: add email integration (read, send, manage)#800
avoidwork merged 16 commits into
mainfrom
feat/email-integration

Conversation

@avoidwork

@avoidwork avoidwork commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Description

Add email integration tools for reading, sending, and managing emails across Gmail, Outlook/MS Graph, and IMAP — including inbox organization and draft management. This change introduces a unified email tool with action-based dispatch, multi-provider support, and dedicated IMAP/SMTP configuration.

Type of Change

  • New feature (non-breaking change which adds functionality)

Testing

  • Unit tests for all email providers (Gmail, MS Graph, IMAP) covering send, read, draft, organize, and search operations
  • Provider factory tests for credential validation and env var resolution
  • Config schema tests for email provider configuration
  • All 1106 tests pass with zero failures

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Files Changed

File Change
src/tools/email/ New email tool with action dispatch, provider base class, and Gmail/Graph/IMAP implementations
src/tools/index.js Email tool registration with tier2 permissions
src/agent/deepAgents.js Email tool classification for agent types
src/config/config.js Email config defaults
src/config/schemas/providers.js Gmail, Graph, and IMAP provider schemas
tests/unit/tools/email/ Comprehensive provider and tool tests
tests/unit/config/providers.test.js Config schema validation tests
package.json New dependencies: googleapis, nodemailer, imap-simple
openspec/specs/ Email tools, providers, and auth specs
README.md Email tool and env var documentation
config.yaml Email provider configuration

OpenSpec change: email-integration
- Proposal: multi-provider email integration (Gmail, MS Graph, IMAP)
- Design: provider abstraction with OAuth2 credential management
- Specs: email-tools, email-providers, email-auth capabilities
- Tasks: 30 implementation tasks across 7 groups

Closes #779
@avoidwork avoidwork self-assigned this Aug 16, 2026
- Add email module: src/tools/email/ with provider abstraction
- Implement GmailProvider, GraphProvider, ImapProvider
- Create email tools: read, send, draft (save/list/update/delete), organize, search
- Add email provider config schemas (Gmail, Graph, IMAP)
- Register email tools in TOOL_PERMISSIONS and TOOL_CLASSIFICATIONS
- Add comprehensive tests for all providers, tools, and config schemas
- Dependencies: googleapis, @microsoft/microsoft-graph-client, nodemailer, imap-simple

Closes #779
- Archive OpenSpec change: 2026-08-16-email-integration
- Apply spec deltas: email-auth (+4), email-providers (+5), email-tools (+4)
- Total: +13 lines added to spec files
- Add EmailConfigSchema with provider discriminated union (gmail, graph, imap)
- Add email section to config.yaml with all provider fields
- Add env var allowlist for email config (EMAIL_PROVIDER_*, EMAIL_*)
- Env resolution maps email.provider.clientId → EMAIL_PROVIDER_CLIENT_ID
- All schema fields nullable with sensible defaults
- Add factory.test.js for email provider creation
- Update provider tests for new schema structure
- Add timeoutMs to base class, AbortController pattern to all providers
- Add validateConfig() to all providers with required field checks
- GmailProvider: fix hardcoded From: madz header, fix base64 encoding (standard not URL-safe), remove duplicate CATEGORY_UPDATES in archive
- GraphProvider: add timeout to all fetch calls, fix folder case (INBOX), fix updateDraft null safety, fix organize addLabel/removeLabel to use params.label
- ImapProvider: fix search/listDrafts folder handling, fix deleteDraft expunge API, use imap-simple addMessage for drafts instead of SMTP hack, add timeout, add validation
…efresh, config schema, startup validation

- Add AES-256-GCM credential encryption module (crypto.js)
- Add #sanitizeError() to all providers to strip credentials from error messages
- Implement OAuth token refresh for GmailProvider and GraphProvider
- Add 401 retry with token refresh in GraphProvider #fetchWithTimeout
- Fix GraphProvider OData injection — escape single quotes in filter values
- Fix Graph archive folder — use 'deleteditems' instead of 'deletedmessages'
- Fix IMAP organize to use params.folder instead of hardcoded INBOX
- Fix IMAP draft IDs — use actual IMAP UIDs instead of synthetic IDs
- Fix IMAP read/search/listDrafts — use UID-based pagination
- Add provider config validation at startup in deepAgents.js
- Fix config.yaml — remove cross-provider fields from email section
- Make Zod provider schemas passthrough to allow extra fields in config
- Add #sanitizeError to IMAP provider alongside Gmail/Graph
- email-auth: update credential storage to reflect config-based AES-256-GCM encryption (not memory system)
- email-auth: update startup validation to reflect config-level validation (not API test requests)
- email-auth: add error message sanitization requirement
- email-tools: fix date filter parameter names (dateFrom/dateTo, not dateAfter/dateBefore)
- Remove crypto.js — no encryption needed, credentials never touch config
- Remove all credential fields from Zod schemas (clientId, clientSecret, etc.)
- GmailProvider reads from EMAIL_GMAIL_* env vars
- GraphProvider reads from EMAIL_GRAPH_* env vars
- ImapProvider reads from EMAIL_IMAP_* env vars
- validateProviderConfig checks env vars instead of config fields
- Clean config.yaml — only provider type and non-secret settings remain
- All 1106 tests pass, lint clean
…on dispatch

- Replace email_read, email_send, email_draft_save/list/update/delete,
  email_organize, email_search with single 'email' tool
- Export emailImpl for testability, wrapped by tool() for registration
- Action dispatch: read, send, draftSave, draftList, draftUpdate,
  draftDelete, organize, search
- Unknown action validated before provider check
- All 1106 tests pass, lint clean
- Add email tool to Built-in Tools table with action list
- Add EMAIL_* env var section with all Gmail, Graph, and IMAP variables
- Split email credentials into EMAIL_IMAP_* and EMAIL_SMTP_* env vars
- IMAP provider uses nodemailer for SMTP sending, imap-simple for IMAP reading
- SMTP defaults to IMAP host when not explicitly configured
- Updated config.yaml sandbox env allowlist
- Updated schema with imapHost, imapPort, imapSecure, smtpHost, smtpPort
- Updated README with new env var documentation
@avoidwork
avoidwork merged commit 7a2e267 into main Aug 17, 2026
2 checks passed
@avoidwork
avoidwork deleted the feat/email-integration branch August 17, 2026 03:16
@avoidwork avoidwork mentioned this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant