{
  "openapi": "3.0.3",
  "info": {
    "title": "LFMail Receiving API",
    "version": "1.0.0",
    "description": "Read-only access to one mailbox per key. Create and revoke keys in webmail Settings > Apps and integrations. HTTPS required; no browser Origin. 60 requests/minute/key, 120/IP. Poll and deduplicate IDs. No sending or outgoing webhook subscription."
  },
  "servers": [
    {
      "url": "https://mail.lfmail.com.br/api/v1"
    }
  ],
  "security": [
    {
      "MailboxKey": []
    }
  ],
  "paths": {
    "/mailbox": {
      "get": {
        "operationId": "getMailbox",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "address",
                    "scope",
                    "sendingAvailable"
                  ],
                  "properties": {
                    "address": {
                      "type": "string",
                      "format": "email"
                    },
                    "scope": {
                      "type": "string",
                      "enum": [
                        "mail:read"
                      ]
                    },
                    "sendingAvailable": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or message ID",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Inactive mailbox or disallowed browser origin",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Message not found in this mailbox",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited; honor Retry-After",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retrying"
              }
            }
          },
          "502": {
            "description": "Mail backend unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/messages": {
      "get": {
        "operationId": "listMessages",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "messages",
                    "queryState",
                    "nextPosition"
                  ],
                  "properties": {
                    "messages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "queryState": {
                      "type": "string"
                    },
                    "nextPosition": {
                      "type": "integer",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or message ID",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Inactive mailbox or disallowed browser origin",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Message not found in this mailbox",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited; honor Retry-After",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retrying"
              }
            }
          },
          "502": {
            "description": "Mail backend unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "in": "query",
            "name": "position",
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0,
              "maximum": 100000
            }
          },
          {
            "in": "query",
            "name": "before",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Messages received before this UTC timestamp."
          }
        ]
      }
    },
    "/messages/{id}": {
      "get": {
        "operationId": "getMessage",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or message ID",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Inactive mailbox or disallowed browser origin",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Message not found in this mailbox",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited; honor Retry-After",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retrying"
              }
            }
          },
          "502": {
            "description": "Mail backend unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-zA-Z0-9_-]{1,160}$"
            }
          }
        ]
      }
    },
    "/messages/{id}/raw": {
      "get": {
        "operationId": "downloadOriginalMessage",
        "responses": {
          "200": {
            "description": "Original MIME including attachments",
            "content": {
              "message/rfc822": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or message ID",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Inactive mailbox or disallowed browser origin",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Message not found in this mailbox",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited; honor Retry-After",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retrying"
              }
            }
          },
          "502": {
            "description": "Mail backend unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-zA-Z0-9_-]{1,160}$"
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "MailboxKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "lfm_<43 base64url characters>"
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "title",
          "status"
        ]
      },
      "Address": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "nullable": true
          },
          "email": {
            "type": "string"
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "subject": {
            "type": "string",
            "nullable": true
          },
          "from": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/Address"
            }
          },
          "to": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/Address"
            }
          },
          "receivedAt": {
            "type": "string",
            "format": "date-time"
          },
          "preview": {
            "type": "string"
          },
          "hasAttachment": {
            "type": "boolean"
          },
          "size": {
            "type": "integer"
          },
          "textBody": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BodyPart"
            }
          },
          "htmlBody": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BodyPart"
            }
          },
          "attachments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BodyPart"
            }
          },
          "bodyValues": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "string"
                },
                "isTruncated": {
                  "type": "boolean"
                },
                "isEncodingProblem": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "BodyPart": {
        "type": "object",
        "properties": {
          "partId": {
            "type": "string"
          },
          "blobId": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "size": {
            "type": "integer"
          }
        }
      }
    }
  }
}
