{
    "allOf": [
        {
            "oneOf": [
                {
                    "properties": {
                        "from": {
                            "description": "Who is the email from? Can be multiple people.",
                            "items": {
                                "$ref": "#/definitions/contact",
                                "type": "object"
                            },
                            "maxItems": 1,
                            "minItems": 1,
                            "type": "array"
                        },
                        "sender": {
                            "oneOf": [
                                {
                                    "type": "null"
                                },
                                {
                                    "$ref": "#/definitions/contact",
                                    "description": "Optional where From is one person."
                                }
                            ]
                        }
                    },
                    "required": [
                        "from"
                    ],
                    "type": "object"
                },
                {
                    "properties": {
                        "from": {
                            "description": "Who is the email from? Can be multiple people.",
                            "items": {
                                "$ref": "#/definitions/contact",
                                "type": "object"
                            },
                            "minItems": 2,
                            "type": "array"
                        },
                        "sender": {
                            "$ref": "#/definitions/contact",
                            "description": "Required where From is multiple people."
                        }
                    },
                    "required": [
                        "from",
                        "sender"
                    ],
                    "type": "object"
                }
            ],
            "type": "object"
        },
        {
            "properties": {
                "bcc": {
                    "description": "Optional. BCC Recipients of the email.",
                    "items": {
                        "$ref": "#/definitions/contact",
                        "type": "object"
                    },
                    "type": [
                        "array",
                        "null"
                    ]
                },
                "bodyParts": {
                    "description": "Body of the email. For a single content-type email, just put one in this array. It is presumed if you add multiple items to this array then it must be multipart. For multipart/alternative (multiple versions of the body such as text / html) add in one body part of type multipart/alternative which has multiple body parts.",
                    "items": {
                        "$ref": "#/definitions/bodyPart",
                        "type": "object"
                    },
                    "minItems": 1,
                    "type": "array"
                },
                "cc": {
                    "description": "Optional. CC Recipients of the email.",
                    "items": {
                        "$ref": "#/definitions/contact",
                        "type": "object"
                    },
                    "type": [
                        "array",
                        "null"
                    ]
                },
                "customHeaders": {
                    "additionalProperties": {
                        "description": "string values",
                        "type": "string"
                    },
                    "description": "Any non standard headers here - these should never overwrite the explicit headers.",
                    "type": [
                        "object",
                        "null"
                    ]
                },
                "date": {
                    "description": "The time the email was 'sent' (finished by a person/system). This is not necessarily the time the email entered a mail server.",
                    "format": "date-time",
                    "type": [
                        "string",
                        "null"
                    ]
                },
                "inReplyTo": {
                    "description": "Which unique MessageID this is in reply to.",
                    "type": [
                        "string",
                        "null"
                    ]
                },
                "replyTo": {
                    "description": "Optional. When hitting reply, who should the emails go to?",
                    "items": {
                        "$ref": "#/definitions/contact",
                        "type": "object"
                    },
                    "type": [
                        "array",
                        "null"
                    ]
                },
                "subject": {
                    "description": "Subject of the email.",
                    "type": [
                        "string",
                        "null"
                    ]
                },
                "to": {
                    "description": "Recipients of the email.",
                    "items": {
                        "$ref": "#/definitions/contact",
                        "type": "object"
                    },
                    "minItems": 1,
                    "type": "array"
                }
            },
            "required": [
                "to",
                "bodyParts"
            ],
            "type": "object"
        }
    ],
    "definitions": {
        "bodyPart": {
            "description": "Body part of an email",
            "oneOf": [
                {
                    "properties": {
                        "bodyParts": {
                            "type": "null"
                        },
                        "contentID": {
                            "description": "An ID used to link/inline this content body (e.g.) an image into a HTML body for example.",
                            "type": "string"
                        },
                        "contentTransferEncoding": {
                            "description": "Encoding of this body part. For a singular email this should go into the headers of the original email.",
                            "type": "string"
                        },
                        "contentType": {
                            "description": "RawContent type of the body. A single type such as text/plain, text/html.",
                            "type": "string"
                        },
                        "rawContent": {
                            "description": "Raw content of this body part. Use this OR bodyParts.",
                            "type": "string"
                        }
                    },
                    "required": [
                        "contentTransferEncoding",
                        "contentType",
                        "rawContent"
                    ],
                    "type": "object"
                },
                {
                    "properties": {
                        "bodyParts": {
                            "items": {
                                "$ref": "#/definitions/bodyPart"
                            },
                            "minItems": 1,
                            "type": "array"
                        },
                        "contentTransferEncoding": {
                            "description": "Encoding of this body part. For a singular email this should go into the headers of the original email.",
                            "type": [
                                "null",
                                "string"
                            ]
                        },
                        "contentType": {
                            "description": "Multipart type",
                            "enum": [
                                "multipart/alternative",
                                "multipart/mixed",
                                "multipart/related"
                            ],
                            "type": "string"
                        },
                        "rawContent": {
                            "type": "null"
                        }
                    },
                    "required": [
                        "contentTransferEncoding",
                        "contentType",
                        "bodyParts"
                    ],
                    "type": "object"
                }
            ],
            "type": "object"
        },
        "contact": {
            "description": "Minimum required output for a Contact",
            "properties": {
                "email": {
                    "_format": "email",
                    "description": "Email address of the contact.",
                    "type": "string"
                },
                "name": {
                    "description": "Name identifying the contact.",
                    "type": [
                        "string",
                        "null"
                    ]
                }
            },
            "required": [
                "email"
            ],
            "type": "object"
        }
    },
    "description": "Minimum required output for an Email",
    "title": "com.xcitestudios.schema.Network.Email",
    "type": "object"
}