# 数据模型(v2,docs/11 §13) 核心实体:CloudflareAccount、Domain、Mailbox、Email、EmailAttachment、Webhook(三级配置)、WebhookDelivery、OAuthConnection、WorkerCredential。 Node 作为邮件链路核心模型已删除(旧 nodes / node_credentials 表由迁移 0003 移除, 账号实体更名为 cloudflare_accounts,凭据更换为 worker_credentials)。 ## cloudflare_accounts ```text id, name, cloudflare_account_id, worker_id, status, provision_steps, created_at, updated_at ``` status:pending_oauth | provisioning | active | error | revoked。 worker_id 同时是 Email Worker 脚本名与 Worker -> Console 的身份 ID。 ## domains ```text id, cloudflare_account_id, account_id, name, status, worker_id, zone_id, webhook_url, webhook_headers, webhook_key_enc, setup_error, created_at, updated_at ``` status:pending(未配置 Email Workers)| active | error。 ## mailboxes ```text id, domain_id, address, status, retention_seconds, is_catch_all, webhook_url, webhook_headers, webhook_key_enc, created_at, updated_at ``` ## emails ```text id, account_id, mailbox_id nullable, message_id, from_address, to_addresses, cc_addresses, subject, text_body, html_body, markdown_body(v2.1.0:正文 Markdown, 入库时从 HTML/纯文本转换), raw_storage_key, size, received_at, expires_at, created_at ``` Console 收到邮件后根据收件人/内容与自身配置关联 mailbox。 ## email_attachments ```text id, email_id, filename, content_type, size, storage_key, content_id ``` ## Webhook(三级:邮箱 -> 域名 -> 全局) 域名/邮箱行内配置(webhook_url / webhook_headers / webhook_key_enc), 全局配置存 settings.global_webhook;独立 webhooks 实体已移除。 ```text webhook_deliveries: id, email_id, target_type(mailbox|domain|global), url, headers, key_enc, status, attempt_count, next_retry_at, last_error, delivered_at, created_at ``` 投递行在入队时冻结解析出的配置,重试不受后续配置变更影响。 ## oauth_connections ```text id, provider, account_id, encrypted_access_token, refresh_token, expires_at, created_at, updated_at ``` OAuth token 必须加密存储。所有 Email 必须有 expires_at,默认 retention 为 86400 秒。 ## worker_credentials ```text id, cloudflare_account_id, worker_id, secret_hash, secret_enc, secret_last4, status(active | revoked), created_at, revoked_at ``` 用于 Email Worker 与 Console 内部认证:secret_hash 为摘要,secret_enc 为 AES-GCM 密文 (HMAC 验签需要原文,加密存储防拖库泄露);明文 secret 仅在签发/轮换时返回一次。 ## 其它 users、settings(全局 Webhook、单一 API/MCP Key:api_key_hash/api_key_last4/api_key_created_at、 Cloudflare OAuth 客户端:cf_oauth_client_id / cf_oauth_client_secret_enc(AES-GCM 密文) / cf_oauth_client_secret_last4)、 nonces、oauth_states。v2.1.0 起 api_credentials 表已删除(Key 合并为单一 Key 存 settings);v2.2.0 起 cf_sim_resources 表已删除(移除本地 sim 模式,接入链路只有真实 Cloudflare OAuth)。