openapi: 3.1.0
info:
  title: PineMail
  version: 0.19.0
  summary: Transactional email API for EU organisations
  description: |
    Two kinds of key, both passed as `Authorization: Bearer ...`:
    project keys (`pm_live_`, made on the project's API keys page; a
    sending key only sends, from its domain, or from any verified one if
    it has none) reach emails, domains,
    mailboxes, webhooks, templates and the directory of their project.
    Account keys (`pm_acct_`, made under Buckets → Access keys) reach the
    account's files, buckets and S3 keys. Each operation lists the scope
    it needs under security. Full access is every scope that exists when
    the key is made; later scopes are not added. Project keys made before
    account keys keep the storage scopes they were given. S3 keys, for
    objects over S3 at s3.pinemail.app, cannot create or delete buckets:
    create them here first. A key stops working when it is revoked or the
    account is suspended. A resource that is not yours answers 404.

    Public JSON uses snake_case. Errors are RFC 7807 problem+json.
    Send is asynchronous: `202` means queued. Poll `GET /v1/emails/{id}`.
    Repeat the same `Idempotency-Key` when retrying a POST.
    `from` accepts `addr@domain` or `Name <addr@domain>` and must use a
    verified domain on the project (or @pinemail.app). Provide `html` or `text`.

    Webhook signing and events: see /docs/webhooks.

    An app or AI agent can create the account itself: POST /v1/signup with
    the person's address, then poll POST /v1/signup/{id}/token. The person
    confirms with one click in the mail PineMail sends; the agent then gets
    an account key with projects:write, lists the account's projects
    (GET /v1/projects) and makes a project key (POST /v1/projects/{id}/keys)
    for domains, mailboxes and sending. The person sees and revokes the key
    under Account → Connected apps.

    AI agents reach these operations as MCP tools at https://pinemail.app/mcp,
    with the same keys and scopes: see /docs/mcp. A person can connect an
    assistant with a login instead (OAuth, with the consent page at
    /oauth/consent); its token reaches the mailbox mail routes and
    GET /v1/mailboxes with the scopes the person allowed, and the project
    routes answer 403 to it.
  contact:
    email: contact@pinemail.app
servers:
  - url: https://pinemail.app
    description: Production — POST /v1/emails
  - url: /api
    description: Same instance at /api/v1
tags:
  - name: Agent sign-up
    description: |
      An account created by an app or AI agent, finished by one click from
      the person whose address it is (the pattern of the OAuth device flow,
      RFC 8628, with the link sent by mail). No key is needed to start.
      The agent never gets the link, so it cannot confirm for the person.
  - name: Projects
    description: |
      The account's projects and their API keys, for an account key with
      projects:write (from agent sign-up, or made under Buckets → Access keys).
  - name: Limits
    description: |
      The limits on what a key reaches, with what is used of each. Limits
      belong to the account that owns the projects; a mailbox can have a
      daily cap of its own on top.
  - name: Emails
  - name: Domains
    description: |
      A domain is `pending` until the account proves it holds it with the
      OWNERSHIP TXT record at `_pinemail.<domain>`; only then can it send,
      have mailboxes or receive mail. INBOUND is the MX for receiving mail.
  - name: Mailboxes
  - name: Mailbox mail
    description: |
      The mail and calendar of the project's mailboxes, for an assistant or
      agent acting for the account owner. The scopes mail:read, mail:draft,
      mail:send, mail:organize and calendar:read are picked on purpose when a key is made;
      Full access leaves them out. The account owner decides which mailboxes
      and correspondents these routes reach, and whether personal data is
      masked (on by default): answers then carry placeholders such as
      [EMAIL_K3F9Q2ZA], masking: on and masked counts, HTML bodies are left
      out, drafts and sends get the real values back (422 for a placeholder
      that cannot be put back), and a read that cannot be masked in time is
      503 with Retry-After and no content.
  - name: Webhooks
  - name: Templates
  - name: Directory
  - name: Files
    description: |
      The account's Drive: its own files and folders (not mailboxes'
      files), reached from any of the account's projects. Needs PineKeep
      on for the account.
  - name: Uploads
    description: Files of any size, sent in parts.
  - name: Buckets
    description: The account's S3 buckets and their objects. Needs PineKeep on for the account.
  - name: S3 keys
    description: Access keys for the S3 endpoint.
paths:
  /v1/signup:
    post:
      tags: [Agent sign-up]
      operationId: startAgentSignup
      summary: Start a sign-up for a person's address
      description: |
        PineMail mails a link to `email`. The person opens it and either
        creates the account (name, password, terms) or, if the address has
        an account, signs in and approves. Poll `poll_url` with `poll_token`
        every `interval` seconds until it answers `approved`. The request
        lasts an hour. Limits: a few per minute and ten an hour per IP
        address, one waiting request per email address, and a daily cap.
        Addresses at pinemail.app are refused.
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email]
              properties:
                email: { type: string, format: email, description: The person's address. }
                name: { type: string, maxLength: 80, description: Suggested name for the account. }
                agent: { type: string, maxLength: 60, description: What the app calls itself, shown to the person. }
      responses:
        "202":
          description: Waiting for the person
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: asu_01JXYZ }
                  status: { type: string, const: pending }
                  poll_token: { type: string }
                  poll_url: { type: string, example: /v1/signup/asu_01JXYZ/token }
                  interval: { type: integer, example: 5 }
                  expires_at: { type: string, format: date-time }
        "422":
          $ref: "#/components/responses/Problem"
        "429":
          $ref: "#/components/responses/Problem"
        "503":
          $ref: "#/components/responses/Problem"
  /v1/signup/{id}/token:
    post:
      tags: [Agent sign-up]
      operationId: collectAgentSignupKey
      summary: Collect the account key once the person has confirmed
      description: |
        `202` while the person has not confirmed. `200` once with the account
        key (pm_acct_, scopes projects:write and buckets:read). `410` when the
        request expired, the key was already collected, or the token does not
        match.
      security: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [poll_token]
              properties:
                poll_token: { type: string }
      responses:
        "200":
          description: Confirmed; the key, shown this once
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string, const: approved }
                  email: { type: string }
                  account_key: { type: string, example: pm_acct_... }
                  account_key_id: { type: string }
                  next: { type: string }
        "202":
          description: Not confirmed yet
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string, const: pending }
                  interval: { type: integer }
                  expires_at: { type: string, format: date-time }
        "410":
          $ref: "#/components/responses/Problem"
        "429":
          $ref: "#/components/responses/Problem"
  /v1/projects:
    get:
      tags: [Projects]
      operationId: listProjects
      description: The account's projects. A new account has one.
      security: [{ accountKey: [projects:write] }]
      responses:
        "200":
          description: Projects
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/Project" }
    post:
      tags: [Projects]
      operationId: createProject
      description: A new project, within the plan's number of projects. The slug comes from the name unless given.
      security: [{ accountKey: [projects:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, maxLength: 80 }
                slug: { type: string, maxLength: 60, pattern: "^[a-z0-9-]+$" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Project" }
        "403":
          $ref: "#/components/responses/Problem"
        "409":
          $ref: "#/components/responses/Problem"
        "422":
          $ref: "#/components/responses/Problem"
  /v1/projects/{id}/keys:
    get:
      tags: [Projects]
      operationId: listProjectKeys
      description: The project's live API keys, never their tokens.
      security: [{ accountKey: [projects:write] }]
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        "200":
          description: Keys
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/ProjectKey" }
        "404":
          $ref: "#/components/responses/Problem"
    post:
      tags: [Projects]
      operationId: createProjectKey
      description: |
        A project key (pm_live_) with the project's full access, or only the
        project scopes given. The token is in this response only. Sending keys
        locked to a domain, and revoking, are in the dashboard.
      security: [{ accountKey: [projects:write] }]
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, maxLength: 60 }
                scopes: { type: array, items: { type: string }, description: Project scopes; leave out for full access. }
      responses:
        "201":
          description: Created; the token, shown this once
          content:
            application/json:
              schema:
                allOf:
                  - { $ref: "#/components/schemas/ProjectKey" }
                  - type: object
                    properties:
                      token: { type: string, example: pm_live_... }
        "404":
          $ref: "#/components/responses/Problem"
        "422":
          $ref: "#/components/responses/Problem"
  /v1/emails:
    post:
      tags: [Emails]
      operationId: sendEmail
      summary: Queue a transactional email
      description: >-
        A sending key (made as such on the project's API keys page) sends only
        from its domain and, when it lists them, from its From addresses; any
        other `from` answers 403 with the allowed domain or addresses in the
        detail. A full project key sends from any verified domain of the project.
      security: [{ bearerAuth: [emails:send] }]
      parameters:
        - in: header
          name: Idempotency-Key
          schema: { type: string, maxLength: 200 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SendEmail"
            example:
              from: Acme <hello@pinemail.app>
              to: [ada@example.com]
              subject: Welcome
              html: "<p>Hello from your app.</p>"
              reply_to: support@example.com
      responses:
        "202":
          description: Queued
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/QueuedEmail"
        "400":
          $ref: "#/components/responses/Problem"
        "401":
          $ref: "#/components/responses/Problem"
        "403":
          $ref: "#/components/responses/Problem"
        "422":
          $ref: "#/components/responses/Problem"
        "429":
          description: >-
            quota_exceeded: a send limit of the account is reached, this month's
            through the API, the last 24 hours' or the last minute's, or the
            request limit per key. Retry-After gives the seconds until a send may
            go: to the 1st of next month, an hour, or a minute. GET /v1/limits
            shows what is used of each.
    get:
      tags: [Emails]
      operationId: listEmails
      summary: List recent emails in the project
      security: [{ bearerAuth: [emails:read] }]
      parameters:
        - in: query
          name: limit
          schema: { type: integer, minimum: 1, maximum: 200, default: 50 }
        - in: query
          name: cursor
          description: The next_cursor of the page before.
          schema: { type: string }
        - in: query
          name: from
          description: One sender's emails, by address (case does not matter).
          schema: { type: string, example: hello@example.com }
      responses:
        "200":
          description: Newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/EmailSummary"
                  next_cursor:
                    type: string
                    nullable: true
  /v1/emails/batch:
    post:
      tags: [Emails]
      operationId: sendEmailBatch
      summary: Queue up to 100 emails in one call
      description: Each item is a SendEmail without attachments. Each is accepted or refused on its own; data lists them in order. An Idempotency-Key covers the whole call.
      security: [{ bearerAuth: [emails:send] }]
      parameters:
        - in: header
          name: Idempotency-Key
          schema: { type: string, maxLength: 200 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              minItems: 1
              maxItems: 100
              items: { $ref: "#/components/schemas/SendEmail" }
      responses:
        "200":
          description: One entry per email, a QueuedEmail or {error}
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      oneOf:
                        - $ref: "#/components/schemas/QueuedEmail"
                        - { type: object, properties: { error: { type: object, additionalProperties: { type: string } } } }
                  accepted: { type: integer }
                  refused: { type: integer }
  /v1/emails/{id}/cancel:
    post:
      tags: [Emails]
      operationId: cancelEmail
      summary: Cancel a scheduled email, or one held with undo_seconds
      security: [{ bearerAuth: [emails:send] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200": { description: "{id, status: canceled}" }
        "404": { description: No scheduled email with that id }
  /v1/limits:
    get:
      tags: [Limits]
      operationId: getLimits
      description: >-
        The limits that apply to what this key reaches, with what is used of
        each. Sending counts recipients (to, cc and bcc): this calendar month
        (UTC) per way of sending, and in the last 24 hours and the last
        minute for both together, as the checks before a send count them.
        A limit of null means none. Any key may call it, without a scope. A
        project key and an account key get their own account. A person's
        sign-in (an assistant connected with a login) gets each account whose
        mailboxes they reach: their own in full ("owner"), and for a mailbox
        they only sign in to, its owner's sending limits ("mailbox"). The
        key's own account is first. Each mailbox's own daily cap counts
        messages sent in the last 24 hours.
      security: [{ bearerAuth: [] }, { accountKey: [] }]
      responses:
        "200":
          description: The accounts and their mailboxes
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/AccountLimits" }
        "401": { description: No key, or a key that is not valid }
  /v1/suppressions:
    get:
      tags: [Emails]
      operationId: listSuppressions
      summary: The addresses the project does not send to
      description: |
        The do-not-send list. It covers the sending API and every mailbox of
        the project: the mail app, the mailbox API and SMTP. A hard bounce or
        a spam complaint adds an address by itself (reason bounce or
        complaint); one added here or in the mail app has reason manual.
        When the project has chosen a number of soft bounces in a row (in its
        settings), an address that reaches it is added with reason
        soft_bounce. At most the newest 500.
      security: [{ bearerAuth: [emails:read] }]
      responses:
        "200":
          description: Newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        address: { type: string }
                        reason: { type: string, enum: [bounce, complaint, manual, soft_bounce] }
                        created_at: { type: string, format: date-time }
    post:
      tags: [Emails]
      operationId: addSuppressions
      summary: Add addresses the project does not send to
      description: |
        For someone who asked not to be written to. A send that includes a
        listed address is refused with 422 (the API and the mailbox API) or
        550 (SMTP), and a scheduled or held email to it is canceled when its
        time comes. Addresses already listed keep their reason.
      security: [{ bearerAuth: [suppressions:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [addresses]
              properties:
                addresses: { type: array, minItems: 1, maxItems: 100, items: { type: string } }
      responses:
        "201": { description: "{added}" }
        "422": { description: Not a list of addresses }
  /v1/suppressions/{address}:
    get:
      tags: [Emails]
      operationId: getSuppression
      summary: Whether the project sends to an address
      security: [{ bearerAuth: [emails:read] }]
      parameters:
        - { in: path, name: address, required: true, schema: { type: string } }
      responses:
        "200":
          description: On the list
          content:
            application/json:
              schema:
                type: object
                properties:
                  address: { type: string }
                  reason: { type: string, enum: [bounce, complaint, manual, soft_bounce] }
                  created_at: { type: string, format: date-time }
                  soft_bounces:
                    nullable: true
                    allOf: [{ $ref: "#/components/schemas/SoftBounce" }]
        "404": { description: Not on the list }
    delete:
      tags: [Emails]
      operationId: removeSuppression
      summary: Send to an address again
      security: [{ bearerAuth: [suppressions:write] }]
      parameters:
        - { in: path, name: address, required: true, schema: { type: string } }
      responses:
        "204": { description: Taken off the list }
        "404": { description: Not on the list }
  /v1/soft-bounces:
    get:
      tags: [Emails]
      operationId: listSoftBounces
      summary: Addresses with temporary bounces
      description: |
        Temporary bounces that SES reports (a full mailbox, a server that is
        down), for mail through the API and from the project's mailboxes,
        latest first. They do not put an address on the do-not-send list by
        themselves; in_a_row starts over when mail to the address is
        delivered. limit is the number in a row after which an address is
        listed (reason soft_bounce), or null for never; it is chosen in the
        project's settings.
      security: [{ bearerAuth: [emails:read] }]
      parameters:
        - in: query
          name: limit
          schema: { type: integer, minimum: 1, maximum: 200, default: 50 }
        - in: query
          name: cursor
          schema: { type: string }
      responses:
        "200":
          description: Latest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/SoftBounce" } }
                  next_cursor: { type: string, nullable: true }
                  limit: { type: integer, nullable: true }
  /v1/soft-bounces/{address}:
    get:
      tags: [Emails]
      operationId: getSoftBounce
      summary: One address's temporary bounces
      security: [{ bearerAuth: [emails:read] }]
      parameters:
        - { in: path, name: address, required: true, schema: { type: string } }
      responses:
        "200":
          description: The counts
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SoftBounce"
        "404": { description: No soft bounces for the address }
  /v1/emails/{id}:
    patch:
      tags: [Emails]
      operationId: rescheduleEmail
      summary: Move a scheduled email to a new time
      security: [{ bearerAuth: [emails:send] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [scheduled_at]
              properties:
                scheduled_at: { type: string, format: date-time }
      responses:
        "200": { description: "{id, status: scheduled, scheduled_at}" }
        "404": { description: No scheduled email with that id }
        "422": { description: A time that has passed or is more than 30 days ahead }
    get:
      tags: [Emails]
      operationId: getEmail
      summary: Fetch one email and its timeline
      security: [{ bearerAuth: [emails:read] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Email
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EmailDetail"
        "404":
          $ref: "#/components/responses/Problem"
  /v1/domains:
    get:
      tags: [Domains]
      operationId: listDomains
      summary: List sending domains
      security: [{ bearerAuth: [domains:read] }]
      responses:
        "200":
          description: Domains
    post:
      tags: [Domains]
      operationId: createDomain
      summary: Add a domain; the response lists the DNS records to publish, OWNERSHIP first
      security: [{ bearerAuth: [domains:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [domain]
              properties:
                domain: { type: string, example: example.com }
                region: { type: string, example: eu-north-1 }
                receive_mail:
                  type: boolean
                  default: true
                  description: false when another service receives the domain's mail; no INBOUND record then.
      responses:
        "201":
          description: Created, DNS records included
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Domain" }
        "422":
          $ref: "#/components/responses/Problem"
  /v1/domains/{id}:
    get:
      tags: [Domains]
      operationId: getDomain
      security: [{ bearerAuth: [domains:read] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Domain and DNS records
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Domain" }
        "404":
          $ref: "#/components/responses/Problem"
    patch:
      tags: [Domains]
      operationId: updateDomain
      summary: Change the choices that decide the records
      description: |
        `receive_mail: false` leaves the INBOUND record out and PineMail takes
        no mail for the domain, for a domain whose mail another service
        receives. `dmarc_policy` is written into the DMARC record.
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                receive_mail: { type: boolean }
                dmarc_policy: { type: string, enum: [none, quarantine, reject] }
      responses:
        "200":
          description: The domain with its records
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Domain" }
        "422":
          $ref: "#/components/responses/Problem"
    delete:
      tags: [Domains]
      operationId: deleteDomain
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      responses:
        "204":
          description: Deleted. The sending identity goes with the last copy of the domain.
        "400":
          description: Hosted PineMail domain cannot be removed
        "409":
          description: The domain has mailboxes; remove them first
  /v1/domains/{id}/verify:
    post:
      tags: [Domains]
      operationId: verifyDomain
      summary: Check ownership, then SPF, DKIM and MAIL FROM
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      responses:
        "200":
          description: The domain as it stands after the check
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Domain" }
        "409":
          description: |
            Another account holds the domain and its record is still
            published, the provider could not be asked, or the domain is
            the hosted one
  /v1/domains/{id}/senders:
    get:
      tags: [Domains]
      operationId: listSenders
      summary: The addresses sent from on the domain, with what each has sent
      security: [{ bearerAuth: [domains:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Most recently used first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/Sender" } }
    post:
      tags: [Domains]
      operationId: createSender
      summary: Add a sender beforehand, with a display name and a mailbox for replies
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [local_part]
              properties:
                local_part: { type: string, example: hello }
                display_name: { type: string, nullable: true, example: Acme }
                reply_mailbox_id: { type: string, nullable: true }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Sender" }
        "409":
          description: Already a sender
        "422":
          $ref: "#/components/responses/Problem"
  /v1/senders/{id}:
    get:
      tags: [Domains]
      operationId: getSender
      security: [{ bearerAuth: [domains:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: The sender
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Sender" }
    patch:
      tags: [Domains]
      operationId: updateSender
      summary: Change the display name or the reply mailbox (null clears it)
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                display_name: { type: string, nullable: true }
                reply_mailbox_id: { type: string, nullable: true }
      responses:
        "200":
          description: The sender
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Sender" }
    delete:
      tags: [Domains]
      operationId: deleteSender
      summary: Forget the display name and reply mailbox; a later send lists the address again
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204":
          description: Removed
  /v1/domains/{id}/dns:
    get:
      tags: [Domains]
      operationId: checkDomainDns
      summary: Look the domain's records up live
      security: [{ bearerAuth: [domains:read] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Each record with its state, and a zone file
          content:
            application/json:
              schema:
                type: object
                properties:
                  domain: { type: string }
                  ownership: { type: string, enum: [verified, pending] }
                  status: { type: string, enum: [verified, pending, failed] }
                  records:
                    type: array
                    items:
                      allOf:
                        - $ref: "#/components/schemas/DnsRecord"
                        - type: object
                          properties:
                            state: { type: string, enum: [ok, missing, different, unknown], description: "unknown: the lookup failed." }
                            found: { type: array, items: { type: string } }
                  zone_file: { type: string }
  /v1/domains/{id}/dns/cloudflare:
    post:
      tags: [Domains]
      operationId: publishDomainDnsToCloudflare
      summary: Add the records to the domain's Cloudflare zone
      description: |
        Uses a Cloudflare API token (Zone:Read and DNS:Edit) for this
        request only; it is not stored. Nothing in the zone is
        overwritten: a record already there is `exists`, a name holding
        something else is `conflict`. The INBOUND MX is added only with
        `inbound: true`.
      security: [{ bearerAuth: [domains:write] }]
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [api_token]
              properties:
                api_token: { type: string }
                inbound: { type: boolean, default: false }
      responses:
        "200":
          description: What happened to each record
          content:
            application/json:
              schema:
                type: object
                properties:
                  domain: { type: string }
                  zone: { type: string }
                  records:
                    type: array
                    items:
                      allOf:
                        - $ref: "#/components/schemas/DnsRecord"
                        - type: object
                          properties:
                            state: { type: string, enum: [created, exists, conflict, skipped, failed] }
                            detail: { type: string }
        "400":
          description: Cloudflare refused the token
        "404":
          description: No such domain, or no zone the token can see
        "502":
          description: Cloudflare answered with an error
  /v1/mailboxes:
    get:
      tags: [Mailboxes]
      operationId: listMailboxes
      security: [{ bearerAuth: [mailboxes:read] }]
      responses:
        "200":
          description: Mailboxes
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Mailbox"
    post:
      tags: [Mailboxes]
      operationId: createMailbox
      security: [{ bearerAuth: [mailboxes:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateMailbox"
      responses:
        "201":
          description: Created. `password` is present only when PineMail generated one.
  /v1/mailboxes/{id}:
    get:
      tags: [Mailboxes]
      operationId: getMailbox
      security: [{ bearerAuth: [mailboxes:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Mailbox
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Mailbox"
    patch:
      tags: [Mailboxes]
      operationId: updateMailbox
      security: [{ bearerAuth: [mailboxes:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateMailbox"
      responses:
        "200":
          description: Updated mailbox
    delete:
      tags: [Mailboxes]
      operationId: deleteMailbox
      security: [{ bearerAuth: [mailboxes:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204":
          description: Deleted
  /v1/mailboxes/{id}/threads:
    get:
      tags: [Mailbox mail]
      operationId: listThreads
      summary: A page of a mailbox's threads, newest first
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - in: query
          name: folder
          schema: { type: string, enum: [inbox, starred, snoozed, sent, drafts, scheduled, important, archive, all, spam, trash], default: inbox }
        - in: query
          name: q
          schema: { type: string, maxLength: 200 }
          description: Search words, matched against subjects, addresses and message text.
        - in: query
          name: kind
          schema: { type: string, enum: [mail, bounce, complaint, auto_reply, challenge] }
          description: Only threads whose latest received message is of this kind.
        - in: query
          name: tag
          schema: { type: string, maxLength: 200 }
          description: Only threads with a message sent with this tag.
        - in: query
          name: limit
          schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
        - in: query
          name: cursor
          schema: { type: string }
          description: The next_cursor of the page before.
      responses:
        "200":
          description: Thread summaries
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/ThreadSummary"
                  next_cursor: { type: string, nullable: true }
        "400":
          description: Unknown folder, kind or cursor
        "403":
          description: The key lacks mail:read, or mailboxes are off for the account
        "404":
          description: No such mailbox in the project
    patch:
      tags: [Mailbox mail]
      operationId: updateThreads
      summary: The same change to many threads
      description: |
        As PATCH .../threads/{threadId}, on up to 100 threads. Threads the
        key does not reach are answered in not_found and left alone.
      security: [{ bearerAuth: [mail:organize] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/ThreadChanges"
                - type: object
                  required: [thread_ids]
                  properties:
                    thread_ids: { type: array, minItems: 1, maxItems: 100, items: { type: string } }
      responses:
        "200":
          description: What was changed
          content:
            application/json:
              schema:
                type: object
                properties:
                  updated: { type: array, items: { type: string } }
                  not_found: { type: array, items: { type: string } }
        "422":
          $ref: "#/components/responses/Problem"
  /v1/mailboxes/{id}/threads/{threadId}:
    get:
      tags: [Mailbox mail]
      operationId: getThread
      summary: One thread with its messages, oldest first
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - in: path
          name: threadId
          required: true
          schema: { type: string }
        - in: query
          name: html
          schema: { type: boolean, default: false }
          description: Include the HTML bodies.
      responses:
        "200":
          description: The thread
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Thread"
        "404":
          description: No such thread in the mailbox
    patch:
      tags: [Mailbox mail]
      operationId: updateThread
      summary: Archive, read, star, snooze, label or trash a thread
      description: |
        As a person would in the mail app. Give only what should change.
        read false marks the latest received message unread; a star marks
        the latest message; labels go on every message of the thread.
        Answers the thread as a summary, with its label_ids.
      security: [{ bearerAuth: [mail:organize] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - in: path
          name: threadId
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ThreadChanges"
      responses:
        "200":
          description: The thread after the change
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/ThreadSummary"
                  - type: object
                    properties:
                      label_ids: { type: array, items: { type: string } }
        "403":
          description: The key lacks mail:organize
        "404":
          description: No such thread in the mailbox
        "422":
          $ref: "#/components/responses/Problem"
  /v1/mailboxes/{id}/labels:
    get:
      tags: [Mailbox mail]
      operationId: listLabels
      summary: The mailbox's labels
      description: For add_label_ids and remove_label_ids. Labels are made in the mail app.
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: By name
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id: { type: string }
                        name: { type: string }
                        color: { type: string }
  /v1/mailboxes/{id}/drafts:
    post:
      tags: [Mailbox mail]
      operationId: createDraft
      summary: Write or update a draft in the mailbox
      description: Nothing is sent. With draft_id the draft is updated in place, in its own thread.
      security: [{ bearerAuth: [mail:draft] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Compose"
      responses:
        "201":
          description: The draft
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  thread_id: { type: string }
                  status: { type: string, enum: [draft] }
        "404":
          description: No such draft (draft_id) in the mailbox
        "422":
          $ref: "#/components/responses/Problem"
  /v1/mailboxes/{id}/messages:
    post:
      tags: [Mailbox mail]
      operationId: sendFromMailbox
      summary: Send from the mailbox
      description: |
        As a person would in the mail app: the message lands in Sent, counts
        against the account's monthly send limit and the mailbox's daily cap,
        waits out the mailbox's undo window, and is held until scheduled_at
        when given. With draft_id an existing draft is sent. Until undo_until
        the mail app, when open, shows the message with Undo, and
        .../messages/{messageId}/cancel takes it back.
      security: [{ bearerAuth: [mail:send] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/Compose"
                - type: object
                  required: [to, subject]
                  properties:
                    scheduled_at: { type: string, format: date-time, description: "Hold the message until then." }
      responses:
        "202":
          description: Queued or scheduled
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  thread_id: { type: string }
                  message_id: { type: string, description: "The Message-ID PineMail gives the message. Replies and bounces are linked to it by reply_to_message_id, also when they quote the id the sending service gave it." }
                  status: { type: string, enum: [queued, scheduled] }
                  undo_until: { type: string, format: date-time, nullable: true }
        "422":
          $ref: "#/components/responses/Problem"
        "429":
          description: >-
            A send limit is reached: the account's this month from mailboxes,
            the last 24 hours' or the last minute's, or the mailbox's own daily
            cap. Retry-After gives the seconds until a send may go. GET
            /v1/limits shows what is used of each.
  /v1/mailboxes/{id}/messages/batch:
    post:
      tags: [Mailbox mail]
      operationId: sendDrafts
      summary: Send or schedule many drafts
      description: |
        Up to 100 of the mailbox's drafts, each sent as it is written, as
        with POST .../messages and its draft_id. With start_at the first goes
        then and each next one spacing_minutes later; without it the first
        goes now, after the undo window. The last may go at most 30 days
        ahead. Each draft is sent or refused on its own; the answer lists
        them in order, with the status and words a single send would have
        had for a refused one.
      security: [{ bearerAuth: [mail:send] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [draft_ids]
              properties:
                draft_ids: { type: array, minItems: 1, maxItems: 100, items: { type: string } }
                start_at: { type: string, format: date-time, description: "In the future; left out, the first goes now." }
                spacing_minutes: { type: integer, minimum: 0, maximum: 1440, default: 0 }
      responses:
        "200":
          description: One entry per draft, in order
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        draft_id: { type: string }
                        id: { type: string }
                        thread_id: { type: string }
                        message_id: { type: string }
                        status: { type: string, enum: [queued, scheduled] }
                        scheduled_at: { type: string, format: date-time, nullable: true }
                        undo_until: { type: string, format: date-time, nullable: true }
                        error:
                          type: object
                          properties:
                            status: { type: integer }
                            detail: { type: string, nullable: true }
                            errors: { type: object, nullable: true, additionalProperties: { type: string } }
                  accepted: { type: integer }
                  refused: { type: integer }
        "422":
          $ref: "#/components/responses/Problem"
  /v1/mailboxes/{id}/messages/{messageId}:
    get:
      tags: [Mailbox mail]
      operationId: getMailboxMessage
      summary: One message, and for a sent one what became of it
      description: |
        A sent message comes with delivery: the status, the times SES
        reported delivery, a hard bounce or a complaint, and the bounces
        the mailbox received for it; and replies: the received messages
        that answer it. A received message has delivery null.
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: messageId, required: true, schema: { type: string } }
        - in: query
          name: html
          schema: { type: boolean, default: false }
          description: Include the HTML body; left out when masking is on.
      responses:
        "200":
          description: The message
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    allOf:
                      - $ref: "#/components/schemas/Message"
                      - type: object
                        properties:
                          thread_id: { type: string }
                  delivery:
                    type: object
                    nullable: true
                    properties:
                      status: { type: string, enum: [draft, queued, scheduled, sent, delivered, soft_bounced, bounced, complained, failed] }
                      scheduled_send_at: { type: string, format: date-time, nullable: true }
                      sent_at: { type: string, format: date-time, nullable: true }
                      delivered_at: { type: string, format: date-time, nullable: true }
                      bounced_at: { type: string, format: date-time, nullable: true }
                      complained_at: { type: string, format: date-time, nullable: true }
                      error: { type: string, nullable: true, description: "Why a failed send failed." }
                      bounces:
                        type: array
                        items:
                          allOf:
                            - $ref: "#/components/schemas/BounceReport"
                            - type: object
                              properties:
                                message_id: { type: string, description: "The bounce's own id in the mailbox." }
                                thread_id: { type: string }
                                received_at: { type: string, format: date-time, nullable: true }
                      complaints:
                        type: array
                        description: Spam reports (ARF) received in the mailbox about this message, such as an abuse desk sends.
                        items:
                          type: object
                          properties:
                            message_id: { type: string, description: "The report's own id in the mailbox." }
                            thread_id: { type: string }
                            from: { $ref: "#/components/schemas/Address" }
                            received_at: { type: string, format: date-time, nullable: true }
                  replies:
                    type: array
                    items:
                      type: object
                      properties:
                        message_id: { type: string }
                        thread_id: { type: string }
                        kind: { type: string, enum: [mail, auto_reply, challenge] }
                        from: { $ref: "#/components/schemas/Address" }
                        received_at: { type: string, format: date-time, nullable: true }
        "404":
          description: No such message in the mailbox, or a thread the owner keeps from assistants
  /v1/mailboxes/{id}/messages/{messageId}/cancel:
    post:
      tags: [Mailbox mail]
      operationId: cancelMailboxMessage
      summary: Take back a sent message
      description: |
        While the message waits out the mailbox's undo window (until
        undo_until) or its scheduled_at, it goes back to Drafts, as Undo
        does in the mail app. Once it has left, the answer is 404.
      security: [{ bearerAuth: [mail:send] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - in: path
          name: messageId
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Back in Drafts
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  status: { type: string, enum: [draft] }
        "404":
          description: No message waiting to be sent with that id in the mailbox
  /v1/mailboxes/{id}/calendar/events:
    get:
      tags: [Mailbox mail]
      operationId: listCalendarEvents
      summary: The mailbox's calendar between two times
      security: [{ bearerAuth: [calendar:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - in: query
          name: from
          schema: { type: string, format: date-time }
          description: Default now.
        - in: query
          name: to
          schema: { type: string, format: date-time }
          description: Default 14 days after from; at most 92 days after it.
      responses:
        "200":
          description: Events, recurring ones expanded into occurrences
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/CalendarEvent"
                  from: { type: string, format: date-time }
                  to: { type: string, format: date-time }
        "400":
          description: Bad or too long a range
  /v1/mailboxes/{id}/assistant-access:
    get:
      tags: [Mailbox mail]
      operationId: getAssistantAccess
      summary: What the account owner lets assistants reach in a mailbox
      description: Read-only. The owner changes it under Account → Assistants. A mailbox kept from assistants is 404.
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: What applies
          content:
            application/json:
              schema:
                type: object
                properties:
                  mailbox_id: { type: string }
                  address: { type: string }
                  correspondents: { type: string, enum: [all, internal, allowlist] }
                  allowed: { type: array, items: { type: string }, description: "Listed domains and addresses, with allowlist." }
                  masking: { type: string, enum: ["on", "off"] }
                  drive: { type: string, enum: ["reached", "kept from assistants"] }
                  placeholder_kinds: { type: array, items: { type: string } }
                  set_by: { type: string }
        "404":
          description: No such mailbox, or one the owner keeps from assistants
  /v1/mailboxes/{id}/messages/{messageId}/attachments/{attachmentId}/text:
    get:
      tags: [Mailbox mail]
      operationId: readAttachmentText
      summary: The text of a mail attachment, masked when the owner has masking on
      description: Plain text, PDF, Word, spreadsheets and a mail inside a mail (message/rfc822, such as the original a bounce returns, read as its headers and text); at most 10 MB read and 200,000 characters returned.
      security: [{ bearerAuth: [mail:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: messageId, required: true, schema: { type: string } }
        - { in: path, name: attachmentId, required: true, schema: { type: string } }
      responses:
        "200":
          description: The text
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DocumentText"
        "404":
          description: No such attachment, or a thread the owner keeps from assistants
        "422":
          description: A type that is not read as text
        "503":
          description: Masking is on and could not finish; no content
  /v1/webhooks:
    get:
      tags: [Webhooks]
      operationId: listWebhooks
      security: [{ bearerAuth: [webhooks:read] }]
      responses:
        "200":
          description: Webhooks
    post:
      tags: [Webhooks]
      operationId: createWebhook
      security: [{ bearerAuth: [webhooks:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url, events]
              properties:
                url: { type: string, format: uri }
                events:
                  type: array
                  items:
                    $ref: "#/components/schemas/WebhookEvent"
      responses:
        "201":
          description: Created. `secret` is shown once.
  /v1/webhooks/{id}:
    get:
      tags: [Webhooks]
      operationId: getWebhook
      security: [{ bearerAuth: [webhooks:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: "Webhook plus recent deliveries. disabled_reason is failing when PineMail turned it off after 5 days of failed deliveries; failing_since is the start of the current run of failures."
    patch:
      tags: [Webhooks]
      operationId: updateWebhook
      security: [{ bearerAuth: [webhooks:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                url: { type: string, format: uri }
                events:
                  type: array
                  items:
                    $ref: "#/components/schemas/WebhookEvent"
                enabled: { type: boolean, description: "true starts the 5-day clock over and clears disabled_reason." }
      responses:
        "200":
          description: Updated
    delete:
      tags: [Webhooks]
      operationId: deleteWebhook
      security: [{ bearerAuth: [webhooks:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204":
          description: Deleted
  /v1/webhooks/{id}/retry:
    post:
      tags: [Webhooks]
      operationId: retryFailedWebhookDeliveries
      summary: Send every failed delivery since a time again
      description: Default 7 days back, at most 30 days and 1,000 deliveries. Each gets a fresh set of attempts. Test events are not resent.
      security: [{ bearerAuth: [webhooks:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                since: { type: string, format: date-time }
      responses:
        "200":
          description: How many were queued again
          content:
            application/json:
              schema: { type: object, properties: { retried: { type: integer } } }
        "404": { description: No webhook with that id }
        "409": { description: The webhook is off }
        "422": { description: since is not a time }
  /v1/webhooks/{id}/deliveries/{delivery_id}/retry:
    post:
      tags: [Webhooks]
      operationId: retryWebhookDelivery
      summary: Send one failed delivery again
      security: [{ bearerAuth: [webhooks:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: delivery_id, required: true, schema: { type: string } }
      responses:
        "200":
          description: Queued again
          content:
            application/json:
              schema: { type: object, properties: { retried: { type: integer } } }
        "404": { description: No such delivery on this webhook, or a test event }
        "409": { description: The webhook is off, or the delivery did not fail }
  /v1/webhooks/{id}/test:
    post:
      tags: [Webhooks]
      operationId: testWebhook
      summary: Send a signed webhook.test event now
      security: [{ bearerAuth: [webhooks:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Immediate delivery result
          content:
            application/json:
              schema:
                type: object
                properties:
                  http_status: { type: integer, nullable: true }
                  success: { type: boolean }
                  delivery_id: { type: string }
  /v1/templates:
    post:
      tags: [Templates]
      operationId: createTemplate
      summary: Make a template
      description: The slug is unique in the project; variables are read from subject and bodies.
      security: [{ bearerAuth: [templates:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, slug, subject]
              properties:
                name: { type: string, maxLength: 120 }
                slug: { type: string, maxLength: 60, pattern: "^[a-z0-9-]+$" }
                subject: { type: string, maxLength: 998 }
                description: { type: string, maxLength: 500, nullable: true }
                html: { type: string, nullable: true }
                text: { type: string, nullable: true }
      responses:
        "201": { description: The template }
        "422": { description: A field that is not valid, or a slug already used }
    get:
      tags: [Templates]
      operationId: listTemplates
      security: [{ bearerAuth: [templates:read] }]
      responses:
        "200":
          description: Templates
  /v1/templates/{id}/versions:
    get:
      tags: [Templates]
      operationId: listTemplateVersions
      summary: The template's earlier versions, newest first (at most 50)
      security: [{ bearerAuth: [templates:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: The current version's number and the earlier versions without bodies
          content:
            application/json:
              schema:
                type: object
                properties:
                  current_version: { type: integer }
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        version: { type: integer }
                        name: { type: string }
                        subject: { type: string }
                        created_at: { type: string, format: date-time }
        "404": { description: No template with that id }
  /v1/templates/{id}/versions/{version}:
    get:
      tags: [Templates]
      operationId: getTemplateVersion
      summary: One earlier version with its bodies
      security: [{ bearerAuth: [templates:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: version, required: true, schema: { type: integer } }
      responses:
        "200":
          description: The version
          content:
            application/json:
              schema:
                type: object
                properties:
                  version: { type: integer }
                  name: { type: string }
                  subject: { type: string }
                  html: { type: string, nullable: true }
                  text: { type: string, nullable: true }
                  created_at: { type: string, format: date-time }
        "404": { description: No such template or version }
  /v1/templates/{id}/versions/{version}/restore:
    post:
      tags: [Templates]
      operationId: restoreTemplateVersion
      summary: Make an earlier version current again, saved as a new version
      security: [{ bearerAuth: [templates:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: version, required: true, schema: { type: integer } }
      responses:
        "200": { description: The template, with its new version number }
        "404": { description: No such template or version }
  /v1/templates/{id}:
    patch:
      tags: [Templates]
      operationId: updateTemplate
      summary: Change a template
      description: Fields left out stay; null clears description, html or text.
      security: [{ bearerAuth: [templates:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 120 }
                slug: { type: string, maxLength: 60, pattern: "^[a-z0-9-]+$" }
                subject: { type: string, maxLength: 998 }
                description: { type: string, maxLength: 500, nullable: true }
                html: { type: string, nullable: true }
                text: { type: string, nullable: true }
      responses:
        "200": { description: The template as it is now }
        "404": { description: No template with that id }
        "422": { description: A field that is not valid, or a slug already used }
    delete:
      tags: [Templates]
      operationId: deleteTemplate
      summary: Remove a template
      security: [{ bearerAuth: [templates:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204": { description: Removed }
        "404": { description: No template with that id }
    get:
      tags: [Templates]
      operationId: getTemplate
      security: [{ bearerAuth: [templates:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Template
  /v1/directory:
    get:
      tags: [Directory]
      operationId: listDirectory
      security: [{ bearerAuth: [directory:read] }]
      responses:
        "200":
          description: People plus inbound and outbound shares
    post:
      tags: [Directory]
      operationId: addDirectoryPerson
      security: [{ bearerAuth: [directory:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, email]
              properties:
                name: { type: string }
                email: { type: string, format: email }
                title: { type: string }
                organization: { type: string }
                notes: { type: string }
      responses:
        "201":
          description: Created
  /v1/directory/{id}:
    patch:
      tags: [Directory]
      operationId: updateDirectoryPerson
      summary: Edit a person added by hand
      description: Fields left out stay; null clears title, organization or notes. Members follow their mailbox and are refused.
      security: [{ bearerAuth: [directory:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 120 }
                email: { type: string, format: email }
                title: { type: string, maxLength: 120, nullable: true }
                organization: { type: string, maxLength: 120, nullable: true }
                notes: { type: string, maxLength: 500, nullable: true }
      responses:
        "200": { description: The person as they are now }
        "400": { description: A member, who follows the mailbox }
        "404": { description: No directory person with that id }
        "422": { description: A field that is not valid, or an address already listed }
    delete:
      tags: [Directory]
      operationId: deleteDirectoryPerson
      security: [{ bearerAuth: [directory:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204":
          description: Deleted
        "400":
          description: The project's own mailboxes are listed automatically and cannot be deleted
  /v1/files:
    get:
      tags: [Files]
      operationId: listFiles
      summary: List a Drive folder, or the trash
      description: |
        Drive's own files and folders (the account's, from any of its
        projects). Without `parent_id`, Drive's top. `trashed=true` lists
        the top item of each trashed tree and cannot be combined with
        `parent_id`. Folders come first, then by name.
      security: [{ accountKey: [files:read] }, { bearerAuth: [files:read] }]
      parameters:
        - { in: query, name: parent_id, schema: { type: string } }
        - { in: query, name: trashed, schema: { type: boolean } }
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 1000, default: 100 } }
        - { in: query, name: cursor, schema: { type: string } }
      responses:
        "200":
          description: Items
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/DriveItem" }
                  next_cursor: { type: string, nullable: true }
        "404": { $ref: "#/components/responses/Problem" }
    post:
      tags: [Files]
      operationId: createFile
      summary: Make a folder, or upload a file of up to 25 MB
      description: |
        A JSON body `{"type":"folder","name","parent_id"}` makes a folder.
        Any other body is a file's content: pass `name` (and optionally
        `parent_id`) in the query and the file's type as Content-Type.
        A file of the same name in the folder gets the upload as its new
        version (200, `new_version: true`); otherwise 201. Larger files
        go through `/v1/uploads`.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - { in: query, name: name, schema: { type: string } }
        - { in: query, name: parent_id, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CreateFolder" }
          application/octet-stream:
            schema: { type: string, format: binary, maxLength: 26214400 }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
        "200": { description: New version of an existing file }
        "409": { $ref: "#/components/responses/Problem" }
        "413":
          description: Body over 25 MB, or the account's storage quota is full
          content:
            application/problem+json:
              schema: { $ref: "#/components/schemas/Problem" }
  /v1/files/{id}:
    get:
      tags: [Files]
      operationId: getFile
      security: [{ accountKey: [files:read] }, { bearerAuth: [files:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: File or folder
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
        "404": { $ref: "#/components/responses/Problem" }
    patch:
      tags: [Files]
      operationId: updateFile
      summary: Rename and/or move
      description: "`parent_id: null` moves to Drive's top. 409 while the item is in the trash."
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                parent_id: { type: string, nullable: true }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
        "409": { $ref: "#/components/responses/Problem" }
        "422": { $ref: "#/components/responses/Problem" }
    delete:
      tags: [Files]
      operationId: deleteFile
      summary: Move to the trash, or delete for good
      description: Everything under a folder goes with it. Trashed items are deleted for good after 30 days.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: query, name: permanent, schema: { type: boolean } }
      responses:
        "204": { description: Done }
  /v1/files/{id}/content:
    get:
      tags: [Files]
      operationId: downloadFile
      description: Always an attachment. Range requests get 206.
      security: [{ accountKey: [files:read] }, { bearerAuth: [files:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: query, name: version, description: A version id from /versions, schema: { type: string } }
      responses:
        "200":
          description: The file's bytes
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        "206": { description: Part of the file }
    put:
      tags: [Files]
      operationId: replaceFileContent
      summary: Store a new version (up to 25 MB)
      description: |
        The earlier version stays in the history. With
        `expected_version_id`, only replaces that version and answers 409
        when the file has moved on.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: query, name: expected_version_id, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema: { type: string, format: binary }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
        "409": { $ref: "#/components/responses/Problem" }
        "413": { $ref: "#/components/responses/Problem" }
  /v1/files/{id}/restore:
    post:
      tags: [Files]
      operationId: restoreFile
      description: Brings an item back from the trash with what was trashed with it.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Restored
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
  /v1/files/{id}/text:
    get:
      tags: [Files]
      operationId: readFileText
      summary: The text of a Drive file's current version, masked when masking is on
      description: Plain text, PDF, Word and spreadsheets; at most 10 MB read and 200,000 characters returned. Also takes a person's sign-in with files:read.
      security: [{ accountKey: [files:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: The text
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DocumentText"
        "422":
          description: A folder, or a type that is not read as text
        "503":
          description: Masking is on and could not finish; no content
  /v1/files/{id}/versions:
    get:
      tags: [Files]
      operationId: listFileVersions
      security: [{ accountKey: [files:read] }, { bearerAuth: [files:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Versions, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id: { type: string }
                        size_bytes: { type: integer }
                        content_type: { type: string }
                        current: { type: boolean }
                        created_at: { type: string, format: date-time }
  /v1/files/{id}/shares:
    get:
      tags: [Files]
      operationId: listFileShares
      security: [{ accountKey: [files:read] }, { bearerAuth: [files:read] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Live shares
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/Share" }
    post:
      tags: [Files]
      operationId: createFileShare
      summary: Share a file or folder by link
      description: Needs the sharing service on as well as storage.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CreateShare" }
      responses:
        "201":
          description: The share, with its URL
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Share"
                  - type: object
                    properties:
                      invited: { type: integer }
                      not_sent:
                        type: array
                        items: { type: string }
  /v1/shares/{id}:
    patch:
      tags: [Files]
      operationId: updateShare
      summary: Move when a Drive share link ends
      description: Counted from now; the link stays the same, and an expired link opens again. A closed link stays closed.
      security: [{ accountKey: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [expires_in_days]
              properties:
                expires_in_days: { type: integer, enum: [1, 7, 30], nullable: true, description: "null: until the link is closed." }
      responses:
        "200": { description: "{id, expires_at}" }
        "404": { description: No open share with that id }
        "422": { description: Not one of the choices }
    delete:
      tags: [Files]
      operationId: revokeShare
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204": { description: Revoked }
        "404": { $ref: "#/components/responses/Problem" }
  /v1/uploads:
    post:
      tags: [Uploads]
      operationId: startUpload
      summary: Start an upload in parts
      description: |
        For files of any size. Send each part with PUT
        `/v1/uploads/{id}/parts/{n}` for n = 0 … part_count-1 (every part
        exactly `part_size` bytes but the last), then POST
        `/v1/uploads/{id}/complete`. The quota is checked here for the
        whole file. Unfinished uploads are dropped after 24 hours.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, size]
              properties:
                name: { type: string }
                size: { type: integer, description: Bytes }
                parent_id: { type: string, nullable: true }
                content_type: { type: string }
      responses:
        "201":
          description: Started
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Upload" }
        "413": { $ref: "#/components/responses/Problem" }
  /v1/uploads/{id}:
    get:
      tags: [Uploads]
      operationId: getUpload
      description: The parts received so far, to resume.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "200":
          description: Upload
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Upload" }
    delete:
      tags: [Uploads]
      operationId: abortUpload
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204": { description: Cancelled }
  /v1/uploads/{id}/parts/{n}:
    put:
      tags: [Uploads]
      operationId: putUploadPart
      description: Sending a part again replaces it.
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
        - { in: path, name: n, required: true, schema: { type: integer, minimum: 0 } }
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema: { type: string, format: binary }
      responses:
        "204": { description: Stored }
        "400": { $ref: "#/components/responses/Problem" }
  /v1/uploads/{id}/complete:
    post:
      tags: [Uploads]
      operationId: completeUpload
      security: [{ accountKey: [files:write] }, { bearerAuth: [files:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "201":
          description: The file
          content:
            application/json:
              schema: { $ref: "#/components/schemas/DriveItem" }
        "400": { description: Parts are missing }
  /v1/keep/join:
    post:
      tags: [Buckets]
      operationId: joinKeep
      description: >-
        Joins the PineKeep beta, which buckets and S3 keys need. Until then
        /v1/buckets and /v1/bucket-keys answer 403. Joining again answers
        the same. Places are approved one by one: an account that is not
        approved gets 202 with status "pending" and a place when an operator
        gives one. While the beta takes no new requests the answer is 409.
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      responses:
        "200":
          description: Joined
          content:
            application/json:
              schema:
                type: object
                properties:
                  joined: { type: boolean }
                  quota_bytes: { type: integer }
                  used_bytes: { type: integer }
        "202": { description: The request is in and waits for approval }
        "403": { description: The request was not approved }
        "409": { description: The beta is closed, full or out of space for now }
  /v1/buckets:
    get:
      tags: [Buckets]
      operationId: listBuckets
      security: [{ accountKey: [buckets:read] }, { bearerAuth: [buckets:read] }]
      responses:
        "200":
          description: Buckets
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/Bucket" }
    post:
      tags: [Buckets]
      operationId: createBucket
      description: Bucket names are one namespace across PineMail, like S3's.
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, pattern: "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$" }
                public_read: { type: boolean }
                protect_days: { $ref: "#/components/schemas/BucketProtection" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Bucket" }
        "409": { description: Name taken, or the account has its 10 buckets }
  /v1/buckets/{name}:
    get:
      tags: [Buckets]
      operationId: getBucket
      security: [{ accountKey: [buckets:read] }, { bearerAuth: [buckets:read] }]
      parameters:
        - $ref: "#/components/parameters/BucketName"
      responses:
        "200":
          description: Bucket, with the S3 endpoint and the account's storage
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Bucket"
                  - type: object
                    properties:
                      s3_endpoint: { type: string }
                      region: { type: string }
                      account:
                        type: object
                        properties:
                          quota_bytes: { type: integer }
                          used_bytes: { type: integer }
                          bucket_bytes: { type: integer }
                          bucket_cap_bytes: { type: integer, nullable: true }
    patch:
      tags: [Buckets]
      operationId: updateBucket
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      parameters:
        - $ref: "#/components/parameters/BucketName"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                public_read: { type: boolean }
                cors_origins:
                  type: array
                  maxItems: 20
                  items: { type: string, examples: ["https://example.com"] }
                protect_days: { $ref: "#/components/schemas/BucketProtection" }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Bucket" }
    delete:
      tags: [Buckets]
      operationId: deleteBucket
      description: 409 while the bucket holds objects, unless `force=true`.
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      parameters:
        - $ref: "#/components/parameters/BucketName"
        - { in: query, name: force, schema: { type: boolean } }
      responses:
        "204": { description: Deleted }
        "409": { $ref: "#/components/responses/Problem" }
  /v1/buckets/{name}/objects:
    get:
      tags: [Buckets]
      operationId: listObjects
      description: |
        In key order. With the default delimiter "/", keys below the
        prefix's next "/" come back once in `common_prefixes`; pass an
        empty `delimiter` for a flat listing.
      security: [{ accountKey: [buckets:read] }, { bearerAuth: [buckets:read] }]
      parameters:
        - $ref: "#/components/parameters/BucketName"
        - { in: query, name: prefix, schema: { type: string } }
        - { in: query, name: delimiter, schema: { type: string, default: "/" } }
        - { in: query, name: cursor, schema: { type: string } }
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 1000, default: 500 } }
      responses:
        "200":
          description: Objects
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        key: { type: string }
                        size_bytes: { type: integer }
                        etag: { type: string, nullable: true }
                        last_modified: { type: string, format: date-time, nullable: true }
                  common_prefixes:
                    type: array
                    items: { type: string }
                  next_cursor: { type: string, nullable: true }
  /v1/buckets/{name}/objects/{key}:
    parameters:
      - $ref: "#/components/parameters/BucketName"
      - in: path
        name: key
        required: true
        description: The object key; "/" in it may be sent as is or encoded. No empty, "." or ".." segments.
        schema: { type: string }
    get:
      tags: [Buckets]
      operationId: getObject
      description: Always an attachment. Range requests get 206.
      security: [{ accountKey: [buckets:read] }, { bearerAuth: [buckets:read] }]
      responses:
        "200":
          description: The object's bytes
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        "404": { $ref: "#/components/responses/Problem" }
    put:
      tags: [Buckets]
      operationId: putObject
      description: Up to 25 MB; larger objects go to the S3 endpoint with an S3 key.
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema: { type: string, format: binary }
      responses:
        "201":
          description: Stored
          content:
            application/json:
              schema:
                type: object
                properties:
                  bucket: { type: string }
                  key: { type: string }
                  size_bytes: { type: integer }
                  content_type: { type: string }
        "413": { $ref: "#/components/responses/Problem" }
    delete:
      tags: [Buckets]
      operationId: deleteObject
      security: [{ accountKey: [buckets:write] }, { bearerAuth: [buckets:write] }]
      responses:
        "204": { description: Deleted }
  /v1/bucket-keys:
    get:
      tags: [S3 keys]
      operationId: listBucketKeys
      description: Live keys. Secrets are never listed.
      security: [{ accountKey: [buckets:read] }, { bearerAuth: [buckets:read] }]
      responses:
        "200":
          description: Keys
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/BucketKey" }
    post:
      tags: [S3 keys]
      operationId: createBucketKey
      description: |
        `buckets: "all"` reaches every bucket the account has, now and
        later; a list reaches only those (the account's own). The secret
        is in this response only.
      security: [{ accountKey: [bucket_keys:write] }, { bearerAuth: [bucket_keys:write] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, permission, buckets]
              properties:
                name: { type: string, maxLength: 80 }
                permission: { type: string, enum: [read, readwrite] }
                buckets:
                  oneOf:
                    - { type: string, const: all }
                    - { type: array, items: { type: string }, minItems: 1, maxItems: 50 }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/BucketKey"
                  - type: object
                    properties:
                      secret_access_key: { type: string }
                      s3_endpoint: { type: string }
                      region: { type: string }
  /v1/bucket-keys/{id}:
    patch:
      tags: [S3 keys]
      operationId: updateBucketKey
      summary: Change an S3 key's name, permission and buckets
      description: The key id and secret stay; the store applies the change within seconds. Fields left out stay as they are.
      security: [{ accountKey: [bucket_keys:write] }, { bearerAuth: [bucket_keys:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 80 }
                permission: { type: string, enum: [read, readwrite] }
                buckets:
                  oneOf:
                    - { type: string, enum: [all] }
                    - { type: array, items: { type: string }, minItems: 1, maxItems: 50 }
      responses:
        "200": { description: The key as it is now, without its secret }
        "404": { description: No S3 key with that id }
        "422": { description: A field that is not valid, or a bucket the account does not have }
    delete:
      tags: [S3 keys]
      operationId: revokeBucketKey
      security: [{ accountKey: [bucket_keys:write] }, { bearerAuth: [bucket_keys:write] }]
      parameters:
        - $ref: "#/components/parameters/Id"
      responses:
        "204": { description: Revoked }
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: pm_live
      description: |
        Project API key. A key must hold the scope named on the operation.
        Full access holds every scope that existed when the key was made.
    accountKey:
      type: http
      scheme: bearer
      bearerFormat: pm_acct
      description: |
        Account key, made under Buckets → Access keys. Reaches the account's
        files, buckets and S3 keys, every bucket or only those chosen; a key
        limited to some buckets cannot create or delete buckets or manage S3
        keys. Project routes answer 403 to it. Project keys made before
        account keys keep the storage scopes they were given.
  parameters:
    Id:
      in: path
      name: id
      required: true
      schema: { type: string }
    BucketName:
      in: path
      name: name
      required: true
      schema: { type: string }
  schemas:
    Project:
      type: object
      properties:
        id: { type: string, example: prj_01JXYZ }
        name: { type: string }
        slug: { type: string }
        created_at: { type: string, format: date-time }
    ProjectKey:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        prefix: { type: string, example: pm_live_AbCd1234 }
        kind: { type: string, enum: [full, send] }
        scopes: { type: array, items: { type: string } }
        last_used_at: { type: [string, "null"], format: date-time }
        created_at: { type: string, format: date-time }
    Counted:
      type: object
      description: A limit with what is used of it. limit and remaining are null when there is no limit.
      properties:
        used: { type: integer }
        limit: { type: integer, nullable: true }
        remaining: { type: integer, nullable: true }
    SendingLimits:
      type: object
      properties:
        month:
          type: object
          properties:
            period_start: { type: string, format: date-time }
            resets_at: { type: string, format: date-time }
            mailboxes: { $ref: "#/components/schemas/Counted" }
            api: { $ref: "#/components/schemas/Counted" }
        last_24_hours: { $ref: "#/components/schemas/Counted" }
        last_minute: { $ref: "#/components/schemas/Counted" }
        paused:
          type: object
          description: Sending paused because too much bounced or was reported as spam, or turned off by an operator.
          properties:
            mailboxes: { type: boolean }
            api: { type: boolean }
        paused_projects:
          type: array
          description: >-
            Projects whose sending is paused on their own bounce and complaint
            figures. The account's other projects send as usual.
          items:
            type: object
            properties:
              id: { type: string }
              name: { type: string }
              slug: { type: string }
              mailboxes: { $ref: "#/components/schemas/PauseInfo" }
              api: { $ref: "#/components/schemas/PauseInfo" }
        pause:
          type: object
          description: Why sending is off for the whole account (paused above), or null when it is not.
          properties:
            mailboxes: { $ref: "#/components/schemas/PauseInfo" }
            api: { $ref: "#/components/schemas/PauseInfo" }
    PauseInfo:
      type: object
      nullable: true
      description: >-
        automatic: paused on the bounce and complaint figures over the last 30
        days (at 10% hard bounces of at least 100 sends, 0.5% complaints of
        at least 1,000 sends, or 5 complaints), with the figures. operator:
        turned off by PineMail. Since 0.18.0 the automatic pause is per
        project (paused_projects).
      properties:
        by: { type: string, enum: [automatic, operator] }
        at: { type: string, format: date-time, nullable: true }
        since: { type: string, format: date-time, description: "automatic only: where the count began." }
        sends: { type: integer, description: "automatic only." }
        hard_bounces: { type: integer, description: "automatic only." }
        complaints: { type: integer, description: "automatic only." }
    MailboxLimit:
      type: object
      properties:
        id: { type: string }
        address: { type: string }
        daily_send_limit: { type: integer, nullable: true, description: "The mailbox's own cap on messages a day; null: none." }
        sent_last_24_hours: { type: integer }
        remaining_today: { type: integer, nullable: true }
    AccountLimits:
      type: object
      required: [access, sending, mailbox_limits]
      properties:
        access: { type: string, enum: [owner, mailbox] }
        plan: { type: string, enum: [free, paid, enterprise], description: Only with access owner. }
        sending: { $ref: "#/components/schemas/SendingLimits" }
        storage:
          type: object
          description: Only with access owner. Everything the account stores counts against one quota.
          properties:
            used_bytes: { type: integer }
            quota_bytes: { type: integer }
            remaining_bytes: { type: integer }
            mail_bytes: { type: integer }
            drive_bytes: { type: integer }
            bucket_bytes: { type: integer }
            bucket_cap_bytes: { type: integer, nullable: true }
            largest_file_bytes: { type: integer }
            large_file_sends_bytes: { type: integer }
        projects: { $ref: "#/components/schemas/Counted" }
        mailboxes: { $ref: "#/components/schemas/Counted" }
        domains: { $ref: "#/components/schemas/Counted" }
        mailbox_limits:
          type: array
          items: { $ref: "#/components/schemas/MailboxLimit" }
    SendEmail:
      type: object
      required: [from, to]
      description: |
        Queue one transactional email. Provide `html` or `text` (or both).
        `from` must be on a verified project domain. Display names are kept
        (`Acme <hello@pinemail.app>`).
      properties:
        from:
          type: string
          examples: ["hello@pinemail.app", "Acme <hello@pinemail.app>"]
        to:
          type: array
          items: { type: string }
        cc:
          type: array
          items: { type: string }
        bcc:
          type: array
          items: { type: string }
        reply_to: { type: string }
        subject: { type: string }
        html: { type: string }
        text: { type: string }
        headers:
          type: object
          additionalProperties: { type: string }
        tags:
          type: array
          items: { type: string }
        template:
          type: object
          description: A saved template instead of subject/html/text. Values in HTML are escaped; a missing variable is 422.
          properties:
            id: { type: string }
            slug: { type: string }
            variables: { type: object, additionalProperties: true }
        scheduled_at:
          type: string
          format: date-time
          description: Send later, up to 30 days ahead. Move with PATCH /v1/emails/{id}, cancel with POST /v1/emails/{id}/cancel.
        undo_seconds:
          type: integer
          minimum: 1
          maximum: 300
          description: |
            Hold the email that many seconds so it can be taken back with
            POST /v1/emails/{id}/cancel until undo_until. It is scheduled
            meanwhile, and the open Emails pages show it with Undo. Not
            together with scheduled_at.
        attachments:
          type: array
          maxItems: 20
          description: At most 30 MB together. The files are deleted once the email has gone.
          items:
            type: object
            required: [filename, content]
            properties:
              filename: { type: string }
              content: { type: string, description: Base64. }
              content_type: { type: string, description: "Guessed from the file name when left out." }
    QueuedEmail:
      type: object
      required: [id, status, created_at]
      properties:
        id: { type: string }
        status: { type: string, enum: [queued, scheduled] }
        created_at: { type: string, format: date-time }
        scheduled_at: { type: string, format: date-time, nullable: true }
        undo_until: { type: string, format: date-time, nullable: true, description: "With undo_seconds: until when cancel takes it back." }
    EmailSummary:
      type: object
      properties:
        id: { type: string }
        status: { type: string }
        subject: { type: string }
        from: { type: string }
        to:
          type: array
          items: { type: string }
        created_at: { type: string, format: date-time }
    EmailDetail:
      allOf:
        - $ref: "#/components/schemas/EmailSummary"
        - type: object
          properties:
            html: { type: string }
            text: { type: string }
            events:
              type: array
              items:
                type: object
    Mailbox:
      type: object
      properties:
        id: { type: string }
        domain_id: { type: string }
        address: { type: string }
        local_part: { type: string }
        domain: { type: string }
        display_name: { type: string, nullable: true }
        is_catch_all: { type: boolean }
        daily_send_limit: { type: integer, nullable: true }
        spam_level: { type: string, nullable: true }
        has_password: { type: boolean }
        unread: { type: integer }
        created_at: { type: string, format: date-time }
    CreateMailbox:
      type: object
      required: [domain_id, local_part]
      properties:
        domain_id: { type: string }
        local_part: { type: string }
        display_name: { type: string }
        password: { type: string, minLength: 12 }
        login: { type: boolean, default: true, description: "Make a login of its own for the mailbox." }
        daily_send_limit: { type: integer, nullable: true, description: "The mailbox's own cap on recipients a day, on top of the account's. Omitted or null: none." }
        is_catch_all: { type: boolean }
        spam_level:
          type: string
          enum: [off, low, medium, high]
        reply_to: { type: string }
        signature_html: { type: string }
    UpdateMailbox:
      type: object
      properties:
        display_name: { type: string }
        is_catch_all: { type: boolean }
        signature_html: { type: string }
        reply_to: { type: string }
        spam_level:
          type: string
          nullable: true
          enum: [off, low, medium, high]
        password: { type: string, minLength: 12, description: "A new password for the mailbox's own login." }
        daily_send_limit: { type: integer, nullable: true, description: "The mailbox's own cap on recipients a day; null removes it." }
    WebhookEvent:
      type: string
      enum:
        - email.queued
        - email.sending
        - email.sent
        - email.delivered
        - email.bounced
        - email.complained
        - email.failed
        - email.opened
        - email.clicked
    DriveItem:
      type: object
      properties:
        id: { type: string }
        type: { type: string, enum: [file, folder] }
        name: { type: string }
        parent_id: { type: string, nullable: true }
        size_bytes: { type: integer }
        content_type: { type: string, nullable: true }
        current_version_id: { type: string, nullable: true }
        starred: { type: boolean }
        trashed_at: { type: string, format: date-time, nullable: true }
        archived_at: { type: string, format: date-time, nullable: true }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
        new_version:
          type: boolean
          description: On uploads only. True when the upload became a new version of a file of the same name.
    CreateFolder:
      type: object
      required: [type, name]
      properties:
        type: { type: string, const: folder }
        name: { type: string, maxLength: 255 }
        parent_id: { type: string, nullable: true }
    Upload:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        size_bytes: { type: integer }
        part_size: { type: integer }
        part_count: { type: integer }
        new_version: { type: boolean }
        received_parts:
          type: array
          items: { type: integer }
        expires_at: { type: string, format: date-time }
    Share:
      type: object
      properties:
        id: { type: string }
        file_id: { type: string }
        audience: { type: string, enum: [link, people] }
        role: { type: string, enum: [view, edit] }
        url: { type: string }
        expires_at: { type: string, format: date-time, nullable: true }
        expired: { type: boolean }
        download_count: { type: integer }
        last_accessed_at: { type: string, format: date-time, nullable: true }
        recipients:
          type: array
          items:
            type: object
            properties:
              email: { type: string }
              verified: { type: boolean }
        created_at: { type: string, format: date-time }
    CreateShare:
      type: object
      properties:
        audience:
          type: string
          enum: [link, people]
          default: link
          description: "link: anyone with the URL. people: only the addresses in emails, who get an invitation."
        role:
          type: string
          enum: [view, edit]
          default: view
          description: edit is for documents and spreadsheets only.
        emails:
          type: array
          maxItems: 20
          items: { type: string }
        expires_in_days:
          type: integer
          nullable: true
          enum: [1, 7, 30, null]
          description: null (the default) lasts until revoked.
    Bucket:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        public_read: { type: boolean }
        cors_origins:
          type: array
          items: { type: string }
        protect_days: { $ref: "#/components/schemas/BucketProtection" }
        protect_unlocked:
          type: integer
          description: Current versions the last daily pass could not lock; 0 when everything is protected.
        used_bytes: { type: integer, description: Measured every minute }
        measured_at: { type: string, format: date-time, nullable: true }
        created_at: { type: string, format: date-time }
    BucketProtection:
      type: integer
      nullable: true
      minimum: 7
      maximum: 365
      description: >-
        Protection against deletion, in days; null is off. While on, the
        bucket keeps versions, and for at least this many days (at most
        2N + 1) after a version is deleted or replaced no S3 key of the
        account can remove it (S3 object lock in GOVERNANCE mode for
        2N + 1 days, moved forward for current versions). Deleting an object hides it behind a delete
        marker; earlier versions can be listed and read over S3
        (ListObjectVersions, GetObject with versionId). Old versions
        count toward the account's storage and are removed when their
        protection has run out, so the storage should hold up to 2N + 1
        days of what the bucket changes. A file with a content type other
        than application/octet-stream is copied each time its lock is
        renewed (about every N days) and can count twice meanwhile. Lifecycle rules are removed from a
        protected bucket. To delete a protected bucket, turn protection
        off (protect_days: null) and delete it once the protection of
        its versions has run out; until then DELETE answers 409. Turning
        it off stops locking new versions; existing locks run their
        course.
    BucketKey:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        access_key_id: { type: string }
        permission: { type: string, enum: [read, readwrite] }
        buckets:
          oneOf:
            - { type: string, const: all }
            - { type: array, items: { type: string } }
        created_at: { type: string, format: date-time }
    DnsRecord:
      type: object
      properties:
        type: { type: string, enum: [TXT, CNAME, MX] }
        host: { type: string }
        value: { type: string, description: "For MX: `<priority> <host>`." }
        purpose: { type: string, enum: [OWNERSHIP, SPF, DKIM, MAIL FROM, DMARC, INBOUND] }
    Sender:
      type: object
      properties:
        id: { type: string }
        domain_id: { type: string }
        address: { type: string, example: hello@example.com }
        display_name: { type: string, nullable: true }
        reply_mailbox_id: { type: string, nullable: true }
        replies_go_to:
          type: string
          nullable: true
          description: The address replies land in; null when they are refused.
        is_mailbox: { type: boolean, description: The address is a mailbox itself. }
        sent_30d: { type: integer }
        sent_total: { type: integer }
        last_sent_at: { type: string, format: date-time, nullable: true }
        created_at: { type: string, format: date-time }
        emails: { type: string, description: The path that lists its emails. }
    Domain:
      type: object
      properties:
        id: { type: string }
        domain: { type: string }
        region: { type: string, nullable: true }
        status:
          type: string
          enum: [verified, pending, failed]
          description: Verified when ownership, DKIM, SPF and MAIL FROM all are.
        ownership: { type: string, enum: [verified, pending] }
        receive_mail: { type: boolean, description: Mail for the domain is received here. }
        dmarc_policy: { type: string, enum: [none, quarantine, reject] }
        dkim_status: { type: string, enum: [verified, pending, failed] }
        spf_status: { type: string, enum: [verified, pending, failed] }
        mail_from_status: { type: string, enum: [verified, pending, failed] }
        last_checked_at: { type: string, format: date-time, nullable: true }
        created_at: { type: string, format: date-time }
        records:
          type: array
          items:
            allOf:
              - $ref: "#/components/schemas/DnsRecord"
              - type: object
                properties:
                  id: { type: string }
                  verified: { type: boolean }
    Address:
      type: object
      properties:
        address: { type: string }
        name: { type: string, nullable: true }
    ThreadSummary:
      type: object
      properties:
        id: { type: string }
        mailbox_id: { type: string }
        kind:
          type: string
          nullable: true
          enum: [mail, bounce, complaint, auto_reply, challenge]
          description: The kind of the latest received message; null before one arrives.
        tags: { type: array, items: { type: string }, description: "Tags of the thread's sent messages." }
        subject: { type: string }
        snippet: { type: string }
        last_message_at: { type: string, format: date-time }
        message_count: { type: integer }
        unread_count: { type: integer }
        has_attachments: { type: boolean }
        is_starred: { type: boolean }
        is_spam: { type: boolean }
        archived_at: { type: string, format: date-time, nullable: true }
        snoozed_until: { type: string, format: date-time, nullable: true }
        deleted_at: { type: string, format: date-time, nullable: true }
        latest_message:
          type: object
          nullable: true
          properties:
            id: { type: string }
            direction: { type: string, enum: [in, out] }
            status: { type: string, enum: [received, draft, queued, scheduled, sent, failed] }
            from: { $ref: "#/components/schemas/Address" }
            to: { type: array, items: { type: string } }
            sent_at: { type: string, format: date-time, nullable: true }
            received_at: { type: string, format: date-time, nullable: true }
    Message:
      type: object
      properties:
        id: { type: string }
        direction: { type: string, enum: [in, out] }
        status: { type: string, enum: [received, draft, queued, scheduled, sent, failed] }
        message_id: { type: string, nullable: true, description: "The Message-ID header, quoted as in_reply_to in a reply." }
        in_reply_to: { type: string, nullable: true }
        kind:
          type: string
          nullable: true
          enum: [mail, bounce, complaint, auto_reply, challenge]
          description: |
            Received mail: bounce (a delivery report), complaint (an abuse
            report, ARF: a recipient marked the mail as spam), auto_reply
            (written by a machine: out of office, a receipt), challenge (a
            sender check that asks to confirm) or mail. Null on sent mail.
        bounce:
          nullable: true
          allOf: [{ $ref: "#/components/schemas/BounceReport" }]
        reply_to_message_id: { type: string, nullable: true, description: "Received mail: the mailbox's own sent message it answers or reports on." }
        tags: { type: array, items: { type: string }, description: "Sent mail: the tags given at send." }
        from: { $ref: "#/components/schemas/Address" }
        to: { type: array, items: { type: string } }
        cc: { type: array, items: { type: string } }
        subject: { type: string }
        text: { type: string }
        html: { type: string, nullable: true, description: "Only with ?html=true." }
        snippet: { type: string }
        is_starred: { type: boolean }
        seen_at: { type: string, format: date-time, nullable: true }
        received_at: { type: string, format: date-time, nullable: true }
        sent_at: { type: string, format: date-time, nullable: true }
        scheduled_send_at: { type: string, format: date-time, nullable: true }
        delivered_at: { type: string, format: date-time, nullable: true, description: "Sent mail: when SES reported delivery." }
        attachments:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              filename: { type: string }
              content_type: { type: string }
              size_bytes: { type: integer }
              is_inline: { type: boolean }
        calendar_invite:
          nullable: true
          allOf: [{ $ref: "#/components/schemas/CalendarEvent" }]
    Thread:
      type: object
      properties:
        id: { type: string }
        mailbox_id: { type: string }
        subject: { type: string }
        kind: { type: string, nullable: true, enum: [mail, bounce, complaint, auto_reply, challenge] }
        tags: { type: array, items: { type: string } }
        last_message_at: { type: string, format: date-time }
        message_count: { type: integer }
        unread_count: { type: integer }
        has_attachments: { type: boolean }
        is_starred: { type: boolean }
        is_spam: { type: boolean }
        archived_at: { type: string, format: date-time, nullable: true }
        snoozed_until: { type: string, format: date-time, nullable: true }
        deleted_at: { type: string, format: date-time, nullable: true }
        label_ids: { type: array, items: { type: string } }
        messages:
          type: array
          items:
            $ref: "#/components/schemas/Message"
    Compose:
      type: object
      properties:
        draft_id: { type: string, description: "An existing draft to update or send." }
        to: { type: array, items: { type: string, format: email }, maxItems: 50 }
        cc: { type: array, items: { type: string, format: email }, maxItems: 50 }
        bcc: { type: array, items: { type: string, format: email }, maxItems: 50 }
        subject: { type: string, maxLength: 998 }
        text: { type: string }
        html: { type: string }
        thread_id: { type: string, description: "The thread a reply belongs to." }
        in_reply_to: { type: string, description: "The message_id of the message replied to." }
        references: { type: string }
        from: { type: string, format: email, description: "An alias of the mailbox; its own address when left out." }
        tags:
          description: "Labels kept on the message, for reading replies by group (GET .../threads?tag=). A list, or an object sent as key:value; up to 20, each up to 200 characters. Left out, a draft keeps its tags."
          oneOf:
            - { type: array, maxItems: 20, items: { type: string, maxLength: 200 } }
            - { type: object, additionalProperties: { type: string } }
    ThreadChanges:
      type: object
      description: Give at least one.
      properties:
        archived: { type: boolean }
        read: { type: boolean }
        starred: { type: boolean }
        spam: { type: boolean }
        trashed: { type: boolean, description: "True moves the thread to the trash; false restores it." }
        snoozed_until: { type: string, format: date-time, nullable: true, description: "In the future; null wakes the thread." }
        add_label_ids: { type: array, maxItems: 20, items: { type: string } }
        remove_label_ids: { type: array, maxItems: 20, items: { type: string } }
    BounceReport:
      type: object
      description: What a delivery report says about the recipient that failed.
      properties:
        recipient: { type: string, nullable: true }
        status: { type: string, nullable: true, description: "The enhanced status code, such as 5.1.1." }
        action: { type: string, nullable: true, description: "failed or delayed." }
        diagnostic: { type: string, nullable: true, description: "The receiving server's own words." }
        type: { type: string, enum: [hard, soft], description: "hard: the address does not take mail; soft: it may later (4.x.x, delayed, or a full mailbox)." }
    SoftBounce:
      type: object
      properties:
        address: { type: string }
        total: { type: integer }
        in_a_row: { type: integer }
        first_at: { type: string, format: date-time }
        last_at: { type: string, format: date-time }
        last_status: { type: string, nullable: true }
        last_diagnostic: { type: string, nullable: true }
    CalendarEvent:
      type: object
      properties:
        id: { type: string }
        uid: { type: string }
        title: { type: string }
        description: { type: string, nullable: true }
        location: { type: string, nullable: true }
        starts_at: { type: string, format: date-time }
        ends_at: { type: string, format: date-time }
        all_day: { type: boolean }
        timezone: { type: string, nullable: true }
        status: { type: string }
        organizer:
          nullable: true
          allOf: [{ $ref: "#/components/schemas/Address" }]
        is_organizer: { type: boolean }
        my_partstat: { type: string, nullable: true }
        conference_url: { type: string, nullable: true }
        rrule: { type: string, nullable: true }
        attendees:
          type: array
          items:
            type: object
            properties:
              address: { type: string }
              name: { type: string, nullable: true }
              partstat: { type: string }
              is_self: { type: boolean }
        source_message_id: { type: string, nullable: true }
    DocumentText:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        content_type: { type: string }
        size_bytes: { type: integer }
        text: { type: string }
        masking: { type: string, enum: [on], description: "Present when personal data was masked." }
        masked: { type: object, additionalProperties: { type: integer }, description: "Placeholders made, per kind (NAME, EMAIL, PHONE, ID, ORGNR, IBAN, CARD, IP)." }
    Problem:
      type: object
      properties:
        type: { type: string }
        title: { type: string }
        status: { type: integer }
        detail: { type: string }
        errors:
          type: object
          additionalProperties: { type: string }
  responses:
    Problem:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: "#/components/schemas/Problem"
security:
  - bearerAuth: []
