{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"type": "object",
	"properties": {
		"kind": {
			"type": "string",
			"const": "reader.config"
		},
		"schemaVersion": {
			"type": "number",
			"const": 3
		},
		"generator": {
			"type": "object",
			"properties": {
				"app": {
					"type": "string",
					"minLength": 1
				},
				"version": {
					"type": "string",
					"minLength": 1
				},
				"exportedAt": {
					"type": "string",
					"format": "date-time",
					"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
				}
			},
			"required": [
				"app",
				"version",
				"exportedAt"
			],
			"additionalProperties": false,
			"description": "Which reader wrote this file, and when."
		},
		"provenance": {
			"type": "object",
			"properties": {
				"accountConfigId": {
					"type": "string",
					"minLength": 25,
					"maxLength": 25
				},
				"instance": {
					"type": "string"
				}
			},
			"required": [
				"accountConfigId",
				"instance"
			],
			"additionalProperties": false,
			"description": "The instance this file was exported from. Never applied."
		},
		"accountConfig": {
			"type": "object",
			"properties": {
				"name": {
					"type": "string"
				},
				"defaultComposerFormat": {
					"type": "string"
				}
			},
			"required": [
				"name"
			],
			"additionalProperties": false
		},
		"accounts": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"accountId": {
						"type": "string",
						"minLength": 25,
						"maxLength": 25
					},
					"email": {
						"type": "string",
						"minLength": 1
					},
					"username": {
						"type": "string",
						"minLength": 1
					},
					"authType": {
						"type": "string",
						"enum": [
							"password",
							"oauthMicrosoft"
						]
					},
					"credentials": {
						"type": "object",
						"properties": {
							"required": {
								"type": "string",
								"enum": [
									"password",
									"oauth"
								]
							},
							"provider": {
								"type": "string",
								"const": "microsoft"
							}
						},
						"required": [
							"required"
						],
						"additionalProperties": false
					},
					"isActive": {
						"type": "boolean"
					},
					"imap": {
						"type": "object",
						"properties": {
							"host": {
								"type": "string",
								"minLength": 1
							},
							"port": {
								"type": "integer",
								"minimum": 1,
								"maximum": 65535
							},
							"tls": {
								"type": "boolean"
							},
							"startTls": {
								"type": "boolean"
							}
						},
						"required": [
							"host",
							"port",
							"tls",
							"startTls"
						],
						"additionalProperties": false
					},
					"smtp": {
						"type": "object",
						"properties": {
							"enabled": {
								"type": "boolean"
							},
							"host": {
								"type": "string"
							},
							"port": {
								"type": "integer",
								"minimum": 1,
								"maximum": 65535
							},
							"tls": {
								"type": "boolean"
							},
							"startTls": {
								"type": "boolean"
							},
							"username": {
								"type": "string"
							}
						},
						"required": [
							"enabled",
							"host",
							"port",
							"tls",
							"startTls",
							"username"
						],
						"additionalProperties": false
					},
					"displayName": {
						"type": "string"
					},
					"muted": {
						"anyOf": [
							{
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							{
								"type": "null"
							}
						]
					},
					"composeLanguages": {
						"type": "array",
						"items": {
							"type": "string",
							"minLength": 1
						}
					},
					"signature": {
						"type": "object",
						"properties": {
							"plainText": {
								"type": "string"
							},
							"html": {
								"type": "string"
							}
						},
						"required": [
							"plainText",
							"html"
						],
						"additionalProperties": false
					},
					"folderRoles": {
						"type": "array",
						"items": {
							"type": "object",
							"properties": {
								"role": {
									"type": "string",
									"enum": [
										"Inbox",
										"Drafts",
										"Sent",
										"Archive",
										"Junk",
										"Trash",
										"All",
										"Flagged"
									]
								},
								"folderPath": {
									"type": "string",
									"minLength": 1,
									"maxLength": 512
								}
							},
							"required": [
								"role",
								"folderPath"
							],
							"additionalProperties": false
						}
					},
					"folderOverrides": {
						"type": "array",
						"items": {
							"type": "object",
							"properties": {
								"folderPath": {
									"type": "string",
									"minLength": 1,
									"maxLength": 512
								},
								"displayName": {
									"type": "string"
								},
								"muted": {
									"anyOf": [
										{
											"type": "object",
											"properties": {
												"value": {
													"type": "boolean"
												},
												"setAt": {
													"type": "integer",
													"minimum": -9007199254740991,
													"maximum": 9007199254740991,
													"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
												},
												"setBy": {
													"type": "string"
												},
												"expiresAt": {
													"type": "integer",
													"minimum": -9007199254740991,
													"maximum": 9007199254740991
												},
												"reason": {
													"type": "string"
												}
											},
											"required": [
												"value",
												"setAt"
											],
											"additionalProperties": false
										},
										{
											"type": "null"
										}
									]
								}
							},
							"required": [
								"folderPath",
								"displayName",
								"muted"
							],
							"additionalProperties": false
						}
					},
					"pinnedFolders": {
						"type": "array",
						"items": {
							"type": "string",
							"minLength": 1,
							"maxLength": 512
						}
					}
				},
				"required": [
					"accountId",
					"email",
					"username",
					"authType",
					"credentials",
					"isActive",
					"imap",
					"smtp",
					"displayName",
					"muted",
					"composeLanguages",
					"signature",
					"folderRoles",
					"folderOverrides",
					"pinnedFolders"
				],
				"additionalProperties": false
			}
		},
		"labels": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"name": {
						"type": "string",
						"minLength": 1,
						"maxLength": 140
					},
					"color": {
						"type": "string",
						"enum": [
							"Default",
							"Red",
							"Orange",
							"Yellow",
							"Green",
							"Teal",
							"Blue",
							"Purple",
							"Gray"
						]
					}
				},
				"required": [
					"name",
					"color"
				],
				"additionalProperties": false
			}
		},
		"filters": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"name": {
						"type": "string",
						"minLength": 1,
						"maxLength": 256
					},
					"scope": {
						"type": "string",
						"enum": [
							"Standing",
							"Temporary"
						]
					},
					"expiresAt": {
						"anyOf": [
							{
								"type": "string",
								"format": "date-time",
								"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
							},
							{
								"type": "null"
							}
						]
					},
					"rule": {
						"type": "object",
						"properties": {
							"version": {
								"type": "number",
								"const": 1
							},
							"test": {
								"$ref": "#/$defs/FilterTest"
							}
						},
						"required": [
							"version",
							"test"
						],
						"additionalProperties": false
					},
					"priority": {
						"type": "integer",
						"minimum": -9007199254740991,
						"maximum": 9007199254740991
					},
					"stop": {
						"type": "boolean"
					},
					"actionLabelName": {
						"anyOf": [
							{
								"type": "string",
								"minLength": 1,
								"maxLength": 140
							},
							{
								"type": "null"
							}
						]
					},
					"actionFolder": {
						"anyOf": [
							{
								"type": "object",
								"properties": {
									"accountId": {
										"type": "string",
										"minLength": 25,
										"maxLength": 25
									},
									"folderPath": {
										"type": "string",
										"minLength": 1,
										"maxLength": 512
									}
								},
								"required": [
									"accountId",
									"folderPath"
								],
								"additionalProperties": false
							},
							{
								"type": "null"
							}
						]
					}
				},
				"required": [
					"name",
					"scope",
					"expiresAt",
					"rule",
					"priority",
					"stop",
					"actionLabelName",
					"actionFolder"
				],
				"additionalProperties": false
			}
		},
		"addressFlags": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"normalizedEmail": {
						"type": "string",
						"minLength": 1
					},
					"displayName": {
						"type": "string"
					},
					"flags": {
						"type": "object",
						"properties": {
							"trusted": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"blocked": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"neverSpam": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"muted": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"vip": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"category": {
								"type": "object",
								"properties": {
									"value": {
										"type": "string",
										"enum": [
											"uncategorized",
											"personal",
											"newsletter",
											"marketing",
											"automated",
											"transactional",
											"social",
											"coldOutreach"
										]
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"autoArchive": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							},
							"unsubscribed": {
								"type": "object",
								"properties": {
									"value": {
										"type": "boolean"
									},
									"setAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991,
										"description": "Epoch milliseconds the flag was set. 0 means it was set at an unknown time, on a row written before the field existed."
									},
									"setBy": {
										"type": "string"
									},
									"expiresAt": {
										"type": "integer",
										"minimum": -9007199254740991,
										"maximum": 9007199254740991
									},
									"reason": {
										"type": "string"
									}
								},
								"required": [
									"value",
									"setAt"
								],
								"additionalProperties": false
							}
						},
						"additionalProperties": false
					}
				},
				"required": [
					"normalizedEmail",
					"displayName",
					"flags"
				],
				"additionalProperties": false
			}
		},
		"clientPreferences": {
			"type": "object",
			"properties": {
				"theme": {
					"type": "string"
				},
				"density": {
					"type": "string"
				}
			},
			"required": [
				"theme",
				"density"
			],
			"additionalProperties": false
		},
		"messageDecisions": {
			"maxItems": 0,
			"type": "array",
			"items": {},
			"description": "Reserved for a later schema version; must be empty in v1."
		}
	},
	"required": [
		"kind",
		"schemaVersion",
		"generator",
		"provenance",
		"accountConfig",
		"accounts",
		"labels",
		"filters",
		"addressFlags"
	],
	"additionalProperties": false,
	"$defs": {
		"FilterTest": {
			"oneOf": [
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "allof"
						},
						"tests": {
							"minItems": 1,
							"maxItems": 50,
							"type": "array",
							"items": {
								"$ref": "#/$defs/FilterTest"
							}
						}
					},
					"required": [
						"test",
						"tests"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "anyof"
						},
						"tests": {
							"minItems": 1,
							"maxItems": 50,
							"type": "array",
							"items": {
								"$ref": "#/$defs/FilterTest"
							}
						}
					},
					"required": [
						"test",
						"tests"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "not"
						},
						"operand": {
							"$ref": "#/$defs/FilterTest"
						}
					},
					"required": [
						"test",
						"operand"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "header"
						},
						"match": {
							"type": "string",
							"enum": [
								"Is",
								"Contains"
							]
						},
						"header": {
							"type": "string",
							"enum": [
								"From",
								"Subject",
								"ListId"
							]
						},
						"key": {
							"type": "string",
							"maxLength": 256
						}
					},
					"required": [
						"test",
						"match",
						"header",
						"key"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "address"
						},
						"match": {
							"type": "string",
							"enum": [
								"Is",
								"Contains"
							]
						},
						"part": {
							"type": "string",
							"enum": [
								"All",
								"Localpart",
								"Domain",
								"RegistrableDomain"
							]
						},
						"key": {
							"type": "string",
							"maxLength": 256
						}
					},
					"required": [
						"test",
						"match",
						"part",
						"key"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "hasWords"
						},
						"words": {
							"type": "array",
							"items": {
								"type": "string",
								"maxLength": 256
							}
						}
					},
					"required": [
						"test",
						"words"
					],
					"additionalProperties": false
				},
				{
					"type": "object",
					"properties": {
						"test": {
							"type": "string",
							"const": "classification"
						},
						"label": {
							"type": "string",
							"enum": [
								"Spam",
								"Phishing",
								"Priority",
								"Personal",
								"Newsletter",
								"Marketing",
								"Automated",
								"Transactional",
								"Social",
								"ColdOutreach"
							]
						}
					},
					"required": [
						"test",
						"label"
					],
					"additionalProperties": false
				}
			]
		}
	},
	"$id": "https://schemas.remit.email/reader-config.v3.schema.json",
	"title": "reader configuration document, v3"
}
