{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "description": "The delivery configuration",
    "markdownDescription": "The [delivery](https://docs.halon.io/manual/queue.html) configuration",
    "additionalProperties": false,
    "required": [
        "version"
    ],
    "properties": {
        "version": {
            "type": "string",
            "enum": [
                "6.11"
            ],
            "description": "The software version the configuration was created for"
        },
        "delivery": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "conditions": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                            "if",
                            "then"
                        ],
                        "properties": {
                            "if": {
                                "type": "object",
                                "additionalProperties": false,
                                "properties": {
                                    "jobid": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/jobid"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/jobid"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "tenantid": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/tenantid"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/tenantid"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "grouping": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/grouping"
                                            },
                                            {
                                                "$ref": "#/definitions/wildcard"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/grouping"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/wildcard"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "localip": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/ipv4"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv4net"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv6"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv6net"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/ipv4"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv4net"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv6"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv6net"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "remoteip": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/ipv4"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv4net"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv6"
                                            },
                                            {
                                                "$ref": "#/definitions/ipv6net"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/ipv4"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv4net"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv6"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/ipv6net"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "transportid": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/objectid"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/objectid"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "recipientdomain": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/domain"
                                            },
                                            {
                                                "$ref": "#/definitions/wildcard"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/domain"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/wildcard"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "remotemx": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/definitions/domain"
                                            },
                                            {
                                                "$ref": "#/definitions/wildcard"
                                            },
                                            {
                                                "$ref": "#/definitions/regex"
                                            },
                                            {
                                                "$ref": "#/definitions/list"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "items": {
                                                    "oneOf": [
                                                        {
                                                            "$ref": "#/definitions/domain"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/wildcard"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/regex"
                                                        },
                                                        {
                                                            "$ref": "#/definitions/list"
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    }
                                }
                            },
                            "then": {
                                "$ref": "#/definitions/settings"
                            }
                        }
                    }
                },
                "default": {
                    "$ref": "#/definitions/settings"
                }
            }
        }
    },
    "definitions": {
        "list": {
            "type": "string",
            "pattern": "^@[a-zA-Z0-9-_.]+$",
            "minLength": 2,
            "maxLength": 64,
            "description": "A \"named\" list of values that needs to be defined in the smtpd-app.yaml file"
        },
        "settings": {
            "type": "object",
            "additionalProperties": false,
            "minProperties": 1,
            "properties": {
                "tls": {
                    "type": "object",
                    "description": "The TLS settings",
                    "additionalProperties": false,
                    "properties": {
                        "mode": {
                            "type": "string",
                            "enum": [
                                "disabled",
                                "optional",
                                "optional_verify",
                                "require",
                                "require_verify",
                                "dane",
                                "dane_require",
                                "dane_fallback_require",
                                "dane_fallback_require_verify",
                                "trust"
                            ],
                            "description": "The TLS mode"
                        },
                        "protocols": {
                            "type": "string",
                            "description": "Which TLS protocols to support",
                            "default": "!SSLv2,!SSLv3,!TLSv1,!TLSv1.1"
                        },
                        "ciphers": {
                            "type": "string",
                            "description": "Which TLS ciphers to support (<=TLSv1.2)",
                            "default": "aNULL:-aNULL:HIGH:MEDIUM:+RC4:@STRENGTH"
                        },
                        "ciphersuites": {
                            "type": "string",
                            "description": "Which TLS cipher suites to support (TLSv1.3)"
                        },
                        "groups": {
                            "type": "string",
                            "description": "Which TLS supported groups to use for key exchange"
                        },
                        "trustanchor": {
                            "type": "array",
                            "uniqueItems": false,
                            "minItems": 1,
                            "description": "The TLS trust anchors",
                            "items": {
                                "type": "object",
                                "required": [
                                    "data"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                    "selector": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 1,
                                        "default": 0,
                                        "description": "The trust selector"
                                    },
                                    "mtype": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 2,
                                        "default": 0,
                                        "description": "The trust match type"
                                    },
                                    "data": {
                                        "type": "string",
                                        "description": "The trust data (hex encoded)"
                                    }
                                }
                            }
                        }
                    }
                },
                "pooling": {
                    "type": "object",
                    "description": "The connection pooling settings",
                    "additionalProperties": false,
                    "properties": {
                        "enabled": {
                            "type": "boolean",
                            "default": false,
                            "description": "If connection pooling should be enabled"
                        },
                        "evictable": {
                            "type": "boolean",
                            "default": true,
                            "description": "If the connection is evictable from the cache due to the cache replacement policy (LRU) if the cache is full"
                        },
                        "timeout": {
                            "oneOf": [
                                {
                                    "type": "integer",
                                    "minimum": 0,
                                    "default": 5,
                                    "description": "The idle timeout (in seconds) before an unused connection is closed"
                                },
                                {
                                    "$ref": "#/definitions/timeformat",
                                    "description": "The idle timeout (in time format) before an unused connection is closed"
                                }
                            ]
                        },
                        "transactions": {
                            "type": "integer",
                            "minimum": 0,
                            "default": 0,
                            "description": "The transactions per connection (0 is unlimited)"
                        }
                    }
                },
                "timeout": {
                    "type": "object",
                    "description": "The connection timeout settings",
                    "additionalProperties": false,
                    "properties": {
                        "connect": {
                            "oneOf": [
                                {
                                    "type": "integer",
                                    "minimum": 0,
                                    "default": 30,
                                    "description": "The connect timeout (in seconds)"
                                },
                                {
                                    "$ref": "#/definitions/timeformat",
                                    "description": "The connect timeout (in time format)"
                                }
                            ]
                        },
                        "smtp": {
                            "type": "object",
                            "description": "The connection timeout settings",
                            "additionalProperties": false,
                            "properties": {
                                "BANNER": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "HELO": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "EHLO": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "LHLO": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "STARTTLS": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "AUTH-CRAM-MD5": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "AUTH-PLAIN": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "AUTH-LOGIN": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "AUTH-LOGIN-USER": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "AUTH": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "XCLIENT": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "MAIL": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "RCPT": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 300
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "DATA": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 120
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "EOD": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 600
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "RSET": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 30
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "NOOP": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 30
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                },
                                "QUIT": {
                                    "oneOf": [
                                        {
                                            "type": "integer",
                                            "minimum": 0,
                                            "default": 30
                                        },
                                        {
                                            "$ref": "#/definitions/timeformat"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "retry": {
                    "type": "object",
                    "description": "The retry settings",
                    "required": [
                        "intervals"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "intervals": {
                            "type": "array",
                            "uniqueItems": false,
                            "minItems": 1,
                            "description": "The retry intervals",
                            "items": {
                                "type": "object",
                                "required": [
                                    "interval"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                    "interval": {
                                        "oneOf": [
                                            {
                                                "type": "integer",
                                                "minimum": 0,
                                                "description": "The interval (in seconds)"
                                            },
                                            {
                                                "$ref": "#/definitions/timeformat",
                                                "description": "The interval (in time format)"
                                            }
                                        ]
                                    },
                                    "notify": {
                                        "type": "boolean",
                                        "default": false,
                                        "description": "If a delayed notification should be sent"
                                    }
                                }
                            }
                        }
                    }
                },
                "extensions": {
                    "type": "object",
                    "description": "SMTP extensions",
                    "additionalProperties": false,
                    "properties": {
                        "chunking": {
                            "type": "boolean",
                            "default": true,
                            "description": "Enable support for the CHUNKING extension"
                        },
                        "pipelining": {
                            "type": "boolean",
                            "default": true,
                            "description": "Enable support for the PIPELINING extension"
                        }
                    }
                }
            }
        },
        "jobid": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$).*$",
            "minLength": 1
        },
        "tenantid": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$).*$",
            "minLength": 1
        },
        "grouping": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$).*$",
            "minLength": 1
        },
        "objectid": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9-_.]+$",
            "minLength": 1,
            "maxLength": 64
        },
        "domain": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$)[a-zA-Z0-9_.-]+$",
            "minLength": 1
        },
        "ipv4": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$)(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\.(?!$)|$)){4}$",
            "minLength": 7
        },
        "ipv4net": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$)(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\.(?!$)|\/[0-9]+$)){4}$",
            "minLength": 9
        },
        "ipv6": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$)(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$",
            "minLength": 3
        },
        "ipv6net": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|[#@].*|.*[*].*)$)(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/[0-9]+$",
            "minLength": 3
        },
        "regex": {
            "type": "string",
            "pattern": "^/.*/$",
            "minLength": 2
        },
        "wildcard": {
            "type": "string",
            "pattern": "^[*][.][a-zA-Z0-9_.-]+$",
            "minLength": 3
        },
        "timeformat": {
            "type": "string",
            "pattern": "^([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?$",
            "minLength": 2
        }
    }
}