mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
cc5f00355f
* feat: add email service with multi-adapter support Implement a full-stack email service with global provider management, per-bot bindings with granular read/write permissions, outbox audit storage, and MCP tool integration for direct mailbox access. Backend: - Email providers: CRUD with dynamic config schema (generic SMTP/IMAP, Mailgun) - Generic adapter: go-mail (SMTP) + go-imap/v2 (IMAP IDLE real-time push via UnilateralDataHandler + UID-based tracking + periodic check fallback) - Mailgun adapter: mailgun-go/v5 with dual inbound mode (webhook + poll) - Bot email bindings: per-bot provider binding with independent r/w permissions - Outbox: outbound email audit log with status tracking - Trigger: inbound emails push notification to bot_inbox (from/subject only, LLM reads full content on demand via MCP tools) - MailboxReader interface: on-demand IMAP queries for listing/reading emails - MCP tools: email_accounts, email_send, email_list (paginated mailbox), email_read (by UID) — all with multi-binding and provider_id selection - Webhook: /email/mailgun/webhook/:config_id (JWT-skipped, signature-verified) - DB migration: 0019_add_email (email_providers, bot_email_bindings, email_outbox) Frontend: - Email Providers page: /email-providers with MasterDetailSidebarLayout - Dynamic config form rendered from ordered provider meta schema with i18n keys - Bot detail: Email tab with bindings management + outbox audit table - Sidebar navigation entry - Full i18n support (en + zh) - Auto-generated SDK from Swagger Closes #17 * feat(email): trigger bot conversation immediately on inbound email Instead of only storing an inbox item and waiting for the next chat, the email trigger now proactively invokes the conversation resolver so the bot processes new emails right away — aligned with the schedule/heartbeat trigger pattern. * fix: lint --------- Co-authored-by: Acbox <acbox0328@gmail.com>
50 lines
1.4 KiB
SQL
50 lines
1.4 KiB
SQL
-- name: CreateBotEmailBinding :one
|
|
INSERT INTO bot_email_bindings (bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config)
|
|
VALUES (
|
|
sqlc.arg(bot_id),
|
|
sqlc.arg(email_provider_id),
|
|
sqlc.arg(email_address),
|
|
sqlc.arg(can_read),
|
|
sqlc.arg(can_write),
|
|
sqlc.arg(can_delete),
|
|
sqlc.arg(config)
|
|
)
|
|
RETURNING *;
|
|
|
|
-- name: GetBotEmailBindingByID :one
|
|
SELECT * FROM bot_email_bindings WHERE id = sqlc.arg(id);
|
|
|
|
-- name: GetBotEmailBindingByBotAndProvider :one
|
|
SELECT * FROM bot_email_bindings
|
|
WHERE bot_id = sqlc.arg(bot_id) AND email_provider_id = sqlc.arg(email_provider_id);
|
|
|
|
-- name: ListBotEmailBindings :many
|
|
SELECT * FROM bot_email_bindings
|
|
WHERE bot_id = sqlc.arg(bot_id)
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: ListBotEmailBindingsByProvider :many
|
|
SELECT * FROM bot_email_bindings
|
|
WHERE email_provider_id = sqlc.arg(email_provider_id)
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: ListReadableBindingsByProvider :many
|
|
SELECT * FROM bot_email_bindings
|
|
WHERE email_provider_id = sqlc.arg(email_provider_id) AND can_read = TRUE
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: UpdateBotEmailBinding :one
|
|
UPDATE bot_email_bindings
|
|
SET
|
|
email_address = sqlc.arg(email_address),
|
|
can_read = sqlc.arg(can_read),
|
|
can_write = sqlc.arg(can_write),
|
|
can_delete = sqlc.arg(can_delete),
|
|
config = sqlc.arg(config),
|
|
updated_at = now()
|
|
WHERE id = sqlc.arg(id)
|
|
RETURNING *;
|
|
|
|
-- name: DeleteBotEmailBinding :exec
|
|
DELETE FROM bot_email_bindings WHERE id = sqlc.arg(id);
|