{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://emaia.eu/docs/inbound-email-webhook-v1.schema.json",
  "title": "Inbound email webhook payload v1",
  "type": "object",
  "required": [
    "message_id",
    "event_type",
    "route_id",
    "route_address",
    "envelope_sender",
    "envelope_recipient",
    "raw_size_bytes",
    "raw_sha256",
    "raw"
  ],
  "properties": {
    "message_id": { "type": "string", "minLength": 1 },
    "event_type": {
      "type": "string",
      "enum": ["inbound.message.received", "inbound.message.test"]
    },
    "route_id": { "type": "string", "minLength": 1 },
    "route_address": { "type": "string", "minLength": 3 },
    "envelope_sender": { "type": "string" },
    "envelope_recipient": { "type": "string", "minLength": 3 },
    "rfc_message_id": { "type": "string" },
    "subject": { "type": "string" },
    "from": { "type": "string" },
    "raw_size_bytes": { "type": "integer", "minimum": 0 },
    "raw_sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "raw": {
      "oneOf": [
        {
          "type": "object",
          "required": ["mode", "content_type", "base64"],
          "properties": {
            "mode": { "const": "inline" },
            "content_type": { "const": "message/rfc822" },
            "base64": { "type": "string", "contentEncoding": "base64" }
          },
          "additionalProperties": true
        },
        {
          "type": "object",
          "required": ["mode", "content_type", "url"],
          "properties": {
            "mode": { "const": "fetch" },
            "content_type": { "const": "message/rfc822" },
            "url": { "type": "string", "format": "uri", "pattern": "^https://" }
          },
          "additionalProperties": true
        }
      ]
    }
  },
  "additionalProperties": true
}
