{
  "openapi": "3.1.1",
  "info": {
    "title": "Sortbay E-mail (.eml/.mbox) to JSON API",
    "version": "1.0.0",
    "summary": "Read an .eml or .mbox file: sender, recipients, date, subject, clean text and attachment list.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://sortbayemailparse.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Read an .eml or .mbox file: sender, recipients, date, subject, clean text and attachment list.",
        "description": "Parses e-mail source the way a mail program would — RFC 5322 headers, MIME multipart, quoted-printable and base64, encoded subjects and file names in any charset, mbox archives — and returns each message as JSON: sender, recipients, date in UTC, subject, the readable text (HTML mail reduced to safe plain text), threading ids and the attachments by name, type and size. Attachment contents are never extracted or stored.\n\nMethodology:\n- Headers are unfolded (RFC 5322 §2.2.3), encoded words like =?UTF-8?B?…?= and =?ISO-8859-1?Q?…?= are decoded (RFC 2047), file names with RFC 2231 continuations and charsets are joined; raw 8-bit headers are read as UTF-8, else Windows-1252.\n- Bodies: base64 and quoted-printable are decoded and the declared charset is applied; multipart/alternative prefers the plain-text part; an HTML-only mail is reduced to plain text (scripts, styles and comments removed, all tags dropped, links kept as “text (url)” for http(s) and mailto only, entities decoded).\n- Attachments (including inline images and forwarded messages) are listed with name, type and decoded size; their content is not returned. Forwarded messages (message/rfc822) are also quoted into the text.\n- Dates are converted to UTC from the numeric offset or the obsolete zone names (GMT, EST, PDT …). mbox files split on “From ” lines after an empty line (RFC 4155) and “\u003eFrom ” escapes are undone. Limits: 500 messages, 200 MIME parts and 8 nesting levels per message, 100 000 characters of text.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "sortbay_email_parse",
        "x-owner-app": "sortbay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SortbayEmailParseInput"
              },
              "examples": {
                "example1": {
                  "summary": "Invoice with a PDF and a German subject",
                  "value": {
                    "source": "From: =?UTF-8?Q?J=C3=BCrgen_M=C3=BCller?= \u003cbuchhaltung@example.de\u003e\nTo: \"Example Ltd, Accounts\" \u003caccounts@example.org\u003e\nSubject: =?UTF-8?B?UmVjaG51bmcgTnIuIDIwMjYtMTE4IOKAkyBiaXR0ZSBwcsO8ZmVu?=\nDate: Tue, 1 Dec 2026 08:03:10 +0000\nMessage-ID: \u003cinv-118@example.de\u003e\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"mix-1\"\n\n--mix-1\nContent-Type: multipart/alternative; boundary=\"alt-1\"\n\n--alt-1\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\nGuten Tag,\n\nanbei die Rechnung f=FCr November. Zahlbar innerhalb von 14 Tagen.\n\nGr=FC=DFe\nJ=FCrgen M=FCller\n--alt-1\nContent-Type: text/html; charset=utf-8\n\n\u003chtml\u003e\u003cbody\u003e\u003cp\u003eGuten Tag,\u003c/p\u003e\u003cp\u003eanbei die Rechnung f\u0026uuml;r November.\u003c/p\u003e\u003cscript\u003ealert(1)\u003c/script\u003e\u003c/body\u003e\u003c/html\u003e\n--alt-1--\n\n--mix-1\nContent-Type: application/pdf; name=\"Rechnung-2026-118.pdf\"\nContent-Disposition: attachment; filename=\"Rechnung-2026-118.pdf\"\nContent-Transfer-Encoding: base64\n\nJVBERi0xLjQKJcfsj6IKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c+PgplbmRvYmoKdHJhaWxlcgo8\nPC9Sb290IDEgMCBSPj4KJSVFT0YK\n--mix-1--\n"
                  }
                },
                "example2": {
                  "summary": "HTML-only booking mail (base64)",
                  "value": {
                    "source": "From: Events Team \u003cevents@example.net\u003e\nTo: hello@example.org\nSubject: Your booking for the winter workshop\nDate: Wed, 2 Dec 2026 15:30:00 -0500\nMessage-ID: \u003cbook-77@example.net\u003e\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: base64\n\nPGgxPkJvb2tpbmcgY29uZmlybWVkPC9oMT48cD5IaSBTYW0sPGJyPnlvdXIgc2VhdCBmb3IgdGhl\nIDxiPldpbnRlciB3b3Jrc2hvcDwvYj4gb24gMTIgRGVjZW1iZXIgaXMgYm9va2VkLjwvcD48dWw+\nPGxpPlRpbWU6IDEwOjAwPC9saT48bGk+Um9vbTogQjI8L2xpPjwvdWw+PHA+PGEgaHJlZj0iaHR0\ncHM6Ly9leGFtcGxlLm5ldC9ib29raW5nLzc3Ij5NYW5hZ2UgeW91ciBib29raW5nPC9hPjwvcD48\nc3R5bGU+cHtjb2xvcjpyZWR9PC9zdHlsZT4=\n"
                  }
                },
                "example3": {
                  "summary": "mbox with three messages",
                  "value": {
                    "source": "From maria.lopez@example.com Mon Nov 30 09:12:44 2026\nFrom: \"Maria Lopez\" \u003cmaria.lopez@example.com\u003e\nTo: Support \u003csupport@example.org\u003e\nSubject: Can't log in after the update\nDate: Mon, 30 Nov 2026 09:12:44 +0100\nMessage-ID: \u003ca1-login@example.com\u003e\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\nHi there,\n\nsince yesterday's update I can't log in any more. The page says =E2=80=9Cs=\nession expired=E2=80=9D right after I type my password.\n\nI'm on Firefox on Windows 11. Could you have a look?\n\nThanks,\nMaria\n\nFrom maria.lopez@example.com Mon Nov 30 11:40:02 2026\nFrom: Maria Lopez \u003cmaria.lopez@example.com\u003e\nTo: support@example.org\nSubject: Re: Can't log in after the update\nDate: Mon, 30 Nov 2026 11:40:02 +0100\nMessage-ID: \u003ca2-login@example.com\u003e\nIn-Reply-To: \u003ca1-login@example.com\u003e\nReferences: \u003ca1-login@example.com\u003e\nContent-Type: text/plain; charset=us-ascii\n\nClearing the cookies helped, thank you! Still strange that it happened.\n\nMaria\n\nFrom priya@shop.example Tue Dec  1 08:35:00 2026\nFrom: Priya Natarajan \u003cpriya@shop.example\u003e\nTo: sales@example.org\nCc: Tom Becker \u003ctom@shop.example\u003e\nSubject: Quote for 40 seats?\nDate: Tue, 01 Dec 2026 14:05:00 +0530\nMessage-ID: \u003clead-40@shop.example\u003e\nContent-Type: text/plain; charset=utf-8\n\nHello,\n\nwe are a team of 40 and would like a quote for annual licences, ideally with\na training session in January. Can you send pricing by Friday?\n\n\u003eFrom the team side we are flexible.\n\nBest regards,\nPriya\n"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SortbayEmailParseResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SortbayEmailParseInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "title": "E-mail source (.eml text) or mbox",
            "description": "Paste the full source of a message (headers, a blank line, then the body) — in most mail programs “Show original” or “View source”. Several messages: paste an mbox (each starts with a “From ” line).",
            "type": "string",
            "maxLength": 2000000,
            "default": "From: =?UTF-8?Q?J=C3=BCrgen_M=C3=BCller?= \u003cbuchhaltung@example.de\u003e\nTo: \"Example Ltd, Accounts\" \u003caccounts@example.org\u003e\nSubject: =?UTF-8?B?UmVjaG51bmcgTnIuIDIwMjYtMTE4IOKAkyBiaXR0ZSBwcsO8ZmVu?=\nDate: Tue, 1 Dec 2026 08:03:10 +0000\nMessage-ID: \u003cinv-118@example.de\u003e\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"mix-1\"\n\n--mix-1\nContent-Type: multipart/alternative; boundary=\"alt-1\"\n\n--alt-1\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\nGuten Tag,\n\nanbei die Rechnung f=FCr November. Zahlbar innerhalb von 14 Tagen.\n\nGr=FC=DFe\nJ=FCrgen M=FCller\n--alt-1\nContent-Type: text/html; charset=utf-8\n\n\u003chtml\u003e\u003cbody\u003e\u003cp\u003eGuten Tag,\u003c/p\u003e\u003cp\u003eanbei die Rechnung f\u0026uuml;r November.\u003c/p\u003e\u003cscript\u003ealert(1)\u003c/script\u003e\u003c/body\u003e\u003c/html\u003e\n--alt-1--\n\n--mix-1\nContent-Type: application/pdf; name=\"Rechnung-2026-118.pdf\"\nContent-Disposition: attachment; filename=\"Rechnung-2026-118.pdf\"\nContent-Transfer-Encoding: base64\n\nJVBERi0xLjQKJcfsj6IKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c+PgplbmRvYmoKdHJhaWxlcgo8\nPC9Sb290IDEgMCBSPj4KJSVFT0YK\n--mix-1--\n"
          },
          "file": {
            "title": "E-mail file (.eml or .mbox, optional)",
            "description": "Up to 10 MB. Used instead of the pasted text when given. Export single mails as .eml or a folder as .mbox from your mail program. Upload as {filename, contentType?, contentBase64}. Max 9766 KiB. Accepts .eml,.mbox,.mbx,.txt,message/rfc822,application/mbox,text/plain.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          },
          "includeHeaders": {
            "title": "Include every header line in the result",
            "type": "boolean",
            "default": false
          }
        },
        "required": []
      },
      "SortbayEmailParseResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "kind",
              "count",
              "truncated",
              "messages"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "eml",
                  "mbox"
                ]
              },
              "count": {
                "type": "integer"
              },
              "truncated": {
                "type": "boolean"
              },
              "messages": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "subject",
                    "from",
                    "to",
                    "date",
                    "text",
                    "attachments"
                  ]
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}