{
  "$id": "https://intentschema.org/intents/communication/email/thread/list/v1.json",
  "fqdn": "org.intentschema.communication.email.thread.list.v1",
  "title": "List email threads",
  "description": "List email threads (conversations) matching a query or filter. Useful for thread-level triage.",
  "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 q-syntax, JMAP filter, Graph KQL)."
          },
          "filter": {
            "type": "object",
            "properties": {
              "labels_any": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "labels_all": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "is_unread": {
                "type": "boolean"
              },
              "after": {
                "type": "string",
                "format": "date-time"
              },
              "before": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 500,
            "default": 50
          },
          "cursor": {
            "type": "string"
          }
        }
      }
    }
  },
  "result": {
    "type": "object",
    "required": [
      "items"
    ],
    "properties": {
      "items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "external_id": {
              "type": "string"
            },
            "subject": {
              "type": "string"
            },
            "snippet": {
              "type": "string"
            },
            "message_count": {
              "type": "integer"
            },
            "latest_message_date": {
              "type": "string",
              "format": "date-time"
            },
            "labels": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "has_unread": {
              "type": "boolean"
            }
          }
        }
      },
      "next_cursor": {
        "type": "string"
      }
    }
  },
  "examples": [
    {
      "name": "unread threads in inbox",
      "value": {
        "target": {
          "system": "gmail"
        },
        "object": {
          "query": "label:inbox is:unread"
        }
      }
    }
  ]
}
