# `MailglassInbound.Ingress.Plug`
[🔗](https://github.com/szTheory/mailglass/blob/v1.4.0/lib/mailglass_inbound/ingress/plug.ex#L1)

Public inbound ingress plug for `mailglass_inbound`.

The plug verifies provider requests first, resolves tenant scope second, then
normalizes and persists the canonical inbound message without executing any mailbox.

## Telemetry + post-commit broadcast

The whole request is wrapped in a `[:mailglass_inbound, :ingress, :request, *]`
span via `MailglassInbound.Telemetry`.

After `Persist.persist/2` returns `{:ok, %{status: :inserted}}` — i.e. AFTER the
`repo.transact` inside `Persist.persist/2` has committed — the plug broadcasts a
PII-free `{:inbound_record_inserted, record_id, %{provider:, record_type:}}`
message on `Mailglass.PubSub` to the per-tenant topic from
`MailglassInbound.PubSub.Topics.inbound_record_inserted/1`. The broadcast runs
OUTSIDE the transaction and never rolls it back:
the committed `InboundRecord` is the durable source of truth, PubSub is the
realtime fan-out for the admin LiveView. A `:duplicate` result
broadcasts nothing.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
