{
  "$id": "https://intentschema.org/intents/communication/email/message/list/v1.json",
  "fqdn": "org.intentschema.communication.email.message.list.v1",
  "title": "List email messages",
  "description": "Searches a user's mailbox and returns message summaries matching the given query and structured filter.",
  "payload": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
      "target"
    ],
    "properties": {
      "target": {
        "$ref": "https://intentschema.org/common/target/v1.json"
      },
      "object": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Provider-specific search string (Gmail syntax, JMAP filter string, Outlook KQL). Applied alongside `filter` if both are provided."
          },
          "filter": {
            "type": "object",
            "description": "Structured filter, JMAP-inspired.",
            "properties": {
              "from": {
                "type": "string"
              },
              "to": {
                "type": "string"
              },
              "subject": {
                "type": "string"
              },
              "body": {
                "type": "string"
              },
              "has_attachment": {
                "type": "boolean"
              },
              "is_unread": {
                "type": "boolean"
              },
              "after": {
                "type": "string",
                "format": "date-time"
              },
              "before": {
                "type": "string",
                "format": "date-time"
              },
              "labels_any": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "labels_all": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 500,
            "default": 50
          },
          "cursor": {
            "type": "string",
            "description": "Opaque pagination cursor returned by a prior search."
          }
        }
      }
    }
  },
  "result": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
      "messages"
    ],
    "properties": {
      "messages": {
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "external_id",
            "subject"
          ],
          "properties": {
            "external_id": {
              "type": "string"
            },
            "thread_id": {
              "type": "string"
            },
            "from": {
              "type": "string",
              "format": "email",
              "description": "RFC 5321 mailbox. Plain address (jane@example.com) or with display name (\"Jane Doe\" <jane@example.com>)."
            },
            "to": {
              "type": "array",
              "items": {
                "type": "string",
                "format": "email",
                "description": "RFC 5321 mailbox. Plain address (jane@example.com) or with display name (\"Jane Doe\" <jane@example.com>)."
              }
            },
            "subject": {
              "type": "string"
            },
            "snippet": {
              "type": "string",
              "description": "Short plaintext preview of the body."
            },
            "date": {
              "type": "string",
              "format": "date-time"
            },
            "labels": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "is_unread": {
              "type": "boolean"
            },
            "has_attachments": {
              "type": "boolean"
            }
          }
        }
      },
      "next_cursor": {
        "type": "string",
        "description": "Present when more results are available."
      },
      "estimated_total": {
        "type": "integer",
        "description": "Optional provider estimate of total matches."
      }
    }
  },
  "examples": [
    {
      "name": "query-string search",
      "value": {
        "target": {
          "system": "gmail"
        },
        "object": {
          "query": "from:jane@example.com is:unread",
          "limit": 20
        }
      }
    },
    {
      "name": "structured filter with pagination",
      "value": {
        "target": {
          "system": "gmail"
        },
        "object": {
          "filter": {
            "from": "jane@example.com",
            "has_attachment": true,
            "after": "2026-01-01T00:00:00Z"
          },
          "limit": 50,
          "cursor": "opaque-cursor-from-prior-result"
        }
      }
    }
  ]
}
