# Phase 81.19.b — out-of-tree standalone subprocess plugin.
#
# This manifest is parsed at compile-time via `include_str!` in
# `EmailPlugin::new()` and shipped alongside the binary so the
# nexo-rs daemon's discovery walker can register the plugin
# without spawning the subprocess. Operators add the directory
# containing this file to `plugins.discovery.search_paths`.
#
# Unlike telegram / whatsapp, email is a SINGLE plugin instance
# that manages N internal accounts via `EmailPluginConfig.accounts`.
# There is no per-instance `registry_name` divergence —
# `manifest().plugin.id` and `Plugin::name()` agree at all times.

[plugin]
id = "email"
version = "0.5.0"
name = "Email"
description = "Email (IMAP/SMTP) channel for nexo agents — multi-account internal."
min_nexo_version = ">=0.1.0"

[plugin.requires]
nexo_capabilities = ["broker"]

# Phase 81.33.b.real Stages 2+4+5 — auto-discovery broker
# handler subscribe allowlist. Defense-in-depth so the plugin
# can only handle the topics it owns.
[plugin.capabilities.broker]
subscribe = [
    "plugin.outbound.email",
    "plugin.outbound.email.>",
    "plugin.email.http.request",
    "plugin.email.admin.>",
    "plugin.email.metrics.scrape",
]
publish   = ["plugin.inbound.email", "plugin.inbound.email.>"]

# Phase 81.33.b.real Stage 2 — daemon mounts HTTP proxy under
# `/email`. Forwards requests via broker JSON-RPC. The plugin
# owns its internal router (see `src/auto_discovery.rs::http_request`).
[plugin.http]
mount_prefix    = "/email"
timeout_seconds = 30

# Phase 81.33.b.real Stage 4 — admin RPC commands forwarded via
# broker. Daemon receives `nexo/admin/email/<verb>` + forwards
# to `plugin.email.admin.<verb>`.
[plugin.admin]
method_prefix       = "nexo/admin/email/"
broker_topic_prefix = "plugin.email.admin"
timeout_seconds     = 15

# Phase 81.33.b.real Stage 5 — Prometheus metrics scrape via
# broker. Replaces the legacy in-process direct call from the
# daemon's `run_metrics_server` to
# `nexo_plugin_email::metrics::render_prometheus`.
[plugin.metrics]
prometheus          = true
broker_topic_prefix = "plugin.email"
timeout_seconds     = 5

# Phase 81.33.b.real Stage 6 — setup wizard dashboard surface.
# 0.5.0: email is multi-tenant; the wizard walks per-tenant subdirs
# of the workspace and probes per-account password files inside.
# Legacy 0.4.x single-map YAML still works via the back-compat
# shim — those operators see one synthetic `default` tenant.
[plugin.dashboard.layout]
kind = "workspace_walk"
subdir = "email"

[plugin.dashboard.auth_check]
kind = "session_dir_files"
candidates = ["email_password.txt", ".nexo-paired"]

# Phase 93.4.c — declarative config contract. Daemon delivers
# operator YAML at `cfg.plugins.entries.email` (Phase 93.3) via
# `plugin.configure` JSON-RPC (Phase 93.2); SDK `on_configure`
# handler deserialises into `EmailPluginConfig` (single-instance
# shape, no Vec wrapper).
[plugin.config_schema]
shape = "array"
schema = '''{
  "type": "object",
  "properties": {
    "enabled":                   { "type": "boolean" },
    "max_body_bytes":            { "type": "integer" },
    "max_attachment_bytes":      { "type": "integer" },
    "attachment_retention_days": { "type": "integer" },
    "max_dlq_lines":             { "type": "integer" },
    "bounce_retention_days":     { "type": "integer" },
    "attachments_dir":           { "type": "string" },
    "outbound_queue_dir":        { "type": "string" },
    "poll_fallback_seconds":     { "type": "integer" },
    "idle_reissue_minutes":      { "type": "integer" },
    "spf_dkim_warn":             { "type": "boolean" },
    "instance":                  { "type": "string" },
    "allow_agents":              { "type": "array" },
    "loop_prevention": {
      "type": "object",
      "properties": {
        "auto_submitted": { "type": "boolean" },
        "list_headers":   { "type": "boolean" },
        "self_from":      { "type": "boolean" },
        "spam_flag":      { "type": "boolean" },
        "feedback_id":    { "type": "boolean" },
        "esp_mailer":     { "type": "boolean" }
      }
    },
    "accounts": { "type": "array" }
  }
}'''

# Phase 93.8.c — credential store contribution (Phase 93.8.a-daemon
# manifest section). Daemon's `SubprocessNexoPlugin::credential_store()`
# reads this and constructs a `RemoteCredentialStore` round-tripping
# the four `plugin.credentials.*` JSON-RPCs to the handlers
# registered in `src/main.rs`. Accounts are the inner
# `EmailPluginConfig.accounts` entries keyed by `instance`.
[plugin.credentials_schema]
enabled = true
accounts_shape = "array"
