Skip to main content

Crate mail4agent

Crate mail4agent 

Source
Expand description

mail4agent daemon entrypoint.

Library face for the node kit and the standalone binary. crates.io 0.1.3 was binary-only; this package is 0.1.4 so the lib/run/spawn face can publish without yanking. The binary remains runnable with no node.

Boot sequence, deliberately split across two phases:

  1. Outside any tokio runtime (plain fn main): load config, open the sqlite mail4agent_store_sqlite::Db, and run this crate’s schema migrations via mail4agent_store_sqlite::Db::run_migrations_blocking – the daemon is outside the runtime at that point, so the blocking entry point is the correct one, rather than relying on try_lock()’s non-panicking behaviour inside an already-running one.
  2. Inside a manually-built tokio runtime: bootstrap the first operator participant if none exists yet, then serve.

The engine and its store stay synchronous throughout (see service.rs for the async facade every handler goes through instead of touching either directly – mail4agent/CLAUDE.md, “The engine is synchronous; the daemon is not”). Every /mail/* and /mcp handler additionally resolves which SESSION of the authenticated account is calling, from the connection itself (src/identity.rs) – that resolution needs this server’s own bound address, which is why serve builds one [AppState] shared by every route rather than handing each route a bare Arc<MailboxService>.

Serves via into_make_service_with_connect_info::<SocketAddr>(), never plain into_make_service() – the latter never inserts a ConnectInfo<SocketAddr> extension, which is exactly the fact src/identity.rs’s whole session-resolution mechanism depends on.

Modules§

control
Local control channel: POST /control/{drain,reload,handoff}.

Structs§

MailboxJoinHandle
Join handle for a mailbox started by spawn. Dropping detaches the thread; the process exit still tears the socket down.

Enums§

MainError

Functions§

main
run
Run the mailbox until a process shutdown signal. Does not install a tracing subscriber — the standalone binary calls main, the node kit calls spawn on a background thread.
spawn
Start the mailbox daemon on a background thread. Same config and DB rules as the standalone binary. Safe to call from a process that already installed tracing (the node kit).