Kantoor.Karta.InboundPayload (Kantoor v1.0.0)

Pure parser for Karta's inbound push (type: "message.received").

auth is the sender-authentication verdict Karta computed. Karta sends it as data.authentication (Karta.Auth.to_map/1): spf and spf_helo are objects with a result and domain; dkim and dmarc are lists of such objects (the DMARC domain is the From domain it judged); arc and authserv_id are ignored here. The field is null for a message Karta did not check.

The verdict is normalised to a flat map of string keys, or nil when Karta sent nothing: spf, dkim, dmarc (result strings), and spf_domain, dkim_domain, header_from (the domains they covered). Older, still accepted forms: data.auth (already that flat map) and data.authentication_results (an RFC 8601 header value). It is the only source of the verdict: headers inside the message are never trusted.

spam comes only from the signed data.scan.spam verdict. A scanned message with is_spam: true enters the mailbox junk folder. Raw message headers never set this verdict.

raw (base64 of the RFC822 message) is optional: the notify-only variant omits it and Kantoor fetches the body separately. delivery_id (data.id) is the stable dedupe key; it equals the webhook-id header.

Summary

Functions

Parses a JSON body (binary) or an already decoded map. Option :webhook_id additionally requires it to equal data.id.

Parses an RFC 8601 Authentication-Results value (as reported by Karta) into the normalised verdict map; nil when it holds no spf/dkim/dmarc result.

True when the push carries the message body.

Types

error()

@type error() ::
  :invalid_json
  | {:unsupported_type, term()}
  | {:missing_field, String.t()}
  | {:invalid_field, String.t()}
  | :invalid_raw
  | :webhook_id_mismatch

t()

@type t() :: %Kantoor.Karta.InboundPayload{
  auth: map() | nil,
  delivery_id: String.t(),
  mail_from: String.t() | nil,
  message_id: String.t(),
  raw: binary() | nil,
  rcpt_to: String.t(),
  received_at: DateTime.t() | nil,
  scan: map() | nil,
  size: non_neg_integer() | nil,
  spam: boolean(),
  subject: String.t() | nil
}

Functions

parse(body, opts \\ [])

@spec parse(binary() | map(), keyword()) :: {:ok, t()} | {:error, error()}

Parses a JSON body (binary) or an already decoded map. Option :webhook_id additionally requires it to equal data.id.

parse_authentication_results(header)

@spec parse_authentication_results(String.t()) :: map() | nil

Parses an RFC 8601 Authentication-Results value (as reported by Karta) into the normalised verdict map; nil when it holds no spf/dkim/dmarc result.

raw?(inbound_payload)

@spec raw?(t()) :: boolean()

True when the push carries the message body.