Skip to content

feat(cli): infer --provider from mailbox domain#42

Merged
stevenobiajulu merged 1 commit intomainfrom
feat/infer-provider-from-mailbox
Apr 20, 2026
Merged

feat(cli): infer --provider from mailbox domain#42
stevenobiajulu merged 1 commit intomainfrom
feat/infer-provider-from-mailbox

Conversation

@stevenobiajulu
Copy link
Copy Markdown
Member

Summary

Closes #41. When --provider is not passed, setup / configure now infers the provider from the --mailbox domain instead of silently defaulting to Microsoft for Gmail addresses.

Priority order:

  1. Explicit --provider — always wins.
  2. Inferred from --mailbox domain (exact match).
  3. Falls back to existing 'microsoft' default (preserves behavior for corporate/custom domains).

Domain map (exact match only, case-insensitive):

When inference fires, we log once to stderr (matching the existing [email-agent-mcp] Configuring mailbox … pattern) with the matched domain so the behavior is transparent:

[email-agent-mcp] Inferred provider "gmail" from mailbox domain "gmail.com". Pass --provider to override.

Pattern matching (e.g., hotmail.*) was intentionally rejected — false-positive risk for corporate domains is not worth the marginal coverage of regional variants.

Diff scope

  • packages/email-mcp/src/cli.ts — new exported helper inferProviderFromMailbox (reuses the existing normalizeMailboxValue so whitespace-padded inputs still infer); two-line change to provider resolution in runConfigure; one new stderr log line.
  • packages/email-mcp/src/cli.test.ts — new describe('cli/Provider Inference') with 8 unit tests covering the domain map, case-insensitivity, whitespace, non-matching domains, and explicit non-pattern-matching (hotmail.co.uk → undefined); one new integration scenario inside the existing cli/Gmail Configure block that runs configure --mailbox test@gmail.com with no --provider and asserts both the Gmail path was taken and the inference log was emitted.

No other files touched. No package-version bump (release is batched separately).

Peer-reviewed by Gemini CLI and Codex CLI before implementation. Codex caught two issues that shaped the final plan: (1) the helper reuses normalizeMailboxValue for input trimming, and (2) the "explicit Microsoft wins" runtime test was intentionally omitted — the Microsoft mock in cli.test.ts only activates for watcher tests (via watcherMockState.mailboxes.length > 0), not configure. The precedence logic is still covered by the unit ?? chain.

Test plan

  • npm run build
  • npm run test:run -w @usejunior/email-mcp — 150/150 passing (9 new tests)
  • npm run lint

When --mailbox is a consumer Gmail/Microsoft address and --provider is
not passed, infer the provider from the domain suffix instead of
silently defaulting to microsoft. Custom business domains still fall
back to the microsoft default since either provider is plausible.
Adds a stderr log line (with the matched domain) so the inference is
transparent.

Closes #41
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@stevenobiajulu stevenobiajulu merged commit b5ab8b8 into main Apr 20, 2026
14 checks passed
@stevenobiajulu stevenobiajulu deleted the feat/infer-provider-from-mailbox branch April 20, 2026 17:49
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.

setup/configure: infer --provider from mailbox email domain

1 participant