@bumail/smtp 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +105 -7
  2. package/dist/chunks/{index-3423jxf9.js → index-n4xwep5m.js} +10 -4
  3. package/dist/chunks/index-n4xwep5m.js.map +14 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/errors.d.ts +3 -1
  6. package/dist/errors.d.ts.map +1 -1
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +724 -126
  10. package/dist/index.js.map +19 -9
  11. package/dist/protocol/command.d.ts +4 -2
  12. package/dist/protocol/command.d.ts.map +1 -1
  13. package/dist/protocol/path.d.ts +13 -2
  14. package/dist/protocol/path.d.ts.map +1 -1
  15. package/dist/server/admission.d.ts +29 -0
  16. package/dist/server/admission.d.ts.map +1 -0
  17. package/dist/server/client-key.d.ts +15 -0
  18. package/dist/server/client-key.d.ts.map +1 -0
  19. package/dist/server/listener.d.ts +46 -0
  20. package/dist/server/listener.d.ts.map +1 -0
  21. package/dist/server/options.d.ts +45 -1
  22. package/dist/server/options.d.ts.map +1 -1
  23. package/dist/server/proxy/address.d.ts +17 -0
  24. package/dist/server/proxy/address.d.ts.map +1 -0
  25. package/dist/server/proxy/header.d.ts +26 -0
  26. package/dist/server/proxy/header.d.ts.map +1 -0
  27. package/dist/server/proxy/reader.d.ts +15 -0
  28. package/dist/server/proxy/reader.d.ts.map +1 -0
  29. package/dist/server/proxy/tls.d.ts +50 -0
  30. package/dist/server/proxy/tls.d.ts.map +1 -0
  31. package/dist/server/proxy/trusted.d.ts +9 -0
  32. package/dist/server/proxy/trusted.d.ts.map +1 -0
  33. package/dist/server/raw-socket.d.ts +9 -0
  34. package/dist/server/raw-socket.d.ts.map +1 -0
  35. package/dist/server/received.d.ts +2 -0
  36. package/dist/server/received.d.ts.map +1 -1
  37. package/dist/server/server.d.ts.map +1 -1
  38. package/dist/server/settings.d.ts +4 -0
  39. package/dist/server/settings.d.ts.map +1 -1
  40. package/dist/server/slots.d.ts +14 -0
  41. package/dist/server/slots.d.ts.map +1 -0
  42. package/dist/server/tls-context.d.ts +16 -0
  43. package/dist/server/tls-context.d.ts.map +1 -0
  44. package/dist/server/transaction.d.ts.map +1 -1
  45. package/dist/server/transport.d.ts +2 -2
  46. package/dist/server/transport.d.ts.map +1 -1
  47. package/docs/README.md +2 -2
  48. package/docs/guide.md +472 -12
  49. package/docs/roadmap.md +57 -0
  50. package/docs/troubleshooting.md +406 -4
  51. package/package.json +2 -2
  52. package/dist/chunks/index-3423jxf9.js.map +0 -14
package/dist/index.js.map CHANGED
@@ -1,25 +1,35 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/protocol/command.ts", "../src/protocol/data.ts", "../src/protocol/reply.ts", "../src/server/guard.ts", "../src/server/auth.ts", "../src/server/state.ts", "../src/server/transaction.ts", "../src/server/commands.ts", "../src/server/received.ts", "../src/server/refusals.ts", "../src/server/intake.ts", "../src/server/input.ts", "../src/server/connection.ts", "../src/server/settings.ts", "../src/server/transport.ts", "../src/server/server.ts"],
3
+ "sources": ["../src/protocol/command.ts", "../src/protocol/data.ts", "../src/protocol/reply.ts", "../src/server/client-key.ts", "../src/server/guard.ts", "../src/server/auth.ts", "../src/server/state.ts", "../src/server/transaction.ts", "../src/server/commands.ts", "../src/server/received.ts", "../src/server/refusals.ts", "../src/server/intake.ts", "../src/server/input.ts", "../src/server/connection.ts", "../src/server/transport.ts", "../src/server/listener.ts", "../src/server/proxy/address.ts", "../src/server/proxy/header.ts", "../src/server/proxy/reader.ts", "../src/server/proxy/tls.ts", "../src/server/admission.ts", "../src/server/proxy/trusted.ts", "../src/server/settings.ts", "../src/server/slots.ts", "../src/server/tls-context.ts", "../src/server/server.ts"],
4
4
  "sourcesContent": [
5
- "import { type Path, parsePath } from './path';\n\n/** A command line, split into its verb (upper case) and the rest. */\nexport interface Command {\n\treadonly verb: string;\n\treadonly argument: string;\n}\n\nexport function parseCommand(line: string): Command {\n\tconst space = line.indexOf(' ');\n\tif (space < 0) return { verb: line.toUpperCase(), argument: '' };\n\treturn {\n\t\tverb: line.slice(0, space).toUpperCase(),\n\t\targument: line.slice(space + 1).trim(),\n\t};\n}\n\n/** `MAIL FROM:<path> params` or `RCPT TO:<path> params`, parsed. */\nexport interface PathCommand {\n\treadonly path: Path;\n\t/** ESMTP parameters (RFC 5321 §4.1.2), keys in upper case; a key with no `=` has the value `''`. */\n\treadonly parameters: Readonly<Record<string, string>>;\n}\n\n/**\n * Parses the argument of `MAIL` or `RCPT`: `FROM:<path> params` (or `TO:`).\n * Tolerates a space after the colon, which many clients send. `undefined`\n * when the syntax is wrong.\n */\nexport function parsePathCommand(\n\targument: string,\n\tkeyword: 'FROM' | 'TO',\n): PathCommand | undefined {\n\tconst match = new RegExp(`^${keyword}:\\\\s*(<[^>]*>)(.*)$`, 'i').exec(\n\t\targument,\n\t);\n\tif (!match) return undefined;\n\tconst path = parsePath(match[1] as string, keyword === 'FROM');\n\tif (!path) return undefined;\n\tconst parameters: Record<string, string> = {};\n\tfor (const item of (match[2] as string).trim().split(/\\s+/)) {\n\t\tif (item === '') continue;\n\t\tconst equals = item.indexOf('=');\n\t\tconst key = (equals < 0 ? item : item.slice(0, equals)).toUpperCase();\n\t\tif (!/^[A-Z0-9][A-Z0-9-]*$/.test(key)) return undefined;\n\t\tparameters[key] = equals < 0 ? '' : item.slice(equals + 1);\n\t}\n\treturn { path, parameters };\n}\n",
5
+ "import { type Path, POSTMASTER, parsePath } from './path';\n\n/** A command line, split into its verb (upper case) and the rest. */\nexport interface Command {\n\treadonly verb: string;\n\treadonly argument: string;\n}\n\nexport function parseCommand(line: string): Command {\n\tconst space = line.indexOf(' ');\n\tif (space < 0) return { verb: line.toUpperCase(), argument: '' };\n\treturn {\n\t\tverb: line.slice(0, space).toUpperCase(),\n\t\targument: line.slice(space + 1).trim(),\n\t};\n}\n\n/** `MAIL FROM:<path> params` or `RCPT TO:<path> params`, parsed. */\nexport interface PathCommand {\n\treadonly path: Path;\n\t/** ESMTP parameters (RFC 5321 §4.1.2), keys in upper case; a key with no `=` has the value `''`. */\n\treadonly parameters: Readonly<Record<string, string>>;\n}\n\n/**\n * Parses the argument of `MAIL` or `RCPT`: `FROM:<path> params` (or `TO:`).\n * Tolerates a space after the colon, which many clients send. `TO:` also\n * takes `<postmaster>` with no domain, in any case (RFC 5321 §4.1.1.3,\n * §4.5.1), as a path whose `postmaster` is `true`. `undefined` when the\n * syntax is wrong.\n */\nexport function parsePathCommand(\n\targument: string,\n\tkeyword: 'FROM' | 'TO',\n): PathCommand | undefined {\n\tconst match = new RegExp(`^${keyword}:\\\\s*(<[^>]*>)(.*)$`, 'i').exec(\n\t\targument,\n\t);\n\tif (!match) return undefined;\n\tconst text = match[1] as string;\n\tconst path =\n\t\tkeyword === 'TO' && text.toLowerCase() === '<postmaster>'\n\t\t\t? POSTMASTER\n\t\t\t: parsePath(text, keyword === 'FROM');\n\tif (!path) return undefined;\n\tconst parameters: Record<string, string> = {};\n\tfor (const item of (match[2] as string).trim().split(/\\s+/)) {\n\t\tif (item === '') continue;\n\t\tconst equals = item.indexOf('=');\n\t\tconst key = (equals < 0 ? item : item.slice(0, equals)).toUpperCase();\n\t\tif (!/^[A-Z0-9][A-Z0-9-]*$/.test(key)) return undefined;\n\t\tparameters[key] = equals < 0 ? '' : item.slice(equals + 1);\n\t}\n\treturn { path, parameters };\n}\n",
6
6
  "const CR = 0x0d;\nconst LF = 0x0a;\nconst DOT = 0x2e;\n\n/** The result of one chunk of DATA. */\nexport interface DataChunk {\n\t/** The message bytes in this chunk, dot-unstuffed. */\n\treadonly data: Uint8Array;\n\t/** The terminating `<CRLF>.<CRLF>` was read. */\n\treadonly done: boolean;\n\t/** What followed the terminator: the next pipelined commands. */\n\treadonly rest: Uint8Array;\n}\n\n/**\n * Reads the content of `DATA` (RFC 5321 §4.1.1.4): removes the leading dot\n * that §4.5.2 adds to lines starting with one, and stops at `<CRLF>.<CRLF>`\n * — that exact sequence and no other, so a bare LF before a dot cannot end\n * the message (SMTP smuggling). It counts the bare CRs and LFs it meets,\n * for the server to refuse the message.\n */\nexport class DataReader {\n\t/** The next byte starts a line: it follows CRLF, or opens the message. */\n\t#lineStart = true;\n\t/** Bytes held back: a CR, or a dot at a line start, whose meaning depends on what follows. */\n\t#held: number[] = [];\n\t#size = 0;\n\tbareLineBreaks = 0;\n\n\t/** The bytes of message read so far, after unstuffing. */\n\tget size(): number {\n\t\treturn this.#size;\n\t}\n\n\twrite(chunk: Uint8Array): DataChunk {\n\t\t// The output never outgrows the chunk and the two bytes held before it.\n\t\tconst out = new Uint8Array(chunk.length + 2);\n\t\tlet n = 0;\n\t\tfor (let i = 0; i < chunk.length; i++) {\n\t\t\tconst byte = chunk[i] as number;\n\t\t\tconst held = this.#held;\n\t\t\tif (held.length > 0) {\n\t\t\t\t// Held: [CR], [DOT], [DOT, CR].\n\t\t\t\tif (held[0] === DOT && held.length === 1) {\n\t\t\t\t\tif (byte === CR) {\n\t\t\t\t\t\theld.push(CR);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t// A stuffed dot: drop it, and read this byte as the line's first.\n\t\t\t\t\tthis.#held = [];\n\t\t\t\t\tthis.#lineStart = false;\n\t\t\t\t\ti--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (held[0] === DOT && held.length === 2) {\n\t\t\t\t\tthis.#held = [];\n\t\t\t\t\tif (byte === LF) {\n\t\t\t\t\t\tthis.#size += n;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tdata: out.subarray(0, n),\n\t\t\t\t\t\t\tdone: true,\n\t\t\t\t\t\t\trest: chunk.slice(i + 1),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\t// `.` CR x: the dot was stuffing; the CR is bare.\n\t\t\t\t\tthis.bareLineBreaks++;\n\t\t\t\t\tout[n++] = CR;\n\t\t\t\t\tthis.#lineStart = false;\n\t\t\t\t\ti--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Held a CR.\n\t\t\t\tthis.#held = [];\n\t\t\t\tif (byte === LF) {\n\t\t\t\t\tout[n++] = CR;\n\t\t\t\t\tout[n++] = LF;\n\t\t\t\t\tthis.#lineStart = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.bareLineBreaks++;\n\t\t\t\tout[n++] = CR;\n\t\t\t\tthis.#lineStart = false;\n\t\t\t\ti--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (byte === CR) {\n\t\t\t\tthis.#held = [CR];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (byte === DOT && this.#lineStart) {\n\t\t\t\tthis.#held = [DOT];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (byte === LF) this.bareLineBreaks++;\n\t\t\tout[n++] = byte;\n\t\t\tthis.#lineStart = false;\n\t\t}\n\t\tthis.#size += n;\n\t\treturn { data: out.subarray(0, n), done: false, rest: new Uint8Array(0) };\n\t}\n}\n",
7
7
  "/** An SMTP reply (RFC 5321 §4.2), with its enhanced status code (RFC 3463) when it has one. */\nexport interface Reply {\n\treadonly code: number;\n\t/** `x.y.z`, written before the text of each line (RFC 2034 §4). */\n\treadonly status?: string;\n\t/** One line or more; a multi-line reply joins them with `code-`. */\n\treadonly text: string | readonly string[];\n}\n\n/** The reply as sent: every line but the last as `code-`, the last as `code `, each ending in CRLF. */\nexport function formatReply(reply: Reply, enhanced = true): string {\n\tconst lines = typeof reply.text === 'string' ? [reply.text] : reply.text;\n\tconst status = enhanced && reply.status ? `${reply.status} ` : '';\n\treturn lines\n\t\t.map((line, i) => {\n\t\t\tconst clean = line.replace(/[\\r\\n]+/g, ' ');\n\t\t\treturn `${reply.code}${i === lines.length - 1 ? ' ' : '-'}${status}${clean}\\r\\n`;\n\t\t})\n\t\t.join('');\n}\n\n/** Builds a reply. */\nexport const reply = (\n\tcode: number,\n\tstatus: string | undefined,\n\ttext: string | readonly string[],\n): Reply => (status === undefined ? { code, text } : { code, status, text });\n",
8
+ "import { isIP } from 'node:net';\n\n/** The 8 groups of an IPv6 address, as numbers; a dotted tail is its last two. */\nfunction groups(ip: string): number[] {\n\tconst dotted = /(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(ip);\n\tlet text = ip;\n\tif (dotted !== null) {\n\t\tconst [a, b, c, d] = dotted.slice(1).map(Number) as [\n\t\t\tnumber,\n\t\t\tnumber,\n\t\t\tnumber,\n\t\t\tnumber,\n\t\t];\n\t\ttext = `${ip.slice(0, dotted.index)}${((a << 8) | b).toString(16)}:${((c << 8) | d).toString(16)}`;\n\t}\n\tconst [head = '', tail] = text.split('::');\n\tconst left = head === '' ? [] : head.split(':');\n\tconst right = tail === undefined || tail === '' ? [] : tail.split(':');\n\tconst all =\n\t\ttail === undefined\n\t\t\t? left\n\t\t\t: [...left, ...Array(8 - left.length - right.length).fill('0'), ...right];\n\treturn all.map((group) => Number.parseInt(group, 16));\n}\n\n/** The IPv4 address in the last 32 bits. */\nfunction ipv4Of(g: readonly number[]): string {\n\tconst [high = 0, low = 0] = g.slice(6);\n\treturn [high >> 8, high & 255, low >> 8, low & 255].join('.');\n}\n\n/**\n * Which client an address counts as, for a limit per client: an IPv4\n * address as it is; an IPv6 address that embeds one — IPv4-mapped\n * (`::ffff:192.0.2.1`, in dotted or hex form, as a dual-stack listener\n * sees an IPv4 client) or NAT64 (`64:ff9b::/96`) — as that IPv4 address;\n * any other IPv6 address by its /64, which one machine usually holds\n * whole, written as its first four groups in lower-case hex without\n * leading zeros, every group written out, zeros included, then `::/64`:\n * `2001:db8::1` is `2001:db8:0:0::/64`, never `2001:db8::/64`. Anything\n * else — an empty string, a Unix socket — is `undefined`: no client that\n * can be told apart, so not limited, rather than putting every such\n * client in one bucket that one of them could fill for all.\n */\nexport function clientKey(ip: string | undefined): string | undefined {\n\tif (typeof ip !== 'string') return undefined;\n\tconst address = ip.replace(/^\\[|\\]$/g, '').replace(/%.*$/, '');\n\tif (isIP(address) === 4) return address;\n\tif (isIP(address) !== 6) return undefined;\n\tconst g = groups(address.toLowerCase());\n\tconst prefix = g.slice(0, 6).join(':');\n\tif (prefix === '0:0:0:0:0:65535' || prefix === '100:65435:0:0:0:0') {\n\t\treturn ipv4Of(g);\n\t}\n\treturn `${g\n\t\t.slice(0, 4)\n\t\t.map((group) => group.toString(16))\n\t\t.join(':')}::/64`;\n}\n",
8
9
  "import { SmtpError } from '../errors';\nimport { type Reply, reply } from '../protocol/reply';\n\n/** The reply when a hook throws, times out or answers what is not a refusal. */\nexport const LOCAL_ERROR = reply(451, '4.3.0', 'Local error in processing');\n\nconst TIMED_OUT = Symbol('timed out');\n\n/** `promise`, or `TIMED_OUT` once `seconds` have passed. */\nexport async function within<T>(\n\tpromise: Promise<T>,\n\tseconds: number,\n): Promise<T | typeof TIMED_OUT> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst deadline = new Promise<typeof TIMED_OUT>((resolve) => {\n\t\ttimer = setTimeout(() => resolve(TIMED_OUT), seconds * 1000);\n\t});\n\ttry {\n\t\treturn await Promise.race([promise, deadline]);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nexport function timedOut(value: unknown): value is typeof TIMED_OUT {\n\treturn value === TIMED_OUT;\n}\n\nexport function hookTimeout(name: string, seconds: number): SmtpError {\n\treturn new SmtpError(\n\t\t'HOOK_TIMEOUT',\n\t\t`${name} did not settle within hookTimeout (${seconds} s)`,\n\t);\n}\n\n/**\n * What a hook answered, as the reply to send: `undefined` to go on, or the\n * refusal. A reply under 400 is not a refusal — sending it would tell the\n * client yes while the server did not take the command — so it is reported\n * and answered as a local error.\n */\nexport function refusalOf(\n\tname: string,\n\tanswer: unknown,\n\treport: (error: unknown) => void,\n): Reply | undefined {\n\tif (answer === undefined) return undefined;\n\tconst code = (answer as Partial<Reply> | null)?.code;\n\tif (typeof code === 'number' && code >= 400 && code < 600) {\n\t\treturn answer as Reply;\n\t}\n\treport(\n\t\tnew SmtpError(\n\t\t\t'INVALID_HOOK_REPLY',\n\t\t\t`${name} answered ${JSON.stringify(answer)}, which is not a refusal: a hook refuses with a 4xx or 5xx reply, and accepts with undefined`,\n\t\t),\n\t);\n\treturn LOCAL_ERROR;\n}\n",
9
10
  "import { reply } from '../protocol/reply';\nimport {\n\ttype Credentials,\n\tdecodeLoginStep,\n\tdecodePlain,\n} from '../protocol/sasl';\nimport type { Connection } from './connection';\n\n/** Failed AUTH attempts before the server hangs up. */\nconst MAX_AUTH_FAILURES = 3;\n\nasync function check(\n\tconnection: Connection,\n\tcredentials: Credentials | undefined,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tstate.waiting = 'command';\n\tstate.loginUser = undefined;\n\tif (credentials === undefined) {\n\t\treturn connection.fail(reply(501, '5.5.2', 'Cannot decode the response'));\n\t}\n\tif (\n\t\tcredentials.authorizationId !== undefined &&\n\t\tcredentials.authorizationId !== credentials.username\n\t) {\n\t\t// A session acts as the user it authenticated as, never as another.\n\t\treturn refuse(connection);\n\t}\n\tconst { authenticate } = settings.options;\n\tconst answer = await connection.check('authenticate', () =>\n\t\tauthenticate?.(credentials, connection.session),\n\t);\n\tif (answer.failed) {\n\t\t// RFC 4954 §6: a failure of the server's own, not of the credentials.\n\t\treturn connection.send(\n\t\t\treply(454, '4.7.0', 'Temporary authentication failure'),\n\t\t);\n\t}\n\tconst ok = answer.value === true;\n\tif (ok) {\n\t\tstate.user = credentials.username;\n\t\treturn connection.send(reply(235, '2.7.0', 'Authentication successful'));\n\t}\n\trefuse(connection);\n}\n\nfunction refuse(connection: Connection): void {\n\tconst { state, settings } = connection;\n\tstate.authFailures++;\n\tif (state.authFailures >= MAX_AUTH_FAILURES) {\n\t\tconst { hostname } = settings.options;\n\t\tconnection.close(\n\t\t\treply(\n\t\t\t\t421,\n\t\t\t\t'4.7.0',\n\t\t\t\t`${hostname} Too many failed authentications, closing`,\n\t\t\t),\n\t\t);\n\t\treturn;\n\t}\n\tconnection.fail(reply(535, '5.7.8', 'Authentication credentials invalid'));\n}\n\n/** `AUTH PLAIN [initial]` or `AUTH LOGIN [initial]` (RFC 4954), over TLS only. */\nexport async function authenticate(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tif (!settings.options.authenticate)\n\t\treturn connection.fail(reply(502, '5.5.1', 'AUTH not available'));\n\tif (!state.secure)\n\t\treturn connection.fail(\n\t\t\treply(\n\t\t\t\t538,\n\t\t\t\t'5.7.11',\n\t\t\t\t'Encryption required for requested authentication mechanism',\n\t\t\t),\n\t\t);\n\tif (state.helo === undefined || !state.esmtp)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Send EHLO first'));\n\tif (state.user !== undefined)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Already authenticated'));\n\tif (state.transaction.from !== undefined)\n\t\treturn connection.fail(\n\t\t\treply(503, '5.5.1', 'AUTH not allowed during a transaction'),\n\t\t);\n\tconst [mechanism = '', initial, extra] = argument.split(' ');\n\tif (extra !== undefined)\n\t\treturn connection.fail(\n\t\t\treply(501, '5.5.4', 'Syntax: AUTH mechanism [initial-response]'),\n\t\t);\n\tswitch (mechanism.toUpperCase()) {\n\t\tcase 'PLAIN':\n\t\t\tif (initial === undefined) {\n\t\t\t\tstate.waiting = 'auth-plain';\n\t\t\t\treturn connection.send(reply(334, undefined, ''));\n\t\t\t}\n\t\t\treturn check(connection, decodePlain(initial === '=' ? '' : initial));\n\t\tcase 'LOGIN':\n\t\t\tif (initial === undefined) {\n\t\t\t\tstate.waiting = 'auth-login-user';\n\t\t\t\treturn connection.send(reply(334, undefined, 'VXNlcm5hbWU6'));\n\t\t\t}\n\t\t\treturn loginUser(connection, initial);\n\t\tdefault:\n\t\t\treturn connection.fail(\n\t\t\t\treply(504, '5.5.4', 'Unrecognized authentication type'),\n\t\t\t);\n\t}\n}\n\nfunction loginUser(\n\tconnection: Connection,\n\tresponse: string,\n): void | Promise<void> {\n\tconst user = decodeLoginStep(response);\n\tif (!user) return check(connection, undefined);\n\tconnection.state.loginUser = user;\n\tconnection.state.waiting = 'auth-login-password';\n\tconnection.send(reply(334, undefined, 'UGFzc3dvcmQ6'));\n}\n\n/** The client's line after a 334 challenge. */\nexport async function continueAuth(\n\tconnection: Connection,\n\tline: string,\n): Promise<void> {\n\tconst { state } = connection;\n\tif (line === '*') {\n\t\tstate.waiting = 'command';\n\t\tstate.loginUser = undefined;\n\t\treturn connection.fail(reply(501, '5.0.0', 'Authentication cancelled'));\n\t}\n\tswitch (state.waiting) {\n\t\tcase 'auth-plain':\n\t\t\treturn check(connection, decodePlain(line));\n\t\tcase 'auth-login-user':\n\t\t\treturn loginUser(connection, line);\n\t\tdefault: {\n\t\t\tconst password = decodeLoginStep(line);\n\t\t\tconst username = state.loginUser ?? '';\n\t\t\treturn check(\n\t\t\t\tconnection,\n\t\t\t\tpassword ? { mechanism: 'LOGIN', username, password } : undefined,\n\t\t\t);\n\t\t}\n\t}\n}\n",
10
11
  "import type { Envelope } from './options';\n\n/** A mail transaction in progress (RFC 5321 §3.3). */\nexport interface Transaction {\n\tfrom?: string;\n\tto: string[];\n\tsmtputf8: boolean;\n\tbody: Envelope['body'];\n}\n\n/** What the next line from the client is. */\nexport type Waiting =\n\t| 'command'\n\t| 'data'\n\t| 'auth-plain'\n\t| 'auth-login-user'\n\t| 'auth-login-password';\n\n/** The state of a session the commands change. */\nexport interface State {\n\thelo?: string | undefined;\n\tesmtp: boolean;\n\tuser?: string | undefined;\n\tsecure: boolean;\n\ttransaction: Transaction;\n\twaiting: Waiting;\n\tloginUser?: string | undefined;\n\terrors: number;\n\tauthFailures: number;\n}\n\nexport const emptyTransaction = (): Transaction => ({\n\tto: [],\n\tsmtputf8: false,\n\tbody: '7BIT',\n});\n",
11
- "import { parsePathCommand } from '../protocol/command';\nimport { reply } from '../protocol/reply';\nimport type { Connection } from './connection';\nimport { LOCAL_ERROR } from './guard';\n\nfunction nonAscii(text: string): boolean {\n\tfor (let i = 0; i < text.length; i++)\n\t\tif (text.charCodeAt(i) > 0x7f) return true;\n\treturn false;\n}\n\n/** `MAIL FROM:<path> [SIZE=] [BODY=] [SMTPUTF8] [AUTH=]` (RFC 5321 §4.1.1.2). */\nexport async function mail(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tif (state.helo === undefined)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Send EHLO first'));\n\tif (state.transaction.from !== undefined) {\n\t\treturn connection.fail(reply(503, '5.5.1', 'Nested MAIL command'));\n\t}\n\tif (settings.mode === 'submission' && state.user === undefined) {\n\t\treturn connection.fail(reply(530, '5.7.0', 'Authentication required'));\n\t}\n\tconst command = parsePathCommand(argument, 'FROM');\n\tif (!command)\n\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: MAIL FROM:<address>'));\n\tconst { path, parameters } = command;\n\tlet body: '7BIT' | '8BITMIME' = '7BIT';\n\tlet smtputf8 = false;\n\tfor (const [key, value] of Object.entries(parameters)) {\n\t\tif (!state.esmtp)\n\t\t\treturn connection.fail(reply(555, '5.5.4', `${key} needs EHLO`));\n\t\tif (key === 'SIZE') {\n\t\t\tif (!/^\\d+$/.test(value))\n\t\t\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: SIZE=<bytes>'));\n\t\t\tif (Number(value) > settings.maxMessageSize) {\n\t\t\t\treturn connection.fail(\n\t\t\t\t\treply(552, '5.3.4', 'Message too big for system'),\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (key === 'BODY') {\n\t\t\tconst kind = value.toUpperCase();\n\t\t\tif (kind !== '7BIT' && kind !== '8BITMIME') {\n\t\t\t\treturn connection.fail(reply(501, '5.5.4', 'BODY is 7BIT or 8BITMIME'));\n\t\t\t}\n\t\t\tbody = kind;\n\t\t} else if (key === 'SMTPUTF8' && value === '') {\n\t\t\tsmtputf8 = true;\n\t\t} else if (key === 'AUTH') {\n\t\t\t// RFC 4954 §5: the original submitter; taken and not passed on.\n\t\t} else {\n\t\t\treturn connection.fail(reply(555, '5.5.4', `${key} is not supported`));\n\t\t}\n\t}\n\tif (!smtputf8 && nonAscii(path.address)) {\n\t\treturn connection.fail(\n\t\t\treply(553, '5.6.7', 'A non-ASCII address needs SMTPUTF8'),\n\t\t);\n\t}\n\tconst options = settings.options;\n\tconst refused = options.onMailFrom\n\t\t? await connection.hook('onMailFrom', () =>\n\t\t\t\toptions.onMailFrom?.(path, connection.session),\n\t\t\t)\n\t\t: undefined;\n\tif (refused) return connection.send(refused);\n\tstate.transaction = { from: path.address, to: [], smtputf8, body };\n\tconnection.send(reply(250, '2.1.0', 'OK'));\n}\n\n/** `RCPT TO:<path>` (RFC 5321 §4.1.1.3), where relaying is refused without AUTH. */\nexport async function rcpt(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tif (state.transaction.from === undefined)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Send MAIL first'));\n\tconst command = parsePathCommand(argument, 'TO');\n\tif (!command)\n\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: RCPT TO:<address>'));\n\tconst { path, parameters } = command;\n\tif (Object.keys(parameters).length > 0) {\n\t\treturn connection.fail(\n\t\t\treply(555, '5.5.4', `${Object.keys(parameters)[0]} is not supported`),\n\t\t);\n\t}\n\tif (!state.transaction.smtputf8 && nonAscii(path.address)) {\n\t\treturn connection.fail(\n\t\t\treply(553, '5.6.7', 'A non-ASCII address needs SMTPUTF8'),\n\t\t);\n\t}\n\tif (state.transaction.to.length >= settings.maxRecipients) {\n\t\treturn connection.send(reply(452, '4.5.3', 'Too many recipients'));\n\t}\n\t// Never an open relay: a domain this server does not host takes AUTH.\n\tif (state.user === undefined) {\n\t\tconst local = await connection.check('localDomains', () =>\n\t\t\tsettings.isLocal(path.domain),\n\t\t);\n\t\tif (local.failed) return connection.send(LOCAL_ERROR);\n\t\tif (local.value !== true) {\n\t\t\treturn connection.fail(reply(554, '5.7.1', 'Relay access denied'));\n\t\t}\n\t}\n\tconst options = settings.options;\n\tconst refused = options.onRcptTo\n\t\t? await connection.hook('onRcptTo', () =>\n\t\t\t\toptions.onRcptTo?.(path, connection.session),\n\t\t\t)\n\t\t: undefined;\n\tif (refused) return connection.send(refused);\n\tstate.transaction.to.push(path.address);\n\tconnection.send(reply(250, '2.1.5', 'OK'));\n}\n",
12
+ "import { parsePathCommand } from '../protocol/command';\nimport { reply } from '../protocol/reply';\nimport type { Connection } from './connection';\nimport { LOCAL_ERROR } from './guard';\n\nfunction nonAscii(text: string): boolean {\n\tfor (let i = 0; i < text.length; i++)\n\t\tif (text.charCodeAt(i) > 0x7f) return true;\n\treturn false;\n}\n\n/** `MAIL FROM:<path> [SIZE=] [BODY=] [SMTPUTF8] [AUTH=]` (RFC 5321 §4.1.1.2). */\nexport async function mail(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tif (state.helo === undefined)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Send EHLO first'));\n\tif (state.transaction.from !== undefined) {\n\t\treturn connection.fail(reply(503, '5.5.1', 'Nested MAIL command'));\n\t}\n\tif (settings.mode === 'submission' && state.user === undefined) {\n\t\treturn connection.fail(reply(530, '5.7.0', 'Authentication required'));\n\t}\n\tconst command = parsePathCommand(argument, 'FROM');\n\tif (!command)\n\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: MAIL FROM:<address>'));\n\tconst { path, parameters } = command;\n\tlet body: '7BIT' | '8BITMIME' = '7BIT';\n\tlet smtputf8 = false;\n\tfor (const [key, value] of Object.entries(parameters)) {\n\t\tif (!state.esmtp)\n\t\t\treturn connection.fail(reply(555, '5.5.4', `${key} needs EHLO`));\n\t\tif (key === 'SIZE') {\n\t\t\tif (!/^\\d+$/.test(value))\n\t\t\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: SIZE=<bytes>'));\n\t\t\tif (Number(value) > settings.maxMessageSize) {\n\t\t\t\treturn connection.fail(\n\t\t\t\t\treply(552, '5.3.4', 'Message too big for system'),\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (key === 'BODY') {\n\t\t\tconst kind = value.toUpperCase();\n\t\t\tif (kind !== '7BIT' && kind !== '8BITMIME') {\n\t\t\t\treturn connection.fail(reply(501, '5.5.4', 'BODY is 7BIT or 8BITMIME'));\n\t\t\t}\n\t\t\tbody = kind;\n\t\t} else if (key === 'SMTPUTF8' && value === '') {\n\t\t\tsmtputf8 = true;\n\t\t} else if (key === 'AUTH') {\n\t\t\t// RFC 4954 §5: the original submitter; taken and not passed on.\n\t\t} else {\n\t\t\treturn connection.fail(reply(555, '5.5.4', `${key} is not supported`));\n\t\t}\n\t}\n\tif (!smtputf8 && nonAscii(path.address)) {\n\t\treturn connection.fail(\n\t\t\treply(553, '5.6.7', 'A non-ASCII address needs SMTPUTF8'),\n\t\t);\n\t}\n\tconst options = settings.options;\n\tconst refused = options.onMailFrom\n\t\t? await connection.hook('onMailFrom', () =>\n\t\t\t\toptions.onMailFrom?.(path, connection.session),\n\t\t\t)\n\t\t: undefined;\n\tif (refused) return connection.send(refused);\n\tstate.transaction = { from: path.address, to: [], smtputf8, body };\n\tconnection.send(reply(250, '2.1.0', 'OK'));\n}\n\n/** `RCPT TO:<path>` (RFC 5321 §4.1.1.3), where relaying is refused without AUTH. */\nexport async function rcpt(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tif (state.transaction.from === undefined)\n\t\treturn connection.fail(reply(503, '5.5.1', 'Send MAIL first'));\n\tconst command = parsePathCommand(argument, 'TO');\n\tif (!command)\n\t\treturn connection.fail(reply(501, '5.5.4', 'Syntax: RCPT TO:<address>'));\n\tconst { path, parameters } = command;\n\tif (Object.keys(parameters).length > 0) {\n\t\treturn connection.fail(\n\t\t\treply(555, '5.5.4', `${Object.keys(parameters)[0]} is not supported`),\n\t\t);\n\t}\n\tif (!state.transaction.smtputf8 && nonAscii(path.address)) {\n\t\treturn connection.fail(\n\t\t\treply(553, '5.6.7', 'A non-ASCII address needs SMTPUTF8'),\n\t\t);\n\t}\n\tif (state.transaction.to.length >= settings.maxRecipients) {\n\t\treturn connection.send(reply(452, '4.5.3', 'Too many recipients'));\n\t}\n\t// Never an open relay: a domain this server does not host takes AUTH.\n\t// `<postmaster>` with no domain is this server's own (RFC 5321 §4.5.1).\n\tif (state.user === undefined && path.postmaster !== true) {\n\t\tconst local = await connection.check('localDomains', () =>\n\t\t\tsettings.isLocal(path.domain),\n\t\t);\n\t\tif (local.failed) return connection.send(LOCAL_ERROR);\n\t\tif (local.value !== true) {\n\t\t\treturn connection.fail(reply(554, '5.7.1', 'Relay access denied'));\n\t\t}\n\t}\n\tconst options = settings.options;\n\tconst refused = options.onRcptTo\n\t\t? await connection.hook('onRcptTo', () =>\n\t\t\t\toptions.onRcptTo?.(path, connection.session),\n\t\t\t)\n\t\t: undefined;\n\tif (refused) return connection.send(refused);\n\tstate.transaction.to.push(path.address);\n\tconnection.send(reply(250, '2.1.5', 'OK'));\n}\n",
12
13
  "import { parseCommand } from '../protocol/command';\nimport { isHelloName } from '../protocol/path';\nimport { reply } from '../protocol/reply';\nimport { authenticate, continueAuth } from './auth';\nimport type { Connection } from './connection';\nimport { emptyTransaction } from './state';\nimport { mail, rcpt } from './transaction';\n\nfunction ehloLines(connection: Connection): string[] {\n\tconst { settings, state } = connection;\n\tconst lines = [\n\t\t`${settings.options.hostname} greets ${state.helo}`,\n\t\t'PIPELINING',\n\t\t`SIZE ${settings.maxMessageSize}`,\n\t\t'8BITMIME',\n\t\t'SMTPUTF8',\n\t\t'ENHANCEDSTATUSCODES',\n\t];\n\tif (settings.options.tls && !state.secure) lines.push('STARTTLS');\n\tif (\n\t\tsettings.options.authenticate &&\n\t\tstate.secure &&\n\t\tstate.user === undefined\n\t) {\n\t\tlines.push('AUTH PLAIN LOGIN');\n\t}\n\treturn lines;\n}\n\nasync function hello(\n\tconnection: Connection,\n\targument: string,\n\tesmtp: boolean,\n): Promise<void> {\n\tif (!isHelloName(argument)) {\n\t\tconnection.fail(\n\t\t\treply(501, '5.5.4', `Syntax: ${esmtp ? 'EHLO' : 'HELO'} hostname`),\n\t\t);\n\t\treturn;\n\t}\n\tconst { state } = connection;\n\tstate.helo = argument;\n\tstate.esmtp = esmtp;\n\t// RFC 5321 §4.1.4: EHLO or HELO resets a transaction in progress.\n\tstate.transaction = emptyTransaction();\n\tconnection.send(\n\t\tesmtp\n\t\t\t? reply(250, undefined, ehloLines(connection))\n\t\t\t: reply(\n\t\t\t\t\t250,\n\t\t\t\t\tundefined,\n\t\t\t\t\t`${connection.settings.options.hostname} greets ${argument}`,\n\t\t\t\t),\n\t);\n}\n\nfunction data(connection: Connection, argument: string): void {\n\tconst { state } = connection;\n\tconst refusal =\n\t\targument !== ''\n\t\t\t? reply(501, '5.5.4', 'Syntax: DATA')\n\t\t\t: state.transaction.from === undefined\n\t\t\t\t? reply(503, '5.5.1', 'Send MAIL first')\n\t\t\t\t: state.transaction.to.length === 0\n\t\t\t\t\t? reply(554, '5.5.1', 'No valid recipients')\n\t\t\t\t\t: undefined;\n\tif (refusal) {\n\t\tconnection.fail(refusal);\n\t\t// What the client pipelined after a refused DATA is message content,\n\t\t// not commands: running it would let a message smuggle commands in.\n\t\tconnection.input.drop();\n\t\treturn;\n\t}\n\tconnection.send(reply(354, undefined, 'End data with <CR><LF>.<CR><LF>'));\n\tconnection.input.beginData();\n}\n\nasync function startTls(\n\tconnection: Connection,\n\targument: string,\n): Promise<void> {\n\tconst { state, settings } = connection;\n\tconst refusal = !settings.options.tls\n\t\t? reply(454, '4.7.0', 'TLS not available')\n\t\t: state.secure\n\t\t\t? reply(503, '5.5.1', 'TLS already active')\n\t\t\t: argument !== ''\n\t\t\t\t? reply(501, '5.5.4', 'Syntax: STARTTLS')\n\t\t\t\t: undefined;\n\tif (refusal) {\n\t\tconnection.fail(refusal);\n\t\treturn;\n\t}\n\tconnection.send(reply(220, '2.0.0', 'Ready to start TLS'));\n\tconnection.input.ignore();\n\t// The 220 must reach the client in clear before the handshake starts.\n\tawait connection.transport.drained();\n\tif (connection.closed) return;\n\tconnection.transport.startTls();\n\tconnection.input.accept();\n\t// RFC 3207 §4.2: everything learnt before TLS is forgotten.\n\tstate.secure = true;\n\tstate.helo = undefined;\n\tstate.esmtp = false;\n\tstate.transaction = emptyTransaction();\n}\n\n/** Runs one command line, or the client's answer to an AUTH challenge. */\nexport async function runCommand(\n\tconnection: Connection,\n\tline: string,\n): Promise<void> {\n\tconst { state } = connection;\n\tif (state.waiting !== 'command') return continueAuth(connection, line);\n\tconst { verb, argument } = parseCommand(line);\n\tswitch (verb) {\n\t\tcase 'EHLO':\n\t\t\treturn hello(connection, argument, true);\n\t\tcase 'HELO':\n\t\t\treturn hello(connection, argument, false);\n\t\tcase 'MAIL':\n\t\t\treturn mail(connection, argument);\n\t\tcase 'RCPT':\n\t\t\treturn rcpt(connection, argument);\n\t\tcase 'DATA':\n\t\t\treturn data(connection, argument);\n\t\tcase 'RSET':\n\t\t\tstate.transaction = emptyTransaction();\n\t\t\treturn connection.send(reply(250, '2.0.0', 'OK'));\n\t\tcase 'NOOP':\n\t\t\treturn connection.send(reply(250, '2.0.0', 'OK'));\n\t\tcase 'VRFY':\n\t\t\treturn connection.send(\n\t\t\t\treply(\n\t\t\t\t\t252,\n\t\t\t\t\t'2.5.0',\n\t\t\t\t\t'Cannot VRFY user; send the message and it will be tried',\n\t\t\t\t),\n\t\t\t);\n\t\tcase 'HELP':\n\t\t\treturn connection.send(reply(214, '2.0.0', 'See RFC 5321'));\n\t\tcase 'QUIT':\n\t\t\treturn connection.quit(\n\t\t\t\treply(\n\t\t\t\t\t221,\n\t\t\t\t\t'2.0.0',\n\t\t\t\t\t`${connection.settings.options.hostname} closing connection`,\n\t\t\t\t),\n\t\t\t);\n\t\tcase 'STARTTLS':\n\t\t\treturn startTls(connection, argument);\n\t\tcase 'AUTH':\n\t\t\treturn authenticate(connection, argument);\n\t\tdefault:\n\t\t\treturn connection.fail(reply(500, '5.5.2', 'Command unrecognized'));\n\t}\n}\n",
13
- "import type { Connection } from './connection';\n\nconst DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst MONTHS = [\n\t'Jan',\n\t'Feb',\n\t'Mar',\n\t'Apr',\n\t'May',\n\t'Jun',\n\t'Jul',\n\t'Aug',\n\t'Sep',\n\t'Oct',\n\t'Nov',\n\t'Dec',\n];\n\nconst two = (n: number) => String(n).padStart(2, '0');\n\n/** An RFC 5322 §3.3 date-time, in UTC. */\nexport function dateTime(date: Date): string {\n\treturn `${DAYS[date.getUTCDay()]}, ${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()} ${two(date.getUTCHours())}:${two(date.getUTCMinutes())}:${two(date.getUTCSeconds())} +0000`;\n}\n\n/** RFC 3848: how the message came — SMTP, ESMTP, then S for TLS and A for AUTH. */\nexport function protocolOf(\n\tesmtp: boolean,\n\tsecure: boolean,\n\tauthenticated: boolean,\n): string {\n\tif (!esmtp) return 'SMTP';\n\treturn `ESMTP${secure ? 'S' : ''}${authenticated ? 'A' : ''}`;\n}\n\n/** Keeps a client-given name printable in a header: anything else becomes `?`. */\nfunction printable(text: string): string {\n\tlet out = '';\n\tfor (const char of text) {\n\t\tconst code = char.charCodeAt(0);\n\t\tout += code > 0x20 && code < 0x7f ? char : '?';\n\t}\n\treturn out;\n}\n\n/** Whether an address can go into the `for` clause as it is: printable, and no `;` to end the clause early. */\nfunction plain(address: string): boolean {\n\treturn printable(address) === address && !address.includes(';');\n}\n\n/**\n * The Received field the server puts on top (RFC 5321 §4.4): who sent the\n * message, from where, how, to whom when there is one recipient, and when.\n */\nexport function receivedField(\n\tconnection: Connection,\n\trecipients: readonly string[],\n\tid: string,\n\tnow = new Date(),\n): string {\n\tconst { state, transport, settings } = connection;\n\tconst lines = [\n\t\t`Received: from ${printable(state.helo ?? 'unknown')} ([${printable(transport.remoteAddress)}])`,\n\t\t`\\tby ${settings.options.hostname} with ${protocolOf(state.esmtp, state.secure, state.user !== undefined)} id ${id}`,\n\t];\n\tconst [recipient] = recipients;\n\tif (recipients.length === 1 && recipient !== undefined && plain(recipient)) {\n\t\tlines.push(`\\tfor <${recipient}>`);\n\t}\n\tlines[lines.length - 1] += `; ${dateTime(now)}`;\n\treturn `${lines.join('\\r\\n')}\\r\\n`;\n}\n",
14
+ "import { isIPv6 } from 'node:net';\nimport type { Connection } from './connection';\n\nconst DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst MONTHS = [\n\t'Jan',\n\t'Feb',\n\t'Mar',\n\t'Apr',\n\t'May',\n\t'Jun',\n\t'Jul',\n\t'Aug',\n\t'Sep',\n\t'Oct',\n\t'Nov',\n\t'Dec',\n];\n\nconst two = (n: number) => String(n).padStart(2, '0');\n\n/** An RFC 5322 §3.3 date-time, in UTC. */\nexport function dateTime(date: Date): string {\n\treturn `${DAYS[date.getUTCDay()]}, ${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()} ${two(date.getUTCHours())}:${two(date.getUTCMinutes())}:${two(date.getUTCSeconds())} +0000`;\n}\n\n/** RFC 3848: how the message came — SMTP, ESMTP, then S for TLS and A for AUTH. */\nexport function protocolOf(\n\tesmtp: boolean,\n\tsecure: boolean,\n\tauthenticated: boolean,\n): string {\n\tif (!esmtp) return 'SMTP';\n\treturn `ESMTP${secure ? 'S' : ''}${authenticated ? 'A' : ''}`;\n}\n\n/** The client's address as a domain literal (RFC 5321 §4.1.3): an IPv6 address is tagged `IPv6:`. */\nexport function addressLiteral(address: string): string {\n\t// A zone (`fe80::1%en0`) names an interface of this host: not part of the literal.\n\tconst bare = address.replace(/%.*$/, '');\n\treturn isIPv6(bare) ? `IPv6:${bare}` : printable(address);\n}\n\n/** Keeps a client-given name printable in a header: anything else becomes `?`. */\nfunction printable(text: string): string {\n\tlet out = '';\n\tfor (const char of text) {\n\t\tconst code = char.charCodeAt(0);\n\t\tout += code > 0x20 && code < 0x7f ? char : '?';\n\t}\n\treturn out;\n}\n\n/** Whether an address can go into the `for` clause as it is: printable, and no `;` to end the clause early. */\nfunction plain(address: string): boolean {\n\treturn printable(address) === address && !address.includes(';');\n}\n\n/**\n * The Received field the server puts on top (RFC 5321 §4.4): who sent the\n * message, from where, how, to whom when there is one recipient, and when.\n */\nexport function receivedField(\n\tconnection: Connection,\n\trecipients: readonly string[],\n\tid: string,\n\tnow = new Date(),\n): string {\n\tconst { state, transport, settings } = connection;\n\tconst lines = [\n\t\t`Received: from ${printable(state.helo ?? 'unknown')} ([${addressLiteral(transport.remoteAddress)}])`,\n\t\t`\\tby ${settings.options.hostname} with ${protocolOf(state.esmtp, state.secure, state.user !== undefined)} id ${id}`,\n\t];\n\tconst [recipient] = recipients;\n\tif (recipients.length === 1 && recipient !== undefined && plain(recipient)) {\n\t\tlines.push(`\\tfor <${recipient}>`);\n\t}\n\tlines[lines.length - 1] += `; ${dateTime(now)}`;\n\treturn `${lines.join('\\r\\n')}\\r\\n`;\n}\n",
14
15
  "import { SmtpError } from '../errors';\nimport { reply } from '../protocol/reply';\n\n/** Why a message on its way in is refused, as the reply and the error `onData` and `onError` see. */\n\nexport const TOO_BIG = reply(552, '5.3.4', 'Message too big for system');\n\nexport const BARE_LINE_BREAK = reply(\n\t550,\n\t'5.6.11',\n\t'Bare CR or LF is not allowed in a message',\n);\n\nexport function tooBig(maxMessageSize: number): SmtpError {\n\treturn new SmtpError(\n\t\t'MESSAGE_TOO_BIG',\n\t\t`The message is larger than maxMessageSize (${maxMessageSize} bytes); do not deliver it`,\n\t);\n}\n\n/** A bare CR or LF is how SMTP smuggling hides a second message. */\nexport function bareLineBreak(): SmtpError {\n\treturn new SmtpError(\n\t\t'BARE_LINE_BREAK',\n\t\t'The message holds a bare CR or LF (SMTP smuggling); do not deliver it',\n\t);\n}\n\n/**\n * The connection closed mid-message, or after its end but before the reply:\n * the client hung up, or the server closed it (idle timeout, socket error).\n */\nexport function connectionLost(ended: boolean): SmtpError {\n\treturn new SmtpError(\n\t\t'CONNECTION_LOST',\n\t\tended\n\t\t\t? 'The connection closed before the reply to the message; do not deliver it'\n\t\t\t: 'The connection closed before the end of the message; do not deliver it',\n\t);\n}\n\nexport function notAnswered(seconds: number): SmtpError {\n\treturn new SmtpError(\n\t\t'HOOK_TIMEOUT',\n\t\t`onData did not answer within hookTimeout (${seconds} s); do not deliver it`,\n\t);\n}\n\nexport function notReadInTime(seconds: number): SmtpError {\n\treturn new SmtpError(\n\t\t'HOOK_TIMEOUT',\n\t\t`onData did not read the message within hookTimeout (${seconds} s); do not deliver it`,\n\t);\n}\n\nexport function notRead(): SmtpError {\n\treturn new SmtpError(\n\t\t'MESSAGE_NOT_READ',\n\t\t'onData answered without reading the message to its end; it was not taken',\n\t);\n}\n",
15
16
  "import type { SmtpError } from '../errors';\nimport { DataReader } from '../protocol/data';\nimport { type Reply, reply } from '../protocol/reply';\nimport type { Connection } from './connection';\nimport { hookTimeout, LOCAL_ERROR, refusalOf, timedOut, within } from './guard';\nimport type { ReceivedMessage } from './options';\nimport { receivedField } from './received';\nimport {\n\tBARE_LINE_BREAK,\n\tbareLineBreak,\n\tconnectionLost,\n\tnotAnswered,\n\tnotRead,\n\tnotReadInTime,\n\tTOO_BIG,\n\ttooBig,\n} from './refusals';\nimport type { Transaction } from './state';\n\n/** Bytes of message held for `onData` before the server stops reading the client. */\nconst HIGH_WATER_MARK = 64 * 1024;\n\n/**\n * One message on its way in: the content of DATA, unstuffed, fed to\n * `onData` as a stream while the client sends it. At most\n * `HIGH_WATER_MARK` bytes wait to be read; past that the server waits for\n * `onData` to read, and so stops reading the client.\n *\n * The stream ends in an `SmtpError` when the message must not be\n * delivered, and the reply to DATA is then that refusal, whatever `onData`\n * answered. The 250 goes out only when `onData` read the stream to its\n * clean end and accepted; a stream left unread errors with\n * `MESSAGE_NOT_READ`. When the message's `signal` aborts is set out on\n * `ReceivedMessage.signal`.\n */\nexport class Intake {\n\treadonly id = crypto.getRandomValues(new Uint8Array(10)).toHex();\n\treadonly #connection: Connection;\n\treadonly #reader = new DataReader();\n\t#controller!: ReadableStreamDefaultController<Uint8Array>;\n\t/** What waits for `onData` to pull. */\n\t#queue: Uint8Array[] = [];\n\t#queued = 0;\n\t/** The end of DATA came, cleanly. */\n\t#ended = false;\n\t/** `onData` pulled the last byte and saw the stream close. */\n\t#read = false;\n\t#state: 'open' | 'closed' | 'errored' | 'cancelled' = 'open';\n\t#failure: Reply | undefined;\n\t#wakers: (() => void)[] = [];\n\treadonly #delivery: Promise<Reply | undefined>;\n\t/** Whether `onData` had read to the end when it answered. */\n\t#readWhenAnswered = false;\n\t/** Aborts when the server refuses the message after `onData` had it. */\n\treadonly #refusal = new AbortController();\n\n\tconstructor(connection: Connection, transaction: Transaction) {\n\t\tthis.#connection = connection;\n\t\t// High-water mark 0: a byte leaves the queue only when onData asks\n\t\t// for it, so the server knows whether it read to the end.\n\t\tconst content = new ReadableStream<Uint8Array>(\n\t\t\t{\n\t\t\t\tstart: (controller) => {\n\t\t\t\t\tthis.#controller = controller;\n\t\t\t\t},\n\t\t\t\tpull: (controller) => this.#pull(controller),\n\t\t\t\tcancel: () => {\n\t\t\t\t\tif (this.#state === 'open') this.#state = 'cancelled';\n\t\t\t\t\tthis.#queue = [];\n\t\t\t\t\tthis.#queued = 0;\n\t\t\t\t\tthis.#wake();\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ highWaterMark: 0 },\n\t\t);\n\t\tthis.#push(\n\t\t\tnew TextEncoder().encode(\n\t\t\t\treceivedField(connection, transaction.to, this.id),\n\t\t\t),\n\t\t);\n\t\tconst message: ReceivedMessage = {\n\t\t\tid: this.id,\n\t\t\tenvelope: {\n\t\t\t\tfrom: transaction.from ?? '',\n\t\t\t\tto: [...transaction.to],\n\t\t\t\tsmtputf8: transaction.smtputf8,\n\t\t\t\tbody: transaction.body,\n\t\t\t},\n\t\t\tcontent,\n\t\t\tsignal: this.#refusal.signal,\n\t\t};\n\t\tthis.#delivery = this.#deliver(message);\n\t}\n\n\t/**\n\t * `onData`'s answer as the reply: `undefined`, its refusal, or 451 when\n\t * it threw or answered what is not a refusal — which also aborts the\n\t * signal, since the message was not taken.\n\t */\n\tasync #deliver(message: ReceivedMessage): Promise<Reply | undefined> {\n\t\tconst connection = this.#connection;\n\t\t/** onData refused the message itself, with a valid 4xx or 5xx reply. */\n\t\tlet ownRefusal = false;\n\t\tconst refuse = (error: unknown) => {\n\t\t\tthis.#refusal.abort(error);\n\t\t\tconnection.report(error);\n\t\t};\n\t\ttry {\n\t\t\t// Keeps onData starting after Input has set up the transaction, as\n\t\t\t// connection.hook did; nothing observable depends on it today.\n\t\t\tawait Promise.resolve();\n\t\t\tconst answer = await connection.settings.options.onData(\n\t\t\t\tmessage,\n\t\t\t\tconnection.session,\n\t\t\t);\n\t\t\tconst refusal = refusalOf('onData', answer, refuse);\n\t\t\townRefusal = refusal !== undefined && refusal === answer;\n\t\t\treturn refusal;\n\t\t} catch (error) {\n\t\t\trefuse(error);\n\t\t\treturn LOCAL_ERROR;\n\t\t} finally {\n\t\t\tthis.#readWhenAnswered = this.#read;\n\t\t\t// Answered before the end: a reader left running must not reach a\n\t\t\t// clean end. The signal aborts only if the server refuses for it.\n\t\t\tif (!this.#read) this.#stop(!ownRefusal);\n\t\t\tthis.#wake();\n\t\t}\n\t}\n\n\t/** A chunk of DATA; resolves once there is room for the next. */\n\tasync write(chunk: Uint8Array): Promise<{ done: boolean; rest: Uint8Array }> {\n\t\tconst { data, done, rest } = this.#reader.write(chunk);\n\t\tconst { maxMessageSize } = this.#connection.settings;\n\t\tif (this.#failure) return { done, rest };\n\t\tif (this.#reader.size > maxMessageSize) {\n\t\t\tthis.#fail(TOO_BIG, tooBig(maxMessageSize));\n\t\t} else if (this.#reader.bareLineBreaks > 0) {\n\t\t\t// A bare CR or LF is how SMTP smuggling hides a second message.\n\t\t\tthis.#fail(BARE_LINE_BREAK, bareLineBreak());\n\t\t} else if (this.#state === 'open' && data.length > 0) {\n\t\t\tthis.#push(data);\n\t\t\tawait this.#room();\n\t\t}\n\t\treturn { done, rest };\n\t}\n\n\t/** The end of DATA: the reply to send. */\n\tasync finish(): Promise<Reply> {\n\t\tif (this.#failure) return this.#failure;\n\t\tthis.#ended = true;\n\t\tthis.#wake();\n\t\tconst { hookTimeout: seconds } = this.#connection.settings;\n\t\tconst answer = await within(this.#delivery, seconds);\n\t\tif (timedOut(answer)) {\n\t\t\tthis.#connection.report(hookTimeout('onData', seconds));\n\t\t\t// The client is told 451 and will try again: a late read must not\n\t\t\t// take it, and a read already finished learns it through the signal.\n\t\t\tthis.#fail(LOCAL_ERROR, notAnswered(seconds));\n\t\t\treturn LOCAL_ERROR;\n\t\t}\n\t\tif (answer) return answer;\n\t\tif (!this.#readWhenAnswered) {\n\t\t\tconst error = notRead();\n\t\t\tthis.#refusal.abort(error);\n\t\t\tthis.#connection.report(error);\n\t\t\treturn LOCAL_ERROR;\n\t\t}\n\t\treturn reply(250, '2.0.0', `OK queued as ${this.id}`);\n\t}\n\n\t/** The connection closed, mid-message or before the reply was sent. */\n\tabort(): void {\n\t\tthis.#fail(LOCAL_ERROR, connectionLost(this.#ended));\n\t}\n\n\t#push(bytes: Uint8Array): void {\n\t\tthis.#queue.push(bytes);\n\t\tthis.#queued += bytes.length;\n\t\tthis.#wake();\n\t}\n\n\t/** onData asks for more: the next chunk, the end, or a wait for either. */\n\tasync #pull(\n\t\tcontroller: ReadableStreamDefaultController<Uint8Array>,\n\t): Promise<void> {\n\t\tfor (;;) {\n\t\t\tif (this.#state !== 'open') return;\n\t\t\tconst next = this.#queue.shift();\n\t\t\tif (next) {\n\t\t\t\tthis.#queued -= next.length;\n\t\t\t\tcontroller.enqueue(next);\n\t\t\t\tthis.#wake();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (this.#ended) {\n\t\t\t\tthis.#read = true;\n\t\t\t\tthis.#state = 'closed';\n\t\t\t\tcontroller.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait new Promise<void>((wake) => this.#wakers.push(wake));\n\t\t}\n\t}\n\n\t/**\n\t * onData answered without reading to the end: the stream errors, and\n\t * takes no more. The signal aborts too, unless onData refused itself.\n\t */\n\t#stop(abortSignal: boolean): void {\n\t\tif (this.#state !== 'open') return;\n\t\tconst error = notRead();\n\t\tif (abortSignal) this.#refusal.abort(error);\n\t\tthis.#controller.error(error);\n\t\tthis.#state = 'cancelled';\n\t\tthis.#queue = [];\n\t\tthis.#queued = 0;\n\t}\n\n\t#fail(answer: Reply, error: SmtpError): void {\n\t\tthis.#failure ??= answer;\n\t\tthis.#refusal.abort(error);\n\t\tif (this.#state === 'open') this.#controller.error(error);\n\t\tthis.#state = 'errored';\n\t\tthis.#queue = [];\n\t\tthis.#queued = 0;\n\t\tthis.#wake();\n\t}\n\n\t/** Waits while the queue is full; gives up on an `onData` that stopped reading. */\n\tasync #room(): Promise<void> {\n\t\tconst { hookTimeout: seconds } = this.#connection.settings;\n\t\twhile (this.#state === 'open' && this.#queued > HIGH_WATER_MARK) {\n\t\t\tconst woken = await within(\n\t\t\t\tnew Promise<void>((wake) => this.#wakers.push(wake)),\n\t\t\t\tseconds,\n\t\t\t);\n\t\t\tif (timedOut(woken)) {\n\t\t\t\tthis.#connection.report(hookTimeout('onData', seconds));\n\t\t\t\tthis.#fail(LOCAL_ERROR, notReadInTime(seconds));\n\t\t\t}\n\t\t}\n\t}\n\n\t#wake(): void {\n\t\tfor (const wake of this.#wakers.splice(0)) wake();\n\t}\n}\n",
16
17
  "import { LineSplitter } from '../protocol/lines';\nimport { reply } from '../protocol/reply';\nimport { runCommand } from './commands';\nimport type { Connection } from './connection';\nimport { Intake } from './intake';\nimport { emptyTransaction } from './state';\n\n/** Bytes waiting to be read past which the server stops reading the client. */\nconst INPUT_LIMIT = 64 * 1024;\n\n/**\n * What a client sends, read in order: command lines one at a time, each\n * answered before the next runs, and the message after DATA. It holds a\n * bounded amount: past `INPUT_LIMIT` waiting bytes it pauses the socket,\n * and it waits for the replies to leave before reading on.\n */\nexport class Input {\n\treadonly #connection: Connection;\n\t#input: Uint8Array[] = [];\n\t#queued = 0;\n\t#paused = false;\n\treadonly #lines = new LineSplitter();\n\t#intake: Intake | undefined;\n\t/** A message whole, while `onData` answers it and before the reply is sent. */\n\t#answering: Intake | undefined;\n\t/** The work in progress on what the client sent; settled when all of it is answered. */\n\t#pumping: Promise<void> | undefined;\n\t/** The 220 went out: input before it breaks RFC 5321 §4.3.1. */\n\t#greeted = false;\n\t/** The client talked before the greeting. */\n\tearly = false;\n\t/** Set while the 220 to STARTTLS leaves: clear text then is never read. */\n\t#ignoring = false;\n\t/** Set by `drop`: the line loop drops what it still holds. */\n\t#dropped = false;\n\n\tconstructor(connection: Connection) {\n\t\tthis.#connection = connection;\n\t}\n\n\tgreeted(): void {\n\t\tthis.#greeted = true;\n\t}\n\n\treceive(chunk: Uint8Array): void {\n\t\tif (this.#ignoring) return;\n\t\tif (!this.#greeted) {\n\t\t\tthis.early = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.#input.push(chunk.slice());\n\t\tthis.#queued += chunk.length;\n\t\tif (this.#queued > INPUT_LIMIT && !this.#paused) {\n\t\t\tthis.#paused = true;\n\t\t\tthis.#connection.transport.pause();\n\t\t}\n\t\tthis.#kick();\n\t}\n\n\t/** The connection closed: a message on its way in must not be delivered. */\n\tabort(): void {\n\t\tthis.#intake?.abort();\n\t\tthis.#intake = undefined;\n\t\t// The connection closed before the reply, so the client will send the\n\t\t// message again: onData learns it through the signal.\n\t\tthis.#answering?.abort();\n\t\tthis.#answering = undefined;\n\t}\n\n\t/**\n\t * Forgets what the client sent ahead and reads nothing until `accept`:\n\t * what comes in clear before TLS never counts (RFC 3207 §4.2,\n\t * CVE-2011-0411).\n\t */\n\tignore(): void {\n\t\tthis.drop();\n\t\tthis.#input = [];\n\t\tthis.#queued = 0;\n\t\tthis.#ignoring = true;\n\t\tthis.#resume();\n\t}\n\n\taccept(): void {\n\t\tthis.#ignoring = false;\n\t}\n\n\t/** Drops the rest of the chunk being read: after a refused DATA, it is message content, not commands. */\n\tdrop(): void {\n\t\tthis.#lines.clear();\n\t\tthis.#dropped = true;\n\t}\n\n\t/** Starts receiving a message: `onData` is called, and gets it as it comes. */\n\tbeginData(): void {\n\t\tconst connection = this.#connection;\n\t\tthis.#intake = new Intake(connection, connection.state.transaction);\n\t\tconnection.state.waiting = 'data';\n\t}\n\n\t/** Resolves once everything received so far is answered. */\n\tasync idle(): Promise<void> {\n\t\twhile (this.#pumping) await this.#pumping;\n\t}\n\n\t#kick(): void {\n\t\tif (this.#pumping) return;\n\t\tconst connection = this.#connection;\n\t\tthis.#pumping = this.#pump()\n\t\t\t.catch((error) => {\n\t\t\t\tconnection.report(error);\n\t\t\t\tconnection.close(reply(421, '4.3.0', 'Local error, closing'));\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.#pumping = undefined;\n\t\t\t\t// Bytes that came after the loop's last look.\n\t\t\t\tif (!connection.closed && this.#input.length > 0) this.#kick();\n\t\t\t});\n\t}\n\n\t#resume(): void {\n\t\tif (this.#paused && this.#queued <= INPUT_LIMIT / 2) {\n\t\t\tthis.#paused = false;\n\t\t\tthis.#connection.transport.resume();\n\t\t}\n\t}\n\n\tasync #pump(): Promise<void> {\n\t\twhile (!this.#connection.closed && this.#input.length > 0) {\n\t\t\tconst chunk = this.#input.shift() as Uint8Array;\n\t\t\tthis.#queued -= chunk.length;\n\t\t\tthis.#resume();\n\t\t\tif (this.#connection.state.waiting === 'data') await this.#data(chunk);\n\t\t\telse await this.#commands(chunk);\n\t\t}\n\t}\n\n\tasync #commands(chunk: Uint8Array): Promise<void> {\n\t\tthis.#lines.push(chunk);\n\t\twhile (!this.#connection.closed) {\n\t\t\t// The replies so far leave before the next command runs.\n\t\t\tawait this.#connection.transport.drained();\n\t\t\tconst event = this.#lines.next();\n\t\t\tif (!event) return;\n\t\t\tif (!('line' in event)) {\n\t\t\t\tthis.#connection.fail(reply(500, '5.5.6', 'Line too long'));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#dropped = false;\n\t\t\tawait runCommand(this.#connection, event.line);\n\t\t\tif (this.#dropped) return;\n\t\t\tif (this.#connection.state.waiting === 'data') {\n\t\t\t\t// Message content pipelined right after DATA.\n\t\t\t\tconst rest = this.#lines.takeRest();\n\t\t\t\tif (rest.length > 0) this.#unshift(rest.slice());\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync #data(chunk: Uint8Array): Promise<void> {\n\t\tconst intake = this.#intake as Intake;\n\t\tconst { done, rest } = await intake.write(chunk);\n\t\tif (!done || this.#connection.closed) return;\n\t\tthis.#intake = undefined;\n\t\tthis.#answering = intake;\n\t\tthis.#connection.state.waiting = 'command';\n\t\tthis.#connection.state.transaction = emptyTransaction();\n\t\tconst answer = await intake.finish();\n\t\tthis.#answering = undefined;\n\t\tthis.#connection.send(answer);\n\t\tif (rest.length > 0) this.#unshift(rest);\n\t}\n\n\t/** Puts bytes back at the front, counted again: the pump took them off the count. */\n\t#unshift(bytes: Uint8Array): void {\n\t\tthis.#input.unshift(bytes);\n\t\tthis.#queued += bytes.length;\n\t\tif (this.#queued > INPUT_LIMIT && !this.#paused) {\n\t\t\tthis.#paused = true;\n\t\t\tthis.#connection.transport.pause();\n\t\t}\n\t}\n}\n",
17
18
  "import { formatReply, type Reply, reply } from '../protocol/reply';\nimport { hookTimeout, LOCAL_ERROR, refusalOf, timedOut, within } from './guard';\nimport { Input } from './input';\nimport type { HookResult, Session } from './options';\nimport type { Settings } from './settings';\nimport { emptyTransaction, type State } from './state';\nimport type { Transport } from './transport';\n\n/**\n * One SMTP session (RFC 5321): reads commands, one at a time and in order —\n * PIPELINING sends several at once, and each reply waits for the hooks of\n * the commands before it — and the message after DATA.\n */\nexport class Connection {\n\treadonly settings: Settings;\n\t#transport: Transport;\n\treadonly id = crypto.getRandomValues(new Uint8Array(8)).toHex();\n\treadonly data: Record<string, unknown> = {};\n\treadonly state: State;\n\t/** What the client sends: commands, then message content after DATA. */\n\treadonly input: Input = new Input(this);\n\t#closed = false;\n\n\tconstructor(settings: Settings, transport: Transport) {\n\t\tthis.settings = settings;\n\t\tthis.#transport = transport;\n\t\tthis.state = {\n\t\t\tesmtp: false,\n\t\t\tsecure: transport.secure,\n\t\t\ttransaction: emptyTransaction(),\n\t\t\twaiting: 'command',\n\t\t\terrors: 0,\n\t\t\tauthFailures: 0,\n\t\t};\n\t}\n\n\tget transport(): Transport {\n\t\treturn this.#transport;\n\t}\n\n\t/** After STARTTLS: writes and hang-ups go through the encrypted socket. */\n\tuseTransport(transport: Transport): void {\n\t\tthis.#transport = transport;\n\t}\n\n\tget session(): Session {\n\t\tconst { helo, user } = this.state;\n\t\treturn {\n\t\t\tid: this.id,\n\t\t\tremoteAddress: this.transport.remoteAddress,\n\t\t\tsecure: this.state.secure,\n\t\t\tesmtp: this.state.esmtp,\n\t\t\t...(helo === undefined ? {} : { helo }),\n\t\t\t...(user === undefined ? {} : { user }),\n\t\t\tdata: this.data,\n\t\t};\n\t}\n\n\tget closed(): boolean {\n\t\treturn this.#closed;\n\t}\n\n\tsend(answer: Reply): void {\n\t\tif (this.#closed) return;\n\t\tthis.transport.write(formatReply(answer, this.state.esmtp));\n\t}\n\n\t/**\n\t * Hangs up, the server's decision (a refusal, too many errors, the idle\n\t * time): `answer` is written, but nothing waits for a client that\n\t * stopped reading. The connection is closed at once, and what it has\n\t * not read is dropped, so a close always completes.\n\t */\n\tclose(answer?: Reply): void {\n\t\tif (this.#closed) return;\n\t\tif (answer) this.send(answer);\n\t\tthis.#closed = true;\n\t\tthis.input.abort();\n\t\tthis.transport.abort();\n\t}\n\n\t/** QUIT: `answer` leaves whole, then the connection hangs up. */\n\tquit(answer: Reply): void {\n\t\tif (this.#closed) return;\n\t\tthis.send(answer);\n\t\tthis.#closed = true;\n\t\tthis.input.abort();\n\t\tthis.transport.end();\n\t}\n\n\t/** Counts a failed command; past the limit, hangs up. */\n\tfail(answer: Reply): void {\n\t\tthis.state.errors++;\n\t\tif (this.state.errors >= this.settings.maxErrors) {\n\t\t\tconst { hostname } = this.settings.options;\n\t\t\tthis.close(reply(421, '4.7.0', `${hostname} Too many errors, closing`));\n\t\t} else {\n\t\t\tthis.send(answer);\n\t\t}\n\t}\n\n\t/** Hands an error to `onError`, which may not throw back. */\n\treport(error: unknown): void {\n\t\ttry {\n\t\t\tthis.settings.options.onError?.(error, this.session);\n\t\t} catch {\n\t\t\t// The app's error handler failing is not the client's business.\n\t\t}\n\t}\n\n\t/**\n\t * Runs a hook: its refusal, or `undefined`. A throw, a reply that is not\n\t * a refusal, or — with `deadline` — no answer within `hookTimeout` is\n\t * reported and answered `451 4.3.0`.\n\t */\n\tasync hook(\n\t\tname: string,\n\t\trun: () => HookResult | Promise<HookResult>,\n\t\tdeadline = true,\n\t): Promise<Reply | undefined> {\n\t\tconst answer = await this.check(name, run, deadline);\n\t\tif (answer.failed) return LOCAL_ERROR;\n\t\treturn refusalOf(name, answer.value, (error) => this.report(error));\n\t}\n\n\t/** Runs app code that answers a value: `failed` when it threw or timed out, which is reported. */\n\tasync check<T>(\n\t\tname: string,\n\t\trun: () => T | Promise<T>,\n\t\tdeadline = true,\n\t): Promise<{ failed: false; value: T } | { failed: true }> {\n\t\tconst seconds = this.settings.hookTimeout;\n\t\ttry {\n\t\t\tconst running = Promise.resolve().then(run);\n\t\t\tconst value = deadline ? await within(running, seconds) : await running;\n\t\t\tif (timedOut(value)) {\n\t\t\t\tthis.report(hookTimeout(name, seconds));\n\t\t\t\treturn { failed: true };\n\t\t\t}\n\t\t\treturn { failed: false, value };\n\t\t} catch (error) {\n\t\t\tthis.report(error);\n\t\t\treturn { failed: true };\n\t\t}\n\t}\n\n\t/** The greeting, or the refusal of `onConnect`, or of a client that talked first. */\n\tasync open(): Promise<void> {\n\t\tconst { options } = this.settings;\n\t\tconst refused = options.onConnect\n\t\t\t? await this.hook('onConnect', () => options.onConnect?.(this.session))\n\t\t\t: undefined;\n\t\tif (refused) return this.close(refused);\n\t\tconst { greetingDelay } = this.settings;\n\t\tif (greetingDelay > 0) await Bun.sleep(greetingDelay * 1000);\n\t\tif (this.#closed) return;\n\t\tif (this.input.early) {\n\t\t\t// RFC 5321 §4.3.1: the client waits for the greeting; a spammer often does not.\n\t\t\treturn this.close(\n\t\t\t\treply(554, '5.5.0', `${options.hostname} Talked before the greeting`),\n\t\t\t);\n\t\t}\n\t\tthis.send(reply(220, undefined, `${options.hostname} ESMTP ready`));\n\t\t// The client's idle time starts at the greeting, not at connect: what\n\t\t// greetingDelay and onConnect took is not taken from it.\n\t\tthis.transport.restartIdle(this.settings.timeout);\n\t\tthis.input.greeted();\n\t}\n\n\t/** Bytes from the client; processed in order, after what came before. */\n\treceive(chunk: Uint8Array): void {\n\t\tif (!this.#closed) this.input.receive(chunk);\n\t}\n\n\t/** Resolves once everything received so far is answered. */\n\tidle(): Promise<void> {\n\t\treturn this.input.idle();\n\t}\n}\n",
18
- "import { SmtpError } from '../errors';\nimport type { SmtpServerOptions } from './options';\n\n/** The options with their defaults, checked once. */\nexport interface Settings {\n\treadonly options: SmtpServerOptions;\n\treadonly mode: 'mx' | 'submission';\n\treadonly maxMessageSize: number;\n\treadonly maxRecipients: number;\n\treadonly maxConnections: number;\n\treadonly maxErrors: number;\n\treadonly timeout: number;\n\treadonly hookTimeout: number;\n\treadonly greetingDelay: number;\n\tisLocal(domain: string): boolean | Promise<boolean>;\n}\n\n/** The longest delay `setTimeout` takes, in whole seconds: past 2^31 − 1 ms it fires after 1 ms. */\nconst MAX_TIMER_SECONDS = Math.floor(2_147_483_647 / 1000);\n\nconst invalid = (message: string) =>\n\tnew SmtpError('INVALID_OPTION', `createSmtpServer(): ${message}`);\n\nfunction positive(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tif (value === undefined) return fallback;\n\tif (!Number.isSafeInteger(value) || value < 1) {\n\t\tthrow invalid(`${name} must be a positive integer, not ${value}`);\n\t}\n\treturn value;\n}\n\n/** `positive`, and short enough for `setTimeout`, which a longer delay makes fire at once. */\nfunction timer(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tconst seconds = positive(name, value, fallback);\n\tif (seconds > MAX_TIMER_SECONDS) {\n\t\tthrow invalid(\n\t\t\t`${name} must be at most ${MAX_TIMER_SECONDS} seconds, not ${seconds}`,\n\t\t);\n\t}\n\treturn seconds;\n}\n\nfunction nonNegative(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tif (value === undefined) return fallback;\n\tif (!Number.isFinite(value) || value < 0) {\n\t\tthrow invalid(\n\t\t\t`${name} must be a number of seconds, 0 or more, not ${value}`,\n\t\t);\n\t}\n\treturn value;\n}\n\n/** `localDomains` as a lookup; the domain it is given is lower case. */\nfunction localLookup(\n\tlocal: SmtpServerOptions['localDomains'],\n): (domain: string) => boolean | Promise<boolean> {\n\tif (typeof local === 'function') return local;\n\tif (\n\t\tArray.isArray(local) &&\n\t\tlocal.every((domain: unknown) => typeof domain === 'string')\n\t) {\n\t\tconst domains = new Set(\n\t\t\t(local as readonly string[]).map((domain) => domain.toLowerCase()),\n\t\t);\n\t\treturn (domain) => domains.has(domain);\n\t}\n\tthrow invalid('localDomains must be an array of domains or a function');\n}\n\nexport function settingsOf(options: SmtpServerOptions): Settings {\n\tif (\n\t\ttypeof options.hostname !== 'string' ||\n\t\t!/^[A-Za-z0-9.-]+$/.test(options.hostname)\n\t) {\n\t\tthrow invalid(`\"${options.hostname}\" is not a host name`);\n\t}\n\tif (typeof options.onData !== 'function') {\n\t\tthrow invalid('onData must be a function: it is where messages go');\n\t}\n\tif (options.implicitTls && !options.tls) {\n\t\tthrow invalid('implicitTls needs tls: { key, cert }');\n\t}\n\tif (options.mode === 'submission' && !options.authenticate) {\n\t\tthrow invalid(\n\t\t\t'submission takes mail only from authenticated users, so it needs authenticate',\n\t\t);\n\t}\n\tif (options.authenticate && !options.tls) {\n\t\tthrow invalid(\n\t\t\t'authenticate needs tls: { key, cert }, since AUTH is offered only once encrypted',\n\t\t);\n\t}\n\tconst isLocal = localLookup(options.localDomains);\n\tconst timeout = positive('timeout', options.timeout, 300);\n\tconst greetingDelay = nonNegative('greetingDelay', options.greetingDelay, 0);\n\tif (greetingDelay >= timeout) {\n\t\tthrow invalid(\n\t\t\t`greetingDelay (${greetingDelay} s) must be shorter than timeout (${timeout} s), or every client times out before the greeting`,\n\t\t);\n\t}\n\treturn {\n\t\toptions,\n\t\tmode: options.mode ?? 'mx',\n\t\tmaxMessageSize: positive(\n\t\t\t'maxMessageSize',\n\t\t\toptions.maxMessageSize,\n\t\t\t25 * 1024 * 1024,\n\t\t),\n\t\tmaxRecipients: positive('maxRecipients', options.maxRecipients, 100),\n\t\tmaxConnections: positive('maxConnections', options.maxConnections, 1000),\n\t\tmaxErrors: positive('maxErrors', options.maxErrors, 10),\n\t\ttimeout,\n\t\thookTimeout: timer('hookTimeout', options.hookTimeout, 60),\n\t\tgreetingDelay,\n\t\tisLocal: (domain) => isLocal(domain.toLowerCase()),\n\t};\n}\n",
19
- "import type { Socket } from 'bun';\nimport { Outgoing } from '../io/outgoing';\n\n/** What a connection needs from its socket: Bun's, or a fake one in specs. */\nexport interface Transport {\n\treadonly remoteAddress: string;\n\treadonly secure: boolean;\n\t/** Queues text for the client; what the socket cannot take now is kept for `drain`. */\n\twrite(text: string): void;\n\t/** Resolves once everything written has left. */\n\tdrained(): Promise<void>;\n\t/**\n\t * Hangs up once everything written has left: a graceful close, as after\n\t * QUIT. A socket not closed within `CLOSE_GRACE_MS` is terminated.\n\t * If the server paused reading, it reads again first, since a half-close\n\t * does not complete over input left unread.\n\t */\n\tend(): void;\n\t/**\n\t * Hangs up now, the server's decision: what the socket already took\n\t * leaves, but what still waits for a client that stopped reading is\n\t * dropped and the connection reset, so the close never hangs on it.\n\t * With nothing queued it hangs up as `end()` does, within the same grace.\n\t */\n\tabort(): void;\n\t/** Stops reading from the client, while the server catches up. */\n\tpause(): void;\n\tresume(): void;\n\t/** Starts TLS on the connection, once the 220 to STARTTLS has left. */\n\tstartTls(): void;\n\t/** Starts the idle time again, as a byte from the client does. */\n\trestartIdle(seconds: number): void;\n}\n\n/**\n * How long any end may wait on the client — for what is queued to leave,\n * then for the close itself — before the socket is terminated.\n */\nexport const CLOSE_GRACE_MS = 5_000;\n\n/**\n * A hang-up while the server paused reading lingers: it reads again and\n * drops what the client sent until nothing came for `LINGER_QUIET_MS`,\n * then half-closes. Bun closes the socket at once on `shutdown(true)`, and\n * Linux answers a close over unread input with a reset that loses the last\n * reply. A client still sending after `LINGER_MAX_MS` is reset.\n */\nexport const LINGER_QUIET_MS = 20;\nexport const LINGER_MAX_MS = 500;\n\n/**\n * A Bun socket as a Transport. What the socket cannot take now waits in an\n * `Outgoing` for the `drain` event, so no reply is lost to a client that\n * reads slowly.\n */\nexport class SocketTransport implements Transport {\n\treadonly #socket: Socket<unknown>;\n\treadonly remoteAddress: string;\n\treadonly secure: boolean;\n\treadonly #startTls: () => void;\n\treadonly #outgoing: Outgoing;\n\t#ending = false;\n\t/** The socket closed: every later write, end or abort is a no-op. */\n\t#closed = false;\n\t/** The server stopped reading: what the client sends waits in the socket. */\n\t#paused = false;\n\t#grace: ReturnType<typeof setTimeout> | undefined;\n\t/** A paused hang-up waiting for the client's input to stop: how it will shut down, when it stops waiting, its timer. */\n\t#linger:\n\t\t| {\n\t\t\t\tdrained: boolean;\n\t\t\t\tuntil: number;\n\t\t\t\ttimer?: ReturnType<typeof setTimeout>;\n\t\t }\n\t\t| undefined;\n\n\tconstructor(\n\t\tsocket: Socket<unknown>,\n\t\tsecure: boolean,\n\t\tstartTls: () => void,\n\t\tremoteAddress = socket.remoteAddress,\n\t) {\n\t\tthis.#socket = socket;\n\t\tthis.secure = secure;\n\t\tthis.#startTls = startTls;\n\t\tthis.remoteAddress = remoteAddress;\n\t\tthis.#outgoing = new Outgoing((bytes) => socket.write(bytes));\n\t}\n\n\twrite(text: string): void {\n\t\tif (this.#closed) return;\n\t\tthis.#outgoing.write(new TextEncoder().encode(text));\n\t}\n\n\t/** Bun's `drain`: the socket can take more. */\n\tdrain(): void {\n\t\tif (this.#outgoing.drain() && this.#ending) this.#hangUp(true);\n\t}\n\n\tdrained(): Promise<void> {\n\t\treturn this.#outgoing.drained();\n\t}\n\n\t/**\n\t * Bun's `data`: the client sent bytes. While a hang-up lingers, they are\n\t * dropped, and the half-close waits until they stop — `LINGER_MAX_MS` at\n\t * most: a client still sending then is reset. Re-arming the timer on each\n\t * chunk would let a client that never pauses keep it from firing, and a\n\t * half-close over its input may never fire `close` (Linux).\n\t */\n\treceived(): void {\n\t\tconst linger = this.#linger;\n\t\tif (!linger) return;\n\t\tconst left = linger.until - Date.now();\n\t\tif (left <= 0) this.#terminate();\n\t\telse this.#lingerFor(Math.min(LINGER_QUIET_MS, left));\n\t}\n\n\t/** The socket closed: nothing more will leave. */\n\tclosed(): void {\n\t\tthis.#closed = true;\n\t\tthis.#disarm();\n\t\tthis.#stopLingering();\n\t\tthis.#outgoing.clear();\n\t}\n\n\t/** After `closed()`, does nothing: no grace is armed on a dead socket. */\n\tend(): void {\n\t\tif (this.#closed) return;\n\t\tthis.#arm();\n\t\tif (this.#outgoing.empty) this.#hangUp(false);\n\t\telse this.#ending = true;\n\t}\n\n\tabort(): void {\n\t\tif (this.#closed) return;\n\t\tif (this.#outgoing.empty) this.end();\n\t\telse this.#terminate();\n\t}\n\n\t/**\n\t * Hangs up with a half-close, `shutdown(true)`, not Bun's `end`: on TLS,\n\t * `end` waits for the client's own close, which a client that stopped\n\t * reading never sends, and a `terminate` after it no longer closes the\n\t * socket (Bun 1.4). The half-close fires `close` at once, and a client\n\t * that reads later still gets every byte, then the end. A full\n\t * `shutdown()` would hold a paused client until the grace, then lose\n\t * its last reply to the reset.\n\t *\n\t * Except on TLS right after a queue drained (`drained`): there the last\n\t * write may still sit in Bun's own TLS buffer, which a half-close drops\n\t * (Bun 1.4.2: up to 96 KiB lost by a client reading slowly). The client\n\t * was reading a moment ago, so a full `shutdown()` closes once it\n\t * answers, and the grace bounds it if it stops.\n\t *\n\t * Reading paused, it reads again first: over input the server never\n\t * read, a half-close does not fire `close` (Bun 1.4.2), and the slot\n\t * waited for the grace. And it lingers: Bun closes the socket as soon as\n\t * it half-closes, and on Linux a close with input still unread is a\n\t * reset, which loses the last reply. So it drops what the client sends\n\t * until that stops for `LINGER_QUIET_MS` (`LINGER_MAX_MS` at most), then\n\t * half-closes: `close` fires at once, and a client that stopped sending\n\t * still gets the last reply and the end. One still sending at\n\t * `LINGER_MAX_MS` is reset (`received()`).\n\t */\n\t#hangUp(drained: boolean): void {\n\t\tthis.#ending = false;\n\t\tif (this.#linger) return;\n\t\tif (!this.#paused) {\n\t\t\tthis.#shutdown(drained);\n\t\t\treturn;\n\t\t}\n\t\tthis.resume();\n\t\tthis.#linger = { drained, until: Date.now() + LINGER_MAX_MS };\n\t\tthis.#lingerFor(LINGER_QUIET_MS);\n\t}\n\n\t/**\n\t * Half-closes in `ms`, unless the client sends again first. Armed for\n\t * less than `LINGER_QUIET_MS`, the input never went quiet before\n\t * `LINGER_MAX_MS`: it resets instead.\n\t */\n\t#lingerFor(ms: number): void {\n\t\tconst linger = this.#linger;\n\t\tif (!linger) return;\n\t\tclearTimeout(linger.timer);\n\t\tlinger.timer = setTimeout(() => {\n\t\t\tif (ms < LINGER_QUIET_MS) return this.#terminate();\n\t\t\tthis.#stopLingering();\n\t\t\tthis.#shutdown(linger.drained);\n\t\t}, ms);\n\t\tlinger.timer.unref?.();\n\t}\n\n\t#stopLingering(): void {\n\t\tclearTimeout(this.#linger?.timer);\n\t\tthis.#linger = undefined;\n\t}\n\n\t#shutdown(drained: boolean): void {\n\t\tif (drained && this.secure) this.#socket.shutdown();\n\t\telse this.#socket.shutdown(true);\n\t}\n\n\t/** Drops what is queued and resets the connection. */\n\t#terminate(): void {\n\t\tthis.#disarm();\n\t\tthis.#stopLingering();\n\t\tthis.#outgoing.clear();\n\t\tthis.#socket.terminate();\n\t}\n\n\t/** Terminates the socket once the grace is up, unless it closed first; the first deadline stands. */\n\t#arm(): void {\n\t\tif (this.#grace) return;\n\t\tthis.#grace = setTimeout(() => this.#terminate(), CLOSE_GRACE_MS);\n\t\tthis.#grace.unref?.();\n\t}\n\n\t#disarm(): void {\n\t\tclearTimeout(this.#grace);\n\t\tthis.#grace = undefined;\n\t}\n\n\tpause(): void {\n\t\tthis.#paused = true;\n\t\tthis.#socket.pause();\n\t}\n\n\tresume(): void {\n\t\tthis.#paused = false;\n\t\tthis.#socket.resume();\n\t}\n\n\tstartTls(): void {\n\t\tthis.#startTls();\n\t}\n\n\trestartIdle(seconds: number): void {\n\t\tthis.#socket.timeout(seconds);\n\t}\n}\n",
20
- "import type { Socket, SocketHandler, TCPSocketListener } from 'bun';\nimport { SmtpError } from '../errors';\nimport { reply } from '../protocol/reply';\nimport { Connection } from './connection';\nimport type { SmtpServerOptions } from './options';\nimport { type Settings, settingsOf } from './settings';\nimport { SocketTransport } from './transport';\n\ninterface SocketState {\n\tconnection?: Connection;\n\ttransport?: SocketTransport;\n\t/** Bytes on the raw socket after STARTTLS are the TLS stream itself: ignored. */\n\tupgraded: boolean;\n}\n\nexport interface SmtpServer {\n\t/** Starts listening; resolves once the port is bound. Once only: a second call throws. */\n\tlisten(options: {\n\t\tport: number;\n\t\thostname?: string;\n\t}): Promise<{ port: number; hostname: string }>;\n\t/** Stops listening; `closeConnections` hangs up on every client too. */\n\tstop(closeConnections?: boolean): void;\n\t/** Open connections. */\n\treadonly connections: number;\n}\n\n/** The handlers both the clear socket and the TLS one share: input, drain, idle time. */\nfunction handlers(settings: Settings): SocketHandler<SocketState> {\n\tconst idle = reply(\n\t\t421,\n\t\t'4.4.2',\n\t\t`${settings.options.hostname} Idle too long, closing`,\n\t);\n\treturn {\n\t\tdata(socket, chunk) {\n\t\t\tif (socket.data.upgraded) return;\n\t\t\t// A hang-up that lingers waits for the client to stop sending.\n\t\t\tsocket.data.transport?.received();\n\t\t\t// Any byte from the client starts the idle time again.\n\t\t\tsocket.timeout(settings.timeout);\n\t\t\tsocket.data.connection?.receive(chunk);\n\t\t},\n\t\tdrain(socket) {\n\t\t\tif (!socket.data.upgraded) socket.data.transport?.drain();\n\t\t},\n\t\terror(socket) {\n\t\t\tsocket.data.connection?.close();\n\t\t},\n\t\ttimeout(socket) {\n\t\t\tif (socket.data.upgraded) return;\n\t\t\tconst { connection, transport } = socket.data;\n\t\t\t// Closed already, after QUIT, and the 221 still waits for a client\n\t\t\t// that stopped reading: the idle time is up for that too.\n\t\t\tif (connection?.closed) transport?.abort();\n\t\t\telse connection?.close(idle);\n\t\t},\n\t};\n}\n\n/** Wraps a socket; STARTTLS swaps it for the encrypted one. */\nfunction transportOf(\n\tsocket: Socket<SocketState>,\n\tsettings: Settings,\n\tsecure: boolean,\n): SocketTransport {\n\tconst transport = new SocketTransport(\n\t\tsocket as Socket<unknown>,\n\t\tsecure,\n\t\t() => {\n\t\t\tconst tls = settings.options.tls;\n\t\t\tconst connection = socket.data.connection;\n\t\t\tif (!tls || !connection) return;\n\t\t\tsocket.data.upgraded = true;\n\t\t\tconst [, encrypted] = socket.upgradeTLS<SocketState>({\n\t\t\t\ttls: { key: tls.key, cert: tls.cert },\n\t\t\t\tdata: { connection, upgraded: false },\n\t\t\t\tsocket: {\n\t\t\t\t\t...handlers(settings),\n\t\t\t\t\tclose: (s) => {\n\t\t\t\t\t\ts.data.transport?.closed();\n\t\t\t\t\t\tconnection.close();\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\tencrypted.timeout(settings.timeout);\n\t\t\tconst next = new SocketTransport(\n\t\t\t\tencrypted as Socket<unknown>,\n\t\t\t\ttrue,\n\t\t\t\t() => {},\n\t\t\t\tsocket.remoteAddress,\n\t\t\t);\n\t\t\tencrypted.data.transport = next;\n\t\t\tconnection.useTransport(next);\n\t\t},\n\t);\n\tsocket.data.transport = transport;\n\treturn transport;\n}\n\n/**\n * An SMTP server (RFC 5321) on `Bun.listen`: EHLO with PIPELINING, SIZE,\n * 8BITMIME, SMTPUTF8 and ENHANCEDSTATUSCODES; STARTTLS (RFC 3207) or\n * implicit TLS (RFC 8314); AUTH PLAIN and LOGIN over TLS only (RFC 4954);\n * policy through hooks. It never relays without AUTH: a recipient outside\n * `localDomains` is refused to an unauthenticated session, whatever the\n * hooks say.\n */\nexport function createSmtpServer(options: SmtpServerOptions): SmtpServer {\n\tconst settings = settingsOf(options);\n\tlet listener: TCPSocketListener<SocketState> | undefined;\n\tconst open = new Set<Connection>();\n\tconst secure = options.implicitTls === true;\n\treturn {\n\t\tget connections() {\n\t\t\treturn open.size;\n\t\t},\n\t\tasync listen({ port, hostname = '0.0.0.0' }) {\n\t\t\tif (listener) {\n\t\t\t\tthrow new SmtpError(\n\t\t\t\t\t'ALREADY_LISTENING',\n\t\t\t\t\t`listen(): the server is already listening on ${listener.hostname}:${listener.port}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlistener = Bun.listen<SocketState>({\n\t\t\t\thostname,\n\t\t\t\tport,\n\t\t\t\t...(secure && options.tls\n\t\t\t\t\t? { tls: { key: options.tls.key, cert: options.tls.cert } }\n\t\t\t\t\t: {}),\n\t\t\t\tsocket: {\n\t\t\t\t\t...handlers(settings),\n\t\t\t\t\topen(socket) {\n\t\t\t\t\t\tsocket.data = { upgraded: false };\n\t\t\t\t\t\tsocket.timeout(settings.timeout);\n\t\t\t\t\t\tif (open.size >= settings.maxConnections) {\n\t\t\t\t\t\t\t// Through a transport, so this hang-up is bounded as every other is.\n\t\t\t\t\t\t\tconst refused = new SocketTransport(\n\t\t\t\t\t\t\t\tsocket as Socket<unknown>,\n\t\t\t\t\t\t\t\tsecure,\n\t\t\t\t\t\t\t\t() => {},\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tsocket.data.transport = refused;\n\t\t\t\t\t\t\trefused.write(\n\t\t\t\t\t\t\t\t`421 4.3.2 ${options.hostname} Too many connections, try later\\r\\n`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\trefused.end();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst connection = new Connection(\n\t\t\t\t\t\t\tsettings,\n\t\t\t\t\t\t\ttransportOf(socket, settings, secure),\n\t\t\t\t\t\t);\n\t\t\t\t\t\topen.add(connection);\n\t\t\t\t\t\tsocket.data.connection = connection;\n\t\t\t\t\t\tvoid connection.open();\n\t\t\t\t\t},\n\t\t\t\t\tclose(socket) {\n\t\t\t\t\t\tconst connection = socket.data.connection;\n\t\t\t\t\t\tif (connection) open.delete(connection);\n\t\t\t\t\t\tsocket.data.transport?.closed();\n\t\t\t\t\t\tsocket.data.connection?.close();\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn { port: listener.port, hostname: listener.hostname };\n\t\t},\n\t\tstop(closeConnections = false) {\n\t\t\tlistener?.stop(closeConnections);\n\t\t\tlistener = undefined;\n\t\t\tif (!closeConnections) return;\n\t\t\t// Bun's `stop(true)` closes the sockets the listener holds, and a\n\t\t\t// socket STARTTLS moved to TLS is no longer one of them: hang up on\n\t\t\t// every connection here, as a timeout does.\n\t\t\tfor (const connection of [...open]) connection.close();\n\t\t},\n\t};\n}\n"
19
+ "import { Outgoing } from '../io/outgoing';\nimport type { RawSocket } from './raw-socket';\n\n/** What a connection needs from its socket: Bun's, or a fake one in specs. */\nexport interface Transport {\n\treadonly remoteAddress: string;\n\treadonly secure: boolean;\n\t/** Queues text for the client; what the socket cannot take now is kept for `drain`. */\n\twrite(text: string): void;\n\t/** Resolves once everything written has left. */\n\tdrained(): Promise<void>;\n\t/**\n\t * Hangs up once everything written has left: a graceful close, as after\n\t * QUIT. A socket not closed within `CLOSE_GRACE_MS` is terminated.\n\t * If the server paused reading, it reads again first, since a half-close\n\t * does not complete over input left unread.\n\t */\n\tend(): void;\n\t/**\n\t * Hangs up now, the server's decision: what the socket already took\n\t * leaves, but what still waits for a client that stopped reading is\n\t * dropped and the connection reset, so the close never hangs on it.\n\t * With nothing queued it hangs up as `end()` does, within the same grace.\n\t */\n\tabort(): void;\n\t/** Stops reading from the client, while the server catches up. */\n\tpause(): void;\n\tresume(): void;\n\t/** Starts TLS on the connection, once the 220 to STARTTLS has left. */\n\tstartTls(): void;\n\t/** Starts the idle time again, as a byte from the client does. */\n\trestartIdle(seconds: number): void;\n}\n\n/**\n * How long any end may wait on the client — for what is queued to leave,\n * then for the close itself — before the socket is terminated.\n */\nexport const CLOSE_GRACE_MS = 5_000;\n\n/**\n * A hang-up while the server paused reading lingers: it reads again and\n * drops what the client sent until nothing came for `LINGER_QUIET_MS`,\n * then half-closes. Bun closes the socket at once on `shutdown(true)`, and\n * Linux answers a close over unread input with a reset that loses the last\n * reply. A client still sending after `LINGER_MAX_MS` is reset.\n */\nexport const LINGER_QUIET_MS = 20;\nexport const LINGER_MAX_MS = 500;\n\n/**\n * A Bun socket as a Transport. What the socket cannot take now waits in an\n * `Outgoing` for the `drain` event, so no reply is lost to a client that\n * reads slowly.\n */\nexport class SocketTransport implements Transport {\n\treadonly #socket: RawSocket;\n\treadonly remoteAddress: string;\n\treadonly secure: boolean;\n\treadonly #startTls: () => void;\n\treadonly #outgoing: Outgoing;\n\t#ending = false;\n\t/** The socket closed: every later write, end or abort is a no-op. */\n\t#closed = false;\n\t/** The server stopped reading: what the client sends waits in the socket. */\n\t#paused = false;\n\t#grace: ReturnType<typeof setTimeout> | undefined;\n\t/** A paused hang-up waiting for the client's input to stop: how it will shut down, when it stops waiting, its timer. */\n\t#linger:\n\t\t| {\n\t\t\t\tdrained: boolean;\n\t\t\t\tuntil: number;\n\t\t\t\ttimer?: ReturnType<typeof setTimeout>;\n\t\t }\n\t\t| undefined;\n\n\tconstructor(\n\t\tsocket: RawSocket,\n\t\tsecure: boolean,\n\t\tstartTls: () => void,\n\t\tremoteAddress = socket.remoteAddress,\n\t) {\n\t\tthis.#socket = socket;\n\t\tthis.secure = secure;\n\t\tthis.#startTls = startTls;\n\t\tthis.remoteAddress = remoteAddress;\n\t\tthis.#outgoing = new Outgoing((bytes) => socket.write(bytes));\n\t}\n\n\twrite(text: string): void {\n\t\tif (this.#closed) return;\n\t\tthis.#outgoing.write(new TextEncoder().encode(text));\n\t}\n\n\t/** Bun's `drain`: the socket can take more. */\n\tdrain(): void {\n\t\tif (this.#outgoing.drain() && this.#ending) this.#hangUp(true);\n\t}\n\n\tdrained(): Promise<void> {\n\t\treturn this.#outgoing.drained();\n\t}\n\n\t/**\n\t * Bun's `data`: the client sent bytes. While a hang-up lingers, they are\n\t * dropped, and the half-close waits until they stop — `LINGER_MAX_MS` at\n\t * most: a client still sending then is reset. Re-arming the timer on each\n\t * chunk would let a client that never pauses keep it from firing, and a\n\t * half-close over its input may never fire `close` (Linux).\n\t */\n\treceived(): void {\n\t\tconst linger = this.#linger;\n\t\tif (!linger) return;\n\t\tconst left = linger.until - Date.now();\n\t\tif (left <= 0) this.#terminate();\n\t\telse this.#lingerFor(Math.min(LINGER_QUIET_MS, left));\n\t}\n\n\t/** The socket closed: nothing more will leave. */\n\tclosed(): void {\n\t\tthis.#closed = true;\n\t\tthis.#disarm();\n\t\tthis.#stopLingering();\n\t\tthis.#outgoing.clear();\n\t}\n\n\t/** After `closed()`, does nothing: no grace is armed on a dead socket. */\n\tend(): void {\n\t\tif (this.#closed) return;\n\t\tthis.#arm();\n\t\tif (this.#outgoing.empty) this.#hangUp(false);\n\t\telse this.#ending = true;\n\t}\n\n\tabort(): void {\n\t\tif (this.#closed) return;\n\t\tif (this.#outgoing.empty) this.end();\n\t\telse this.#terminate();\n\t}\n\n\t/**\n\t * Hangs up with a half-close, `shutdown(true)`, not Bun's `end`: on TLS,\n\t * `end` waits for the client's own close, which a client that stopped\n\t * reading never sends, and a `terminate` after it no longer closes the\n\t * socket (Bun 1.4). The half-close fires `close` at once, and a client\n\t * that reads later still gets every byte, then the end. A full\n\t * `shutdown()` would hold a paused client until the grace, then lose\n\t * its last reply to the reset.\n\t *\n\t * Except on TLS right after a queue drained (`drained`): there the last\n\t * write may still sit in Bun's own TLS buffer, which a half-close drops\n\t * (Bun 1.4.2: up to 96 KiB lost by a client reading slowly). The client\n\t * was reading a moment ago, so a full `shutdown()` closes once it\n\t * answers, and the grace bounds it if it stops.\n\t *\n\t * Reading paused, it reads again first: over input the server never\n\t * read, a half-close does not fire `close` (Bun 1.4.2), and the slot\n\t * waited for the grace. And it lingers: Bun closes the socket as soon as\n\t * it half-closes, and on Linux a close with input still unread is a\n\t * reset, which loses the last reply. So it drops what the client sends\n\t * until that stops for `LINGER_QUIET_MS` (`LINGER_MAX_MS` at most), then\n\t * half-closes: `close` fires at once, and a client that stopped sending\n\t * still gets the last reply and the end. One still sending at\n\t * `LINGER_MAX_MS` is reset (`received()`).\n\t */\n\t#hangUp(drained: boolean): void {\n\t\tthis.#ending = false;\n\t\tif (this.#linger) return;\n\t\tif (!this.#paused) {\n\t\t\tthis.#shutdown(drained);\n\t\t\treturn;\n\t\t}\n\t\tthis.resume();\n\t\tthis.#linger = { drained, until: Date.now() + LINGER_MAX_MS };\n\t\tthis.#lingerFor(LINGER_QUIET_MS);\n\t}\n\n\t/**\n\t * Half-closes in `ms`, unless the client sends again first. Armed for\n\t * less than `LINGER_QUIET_MS`, the input never went quiet before\n\t * `LINGER_MAX_MS`: it resets instead.\n\t */\n\t#lingerFor(ms: number): void {\n\t\tconst linger = this.#linger;\n\t\tif (!linger) return;\n\t\tclearTimeout(linger.timer);\n\t\tlinger.timer = setTimeout(() => {\n\t\t\tif (ms < LINGER_QUIET_MS) return this.#terminate();\n\t\t\tthis.#stopLingering();\n\t\t\tthis.#shutdown(linger.drained);\n\t\t}, ms);\n\t\tlinger.timer.unref?.();\n\t}\n\n\t#stopLingering(): void {\n\t\tclearTimeout(this.#linger?.timer);\n\t\tthis.#linger = undefined;\n\t}\n\n\t#shutdown(drained: boolean): void {\n\t\tif (drained && this.secure) this.#socket.shutdown();\n\t\telse this.#socket.shutdown(true);\n\t}\n\n\t/** Drops what is queued and resets the connection. */\n\t#terminate(): void {\n\t\tthis.#disarm();\n\t\tthis.#stopLingering();\n\t\tthis.#outgoing.clear();\n\t\tthis.#socket.terminate();\n\t}\n\n\t/** Terminates the socket once the grace is up, unless it closed first; the first deadline stands. */\n\t#arm(): void {\n\t\tif (this.#grace) return;\n\t\tthis.#grace = setTimeout(() => this.#terminate(), CLOSE_GRACE_MS);\n\t\tthis.#grace.unref?.();\n\t}\n\n\t#disarm(): void {\n\t\tclearTimeout(this.#grace);\n\t\tthis.#grace = undefined;\n\t}\n\n\tpause(): void {\n\t\tthis.#paused = true;\n\t\tthis.#socket.pause();\n\t}\n\n\tresume(): void {\n\t\tthis.#paused = false;\n\t\tthis.#socket.resume();\n\t}\n\n\tstartTls(): void {\n\t\tthis.#startTls();\n\t}\n\n\trestartIdle(seconds: number): void {\n\t\tthis.#socket.timeout(seconds);\n\t}\n}\n",
20
+ "import type { Socket, SocketHandler } from 'bun';\nimport { reply } from '../protocol/reply';\nimport type { Connection } from './connection';\nimport type { HeaderReader } from './proxy/reader';\nimport type { ProxiedTls } from './proxy/tls';\nimport type { RawSocket } from './raw-socket';\nimport type { Settings } from './settings';\nimport type { Slots } from './slots';\nimport { SocketTransport } from './transport';\n\n/**\n * What a socket of the SMTP server does: the handlers the clear socket and\n * the TLS one share, and the STARTTLS upgrade. The listener's own `open`,\n * `handshake` and `close` are in `admission.ts`.\n */\n\nexport interface SocketState {\n\tconnection?: Connection;\n\ttransport?: SocketTransport;\n\t/** Bytes on the raw socket after STARTTLS are the TLS stream itself: ignored. */\n\tupgraded: boolean;\n\t/**\n\t * Implicit TLS whose handshake has not completed: the socket is counted,\n\t * but bounded by `handshakeTimeout`, and `start` waits for the handshake.\n\t */\n\thandshaking?: boolean;\n\t/** What the server does once the handshake completes: greet, or turn away. */\n\tstart?: () => void;\n\t/** A trusted proxy's PROXY header, still coming: nothing else is read meanwhile. */\n\theader?: HeaderReader;\n\t/** Implicit TLS behind a PROXY header, over this raw socket. */\n\ttls?: ProxiedTls;\n}\n\n/** Bytes from the client, in clear or decrypted: they start the idle time again. */\nexport function received(\n\tsocket: Socket<SocketState>,\n\tsettings: Settings,\n\tchunk: Uint8Array,\n): void {\n\t// A hang-up that lingers waits for the client to stop sending.\n\tsocket.data.transport?.received();\n\t// Any byte from the client starts the idle time again.\n\tsocket.timeout(settings.timeout);\n\tsocket.data.connection?.receive(chunk);\n}\n\n/**\n * The handlers both the clear socket and the TLS one share: input, drain,\n * idle time. `socket.data` is read with `?.` throughout: Bun may report an\n * error or a close on a socket whose `open` never ran.\n */\nexport function handlers(settings: Settings): SocketHandler<SocketState> {\n\tconst idle = reply(\n\t\t421,\n\t\t'4.4.2',\n\t\t`${settings.options.hostname} Idle too long, closing`,\n\t);\n\treturn {\n\t\tdata(socket, chunk) {\n\t\t\tconst state = socket.data;\n\t\t\tif (!state || state.upgraded) return;\n\t\t\tif (state.header) return state.header.receive(chunk);\n\t\t\tif (!state.tls) return received(socket, settings, chunk);\n\t\t\t// TLS records: decrypted, they come back through `received`.\n\t\t\tstate.transport?.received();\n\t\t\tstate.tls.receive(chunk);\n\t\t},\n\t\tdrain(socket) {\n\t\t\tconst state = socket.data;\n\t\t\tif (!state || state.upgraded) return;\n\t\t\tif (state.tls) state.tls.rawDrain();\n\t\t\telse state.transport?.drain();\n\t\t},\n\t\terror(socket) {\n\t\t\tsocket.data?.connection?.close();\n\t\t},\n\t\ttimeout(socket) {\n\t\t\tif (!socket.data || socket.data.upgraded) return;\n\t\t\t// A TLS handshake that never completed: nothing to say, no one to say it to.\n\t\t\tif (socket.data.handshaking) return socket.terminate();\n\t\t\tconst { connection, transport } = socket.data;\n\t\t\t// Closed already, after QUIT, and the 221 still waits for a client\n\t\t\t// that stopped reading: the idle time is up for that too.\n\t\t\tif (connection?.closed) transport?.abort();\n\t\t\telse connection?.close(idle);\n\t\t},\n\t};\n}\n\n/** Writes one reply and hangs up, through a transport so the hang-up is bounded as every other is. */\nexport function turnAway(\n\tsocket: Socket<SocketState>,\n\traw: RawSocket,\n\tsecure: boolean,\n\tline: string,\n): void {\n\tconst refused = new SocketTransport(raw, secure, () => {});\n\tsocket.data.transport = refused;\n\trefused.write(line);\n\trefused.end();\n}\n\n/**\n * Wraps a socket — Bun's, or `ProxiedTls` over it — for the client at\n * `address`; STARTTLS swaps it for the encrypted one.\n */\nexport function transportOf(\n\tsocket: Socket<SocketState>,\n\traw: RawSocket,\n\taddress: string,\n\tsettings: Settings,\n\tsecure: boolean,\n\tslots: Slots<Connection>,\n): SocketTransport {\n\tconst transport = new SocketTransport(\n\t\traw,\n\t\tsecure,\n\t\t() => {\n\t\t\tconst tls = settings.options.tls;\n\t\t\tconst connection = socket.data.connection;\n\t\t\tif (!tls || !connection) return;\n\t\t\tsocket.data.upgraded = true;\n\t\t\tconst [, encrypted] = socket.upgradeTLS<SocketState>({\n\t\t\t\ttls: { key: tls.key, cert: tls.cert },\n\t\t\t\tdata: { connection, upgraded: false },\n\t\t\t\tsocket: {\n\t\t\t\t\t...handlers(settings),\n\t\t\t\t\tclose: (s) => {\n\t\t\t\t\t\tslots.release(connection);\n\t\t\t\t\t\ts.data.transport?.closed();\n\t\t\t\t\t\tconnection.close();\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\tencrypted.timeout(settings.timeout);\n\t\t\tconst next = new SocketTransport(\n\t\t\t\tencrypted as Socket<unknown>,\n\t\t\t\ttrue,\n\t\t\t\t() => {},\n\t\t\t\taddress,\n\t\t\t);\n\t\t\tencrypted.data.transport = next;\n\t\t\tconnection.useTransport(next);\n\t\t},\n\t\taddress,\n\t);\n\tsocket.data.transport = transport;\n\treturn transport;\n}\n",
21
+ "import { isIP } from 'node:net';\n\n/**\n * IP addresses as bytes, for the PROXY protocol: what `trusted` lists and\n * what a header names. An IPv4-mapped IPv6 address (`::ffff:192.0.2.1`)\n * is its IPv4 address, in both: a dual-stack listener reports an IPv4\n * peer that way.\n */\n\n/** The 4 or 16 bytes of an IP address, or `undefined` for anything else, a zone included. */\nexport function addressBytes(text: string): Uint8Array | undefined {\n\t// A zone (`fe80::1%eth0`) names an interface of this host, never a client's.\n\tif (text.includes('%')) return undefined;\n\tconst kind = isIP(text);\n\tif (kind === 4) return new Uint8Array(text.split('.').map(Number));\n\tif (kind !== 6) return undefined;\n\treturn unmapped(ipv6Bytes(text.toLowerCase()));\n}\n\n/** The 16 bytes of a valid IPv6 address, a dotted tail included. */\nfunction ipv6Bytes(text: string): Uint8Array {\n\tconst bytes = new Uint8Array(16);\n\tlet tail = text;\n\tconst dotted = /(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(text);\n\tif (dotted) {\n\t\tbytes.set(dotted.slice(1).map(Number), 12);\n\t\ttail = `${text.slice(0, dotted.index)}0:0`;\n\t}\n\tconst [head = '', rest] = tail.split('::');\n\tconst left = head === '' ? [] : head.split(':');\n\tconst right = rest === undefined || rest === '' ? [] : rest.split(':');\n\tconst groups =\n\t\trest === undefined\n\t\t\t? left\n\t\t\t: [...left, ...Array(8 - left.length - right.length).fill('0'), ...right];\n\tconst view = new DataView(bytes.buffer);\n\tgroups.forEach((group, at) => {\n\t\tif (!dotted || at < 6) view.setUint16(at * 2, Number.parseInt(group, 16));\n\t});\n\treturn bytes;\n}\n\n/** An IPv4-mapped address as its 4 bytes; any other as it is. */\nexport function unmapped(bytes: Uint8Array): Uint8Array {\n\tif (bytes.length !== 16) return bytes;\n\tconst mapped =\n\t\tbytes.subarray(0, 10).every((byte) => byte === 0) &&\n\t\tbytes[10] === 0xff &&\n\t\tbytes[11] === 0xff;\n\treturn mapped ? bytes.slice(12) : bytes;\n}\n\n/**\n * An address's text: dotted for IPv4 (an IPv4-mapped address included),\n * RFC 5952's form for IPv6 — lower case, no leading zeros, the longest\n * run of two zero groups or more as `::`.\n */\nexport function formatAddress(raw: Uint8Array): string {\n\tconst bytes = unmapped(raw);\n\tif (bytes.length === 4) return bytes.join('.');\n\tconst view = new DataView(bytes.buffer, bytes.byteOffset, 16);\n\tconst groups = Array.from({ length: 8 }, (_, at) => view.getUint16(at * 2));\n\tlet best = { at: -1, length: 1 };\n\tfor (let at = 0; at < 8; ) {\n\t\tlet end = at;\n\t\twhile (end < 8 && groups[end] === 0) end++;\n\t\tif (end - at > best.length) best = { at, length: end - at };\n\t\tat = end === at ? at + 1 : end;\n\t}\n\tconst hex = groups.map((group) => group.toString(16));\n\tif (best.at < 0) return hex.join(':');\n\tconst left = hex.slice(0, best.at).join(':');\n\tconst right = hex.slice(best.at + best.length).join(':');\n\treturn `${left}::${right}`;\n}\n",
22
+ "import { addressBytes, formatAddress } from './address';\n\n/**\n * The PROXY protocol header (HAProxy's proxy-protocol.txt, versions 1 and\n * 2) a TCP proxy sends before anything of the client's, read from the\n * bytes received so far. `source` is the client's address, or absent to\n * keep the peer's: a v2 LOCAL (a health check from the proxy itself), an\n * UNSPEC, UNIX or datagram address, a v1 UNKNOWN.\n */\nexport type ProxyHeader =\n\t| { readonly status: 'partial' }\n\t| { readonly status: 'invalid'; readonly reason: string }\n\t| {\n\t\t\treadonly status: 'complete';\n\t\t\t/** Bytes of the header: what follows is the client's. */\n\t\t\treadonly length: number;\n\t\t\treadonly source?: string;\n\t };\n\n/** A v1 line, CRLF included, is 107 bytes at most. */\nexport const MAX_V1_LENGTH = 107;\n/** v2's addresses take 216 bytes at most (two UNIX paths); TLVs past this are refused. */\nexport const MAX_TLV_BYTES = 2048;\n/** The longest header read: past it, whatever the bytes, the header is refused. */\nexport const MAX_HEADER_LENGTH = 16 + 216 + MAX_TLV_BYTES;\n\nconst V1_PREFIX = new TextEncoder().encode('PROXY ');\nconst V2_SIGNATURE = new Uint8Array([\n\t0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 0x51, 0x55, 0x49, 0x54, 0x0a,\n]);\n/** v2 address block length by family: UNSPEC, INET, INET6, UNIX. */\nconst ADDRESS_LENGTH = [0, 12, 36, 216] as const;\n\nconst PARTIAL = { status: 'partial' } as const;\nconst invalid = (reason: string) => ({ status: 'invalid', reason }) as const;\n\n/** The bytes so far agree with `prefix` as far as both go. */\nfunction startsAs(bytes: Uint8Array, prefix: Uint8Array): boolean {\n\tconst length = Math.min(bytes.length, prefix.length);\n\tfor (let at = 0; at < length; at++) {\n\t\tif (bytes[at] !== prefix[at]) return false;\n\t}\n\treturn true;\n}\n\nexport function readProxyHeader(bytes: Uint8Array): ProxyHeader {\n\tif (bytes.length === 0) return PARTIAL;\n\tif (startsAs(bytes, V2_SIGNATURE)) return readV2(bytes);\n\tif (startsAs(bytes, V1_PREFIX)) return readV1(bytes);\n\treturn invalid('no PROXY protocol signature');\n}\n\nfunction readV2(bytes: Uint8Array): ProxyHeader {\n\tif (bytes.length < 16) return PARTIAL;\n\tconst view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\tconst versionCommand = view.getUint8(12);\n\tif (versionCommand >> 4 !== 2) return invalid('not version 2');\n\tconst command = versionCommand & 0x0f;\n\tif (command > 1) return invalid(`unknown command ${command}`);\n\tconst family = view.getUint8(13) >> 4;\n\tconst transport = view.getUint8(13) & 0x0f;\n\tconst length = view.getUint16(14);\n\t// LOCAL: the proxy's own connection; its address block is ignored.\n\tconst addresses = command === 0 ? 0 : ADDRESS_LENGTH[family as 0 | 1 | 2 | 3];\n\tif (addresses === undefined || transport > 2) {\n\t\treturn invalid('unknown address family or transport');\n\t}\n\tif (length < addresses) return invalid('address block too short');\n\t// Refused from the first 16 bytes, before any of it is waited for.\n\tif (length - addresses > MAX_TLV_BYTES) return invalid('TLVs too long');\n\tconst total = 16 + length;\n\tif (bytes.length < total) return PARTIAL;\n\tif (command === 0) return { status: 'complete', length: total };\n\tconst tlvs = bytes.subarray(16 + addresses, total);\n\tif (!wellFormedTlvs(tlvs)) return invalid('malformed TLV');\n\t// Only a TCP client over IPv4 or IPv6 replaces the peer's address.\n\tif (transport !== 1 || (family !== 1 && family !== 2)) {\n\t\treturn { status: 'complete', length: total };\n\t}\n\tconst size = family === 1 ? 4 : 16;\n\tconst source = formatAddress(bytes.slice(16, 16 + size));\n\treturn { status: 'complete', length: total, source };\n}\n\n/** Each TLV — a type, a 16-bit length, its value — ends within the block: skipped, never read. */\nfunction wellFormedTlvs(block: Uint8Array): boolean {\n\tlet at = 0;\n\twhile (at < block.length) {\n\t\tif (at + 3 > block.length) return false;\n\t\tconst length = ((block[at + 1] as number) << 8) | (block[at + 2] as number);\n\t\tat += 3 + length;\n\t}\n\treturn at === block.length;\n}\n\nconst PORT = /^(0|[1-9]\\d{0,4})$/;\n\nfunction readV1(bytes: Uint8Array): ProxyHeader {\n\tconst end = bytes.indexOf(0x0a);\n\tif (end < 0) {\n\t\treturn bytes.length >= MAX_V1_LENGTH\n\t\t\t? invalid('v1 line too long')\n\t\t\t: PARTIAL;\n\t}\n\tif (end + 1 > MAX_V1_LENGTH) return invalid('v1 line too long');\n\tif (bytes[end - 1] !== 0x0d) return invalid('v1 line without CRLF');\n\tconst line = bytes.subarray(0, end - 1);\n\tif (line.some((byte) => byte < 0x20 || byte > 0x7e)) {\n\t\treturn invalid('v1 line not printable');\n\t}\n\tconst [, protocol, ...rest] = new TextDecoder().decode(line).split(' ');\n\tif (protocol === 'UNKNOWN') return { status: 'complete', length: end + 1 };\n\tconst [source = '', destination = '', sourcePort = '', port = ''] = rest;\n\tconst size = protocol === 'TCP4' ? 4 : protocol === 'TCP6' ? 16 : 0;\n\tif (size === 0) return invalid('v1 protocol not TCP4, TCP6 or UNKNOWN');\n\tconst from = rawAddress(source, size);\n\tif (\n\t\trest.length !== 4 ||\n\t\t!from ||\n\t\t!rawAddress(destination, size) ||\n\t\t!validPort(sourcePort) ||\n\t\t!validPort(port)\n\t) {\n\t\treturn invalid('v1 addresses or ports malformed');\n\t}\n\treturn { status: 'complete', length: end + 1, source: formatAddress(from) };\n}\n\n/** The bytes of `text` written as an address of `size` bytes: no IPv4-mapped shortcut for TCP6. */\nfunction rawAddress(text: string, size: number): Uint8Array | undefined {\n\tif (size === 4 && text.includes(':')) return undefined;\n\tif (size === 16 && !text.includes(':')) return undefined;\n\treturn addressBytes(text);\n}\n\nfunction validPort(text: string): boolean {\n\treturn PORT.test(text) && Number(text) <= 65_535;\n}\n",
23
+ "import { MAX_HEADER_LENGTH, readProxyHeader } from './header';\n\n/**\n * Reads the PROXY header a trusted proxy sends first, chunk by chunk, within\n * `seconds` from the TCP connection, however slowly it comes. `done` gets\n * the client's address (`undefined` to keep the peer's) and what followed\n * the header; `refuse` is called for a header that is malformed, too long\n * or too late. Either is called once, and the reader then ignores input.\n */\nexport class HeaderReader {\n\t#bytes = new Uint8Array(0);\n\t#timer: ReturnType<typeof setTimeout> | undefined;\n\t#settled = false;\n\treadonly #done: (source: string | undefined, rest: Uint8Array) => void;\n\treadonly #refuse: () => void;\n\n\tconstructor(\n\t\tseconds: number,\n\t\tdone: (source: string | undefined, rest: Uint8Array) => void,\n\t\trefuse: () => void,\n\t) {\n\t\tthis.#done = done;\n\t\tthis.#refuse = refuse;\n\t\tthis.#timer = setTimeout(() => this.#settle(refuse), seconds * 1000);\n\t\tthis.#timer.unref?.();\n\t}\n\n\treceive(chunk: Uint8Array): void {\n\t\tif (this.#settled) return;\n\t\tconst bytes = new Uint8Array(this.#bytes.length + chunk.length);\n\t\tbytes.set(this.#bytes);\n\t\tbytes.set(chunk, this.#bytes.length);\n\t\tthis.#bytes = bytes;\n\t\tconst header = readProxyHeader(bytes);\n\t\tif (header.status === 'complete') {\n\t\t\tconst rest = bytes.slice(header.length);\n\t\t\tthis.#settle(() => this.#done(header.source, rest));\n\t\t} else if (\n\t\t\theader.status === 'invalid' ||\n\t\t\tbytes.length >= MAX_HEADER_LENGTH\n\t\t) {\n\t\t\tthis.#settle(this.#refuse);\n\t\t}\n\t}\n\n\t/** The socket closed first: no timer is left behind. */\n\tcancel(): void {\n\t\tthis.#settled = true;\n\t\tclearTimeout(this.#timer);\n\t\tthis.#bytes = new Uint8Array(0);\n\t}\n\n\t#settle(then: () => void): void {\n\t\tif (this.#settled) return;\n\t\tthis.cancel();\n\t\tthen();\n\t}\n}\n",
24
+ "import { Duplex } from 'node:stream';\nimport { type SecureContext, TLSSocket } from 'node:tls';\nimport type { Socket } from 'bun';\n\n/** What the TLS session tells the listener. */\nexport interface TlsEvents {\n\t/** The handshake completed. */\n\tsecure(): void;\n\t/** Bytes from the client, decrypted. */\n\tdata(bytes: Uint8Array): void;\n\t/** What was written has left: the transport may write more. */\n\tdrain(): void;\n}\n\n/**\n * Implicit TLS behind a PROXY header. A listener with `tls` would take the\n * header for a broken ClientHello, so the listener is a clear one, and TLS\n * starts once the header is read. Bun's `socket.upgradeTLS` cannot be\n * used: it reads only what arrives after it, and a proxy sends the\n * client's ClientHello in the same segment as the header as often as not\n * (Bun 1.4.2: the handshake then never completes). So the TLS session is\n * `node:tls` over a stream this class feeds: what followed the header\n * first, then every chunk of the raw socket's `data` (`receive`).\n *\n * It has the shape of the Bun socket a `SocketTransport` drives. `write`\n * takes nothing while TLS holds more than its high-water mark, and\n * `drain` comes once it took it all; the stream under it hands the raw\n * socket what it takes and waits for the raw `drain` for the rest, so a\n * client that reads slowly holds the server back, never its memory.\n */\nexport class ProxiedTls {\n\treadonly #raw: Socket<unknown>;\n\treadonly #wire: Duplex;\n\treadonly #tls: TLSSocket;\n\t/** What the raw socket did not take yet, and the stream's callback for it. */\n\t#pending: { bytes: Uint8Array; done: () => void } | undefined;\n\t/** How the raw socket closes once TLS ended: `shutdown(true)` or `shutdown()`. */\n\t#halfClose = true;\n\n\tconstructor(raw: Socket<unknown>, context: SecureContext, events: TlsEvents) {\n\t\tthis.#raw = raw;\n\t\tthis.#wire = new Duplex({\n\t\t\tread() {},\n\t\t\twrite: (chunk: Uint8Array, _encoding, done) => this.#send(chunk, done),\n\t\t\tfinal: (done) => {\n\t\t\t\tthis.#raw.shutdown(this.#halfClose);\n\t\t\t\tdone();\n\t\t\t},\n\t\t});\n\t\tthis.#tls = new TLSSocket(this.#wire as never, {\n\t\t\tisServer: true,\n\t\t\tsecureContext: context,\n\t\t});\n\t\tthis.#tls.on('secure', () => events.secure());\n\t\tthis.#tls.on('data', (bytes: Uint8Array) => events.data(bytes));\n\t\tthis.#tls.on('drain', () => events.drain());\n\t\t// A broken handshake or record: nothing to say, no one to say it to.\n\t\tthis.#tls.on('error', () => this.terminate());\n\t}\n\n\tget remoteAddress(): string {\n\t\treturn this.#raw.remoteAddress;\n\t}\n\n\t/** The raw socket's `data`: TLS records from the client. */\n\treceive(chunk: Uint8Array): void {\n\t\tthis.#wire.push(Uint8Array.from(chunk));\n\t}\n\n\t/** The raw socket's `drain`: it can take more of what TLS wrote. */\n\trawDrain(): void {\n\t\tconst pending = this.#pending;\n\t\tif (!pending) return;\n\t\tconst written = Math.max(this.#raw.write(pending.bytes), 0);\n\t\tif (written < pending.bytes.length) {\n\t\t\tpending.bytes = pending.bytes.subarray(written);\n\t\t\treturn;\n\t\t}\n\t\tthis.#pending = undefined;\n\t\tpending.done();\n\t}\n\n\t#send(chunk: Uint8Array, done: () => void): void {\n\t\tconst written = Math.max(this.#raw.write(chunk), 0);\n\t\tif (written < chunk.length) {\n\t\t\tthis.#pending = { bytes: chunk.subarray(written), done };\n\t\t} else done();\n\t}\n\n\twrite(bytes: Uint8Array): number {\n\t\tif (this.#tls.destroyed || this.#tls.writableNeedDrain) return 0;\n\t\tthis.#tls.write(bytes);\n\t\treturn bytes.length;\n\t}\n\n\t/**\n\t * Ends TLS — a close_notify after everything written — then the raw\n\t * socket, as `shutdown(halfClose)` would. Nothing written is lost, so\n\t * the two differ only in the raw socket's close.\n\t */\n\tshutdown(halfClose = false): void {\n\t\tthis.#halfClose = halfClose;\n\t\t// TLS ended — its close_notify written to the wire — ends the wire too,\n\t\t// which closes the raw socket once what it holds has left: waiting for\n\t\t// the client's own close_notify would hold a client that stopped\n\t\t// reading for as long as it likes.\n\t\tthis.#tls.once('finish', () => this.#wire.end());\n\t\tthis.#tls.end();\n\t}\n\n\tterminate(): void {\n\t\tthis.#pending = undefined;\n\t\tthis.#tls.destroy();\n\t\tthis.#raw.terminate();\n\t}\n\n\t/** The raw socket closed: TLS has nowhere to go. */\n\tclosed(): void {\n\t\tthis.#pending = undefined;\n\t\tthis.#tls.destroy();\n\t}\n\n\tpause(): void {\n\t\tthis.#raw.pause();\n\t}\n\n\tresume(): void {\n\t\tthis.#raw.resume();\n\t}\n\n\ttimeout(seconds: number): void {\n\t\tthis.#raw.timeout(seconds);\n\t}\n}\n",
25
+ "import type { SecureContext } from 'node:tls';\nimport type { Socket, SocketHandler } from 'bun';\nimport { clientKey } from './client-key';\nimport { Connection } from './connection';\nimport { received, type SocketState, transportOf, turnAway } from './listener';\nimport { HeaderReader } from './proxy/reader';\nimport { ProxiedTls } from './proxy/tls';\nimport type { RawSocket } from './raw-socket';\nimport type { Settings } from './settings';\nimport type { Slots } from './slots';\n\n/**\n * The listener's own handlers: `open` counts a socket and greets it or\n * turns it away, `handshake` lets implicit TLS start once encrypted,\n * `close` frees the slot.\n *\n * Behind a trusted proxy (`proxyProtocol`), `open` only starts reading the\n * header: the socket is counted, by the client's address, once the header\n * named it. On implicit TLS with `proxyProtocol`, the listener is a clear\n * one and `proxied` is the TLS context: every socket's TLS runs through\n * `ProxiedTls`, after the header from a trusted proxy, from the first byte\n * from anyone else.\n */\nexport interface Listening {\n\treadonly settings: Settings;\n\treadonly slots: Slots<Connection>;\n\t/** Sockets still in their handshake or awaiting a PROXY header, for `stop(true)`. */\n\treadonly handshaking: Set<Socket<SocketState>>;\n\t/** TLS from the first byte: implicit TLS. */\n\treadonly secure: boolean;\n\treadonly proxied?: SecureContext;\n}\n\nexport function listenerHandlers(\n\tlistening: Listening,\n): Pick<SocketHandler<SocketState>, 'open' | 'handshake' | 'close'> {\n\tconst { settings, slots, handshaking, secure } = listening;\n\treturn {\n\t\t// With a `handshake` handler, Bun calls `open` on implicit TLS\n\t\t// as soon as TCP connects; without one, only once the\n\t\t// handshake completed, so a client that never sends its\n\t\t// ClientHello would be counted by no limit and bounded by no\n\t\t// timer.\n\t\topen(socket) {\n\t\t\tsocket.data = { upgraded: false, handshaking: secure };\n\t\t\tsocket.timeout(secure ? settings.handshakeTimeout : settings.timeout);\n\t\t\tconst peer = socket.remoteAddress;\n\t\t\tif (settings.trusts?.(peer)) awaitHeader(listening, socket, peer);\n\t\t\telse admit(listening, socket, peer);\n\t\t},\n\t\thandshake: (socket, success) => handshake(listening, socket, success),\n\t\tclose(socket) {\n\t\t\thandshaking.delete(socket);\n\t\t\tsocket.data?.header?.cancel();\n\t\t\tsocket.data?.tls?.closed();\n\t\t\tconst connection = socket.data?.connection;\n\t\t\tif (connection) slots.release(connection);\n\t\t\tsocket.data?.transport?.closed();\n\t\t\tconnection?.close();\n\t\t},\n\t};\n}\n\nfunction handshake(\n\t{ settings, handshaking }: Listening,\n\tsocket: Socket<SocketState>,\n\tsuccess: boolean,\n): void {\n\tconst state = socket.data;\n\tif (!state?.handshaking) return;\n\thandshaking.delete(socket);\n\t// A failed handshake: Bun closes the socket, and `close` counts it out.\n\tif (!success) return;\n\tstate.handshaking = false;\n\tsocket.timeout(settings.timeout);\n\tconst start = state.start;\n\tdelete state.start;\n\tstart?.();\n}\n\n/**\n * A trusted proxy's socket: its header first, within `handshakeTimeout`\n * however slowly it comes, or the socket is reset — nothing written,\n * nothing reported, nothing counted. The proxy's own address is never a\n * client's: no limit counts the socket before the header named one.\n */\nfunction awaitHeader(\n\tlistening: Listening,\n\tsocket: Socket<SocketState>,\n\tpeer: string,\n): void {\n\tconst { settings, handshaking, secure } = listening;\n\tsocket.data.handshaking = true;\n\tsocket.timeout(settings.handshakeTimeout);\n\thandshaking.add(socket);\n\tsocket.data.header = new HeaderReader(\n\t\tsettings.handshakeTimeout,\n\t\t(source, rest) => {\n\t\t\tdelete socket.data.header;\n\t\t\thandshaking.delete(socket);\n\t\t\tsocket.data.handshaking = secure;\n\t\t\tif (!secure) socket.timeout(settings.timeout);\n\t\t\tadmit(listening, socket, source ?? peer, rest);\n\t\t},\n\t\t() => socket.terminate(),\n\t);\n}\n\n/** Counts the socket as the client at `address`, then greets it or turns it away. */\nfunction admit(\n\tlistening: Listening,\n\tsocket: Socket<SocketState>,\n\taddress: string,\n\tfirst?: Uint8Array,\n): void {\n\tconst { settings, slots, handshaking, secure, proxied } = listening;\n\tlet raw: RawSocket = socket;\n\tif (proxied) {\n\t\traw = startTls(listening, socket, proxied);\n\t\tif (first && first.length > 0) socket.data.tls?.receive(first);\n\t}\n\tconst begin = (start: () => void) => {\n\t\tif (!secure) return start();\n\t\thandshaking.add(socket);\n\t\tsocket.data.start = start;\n\t};\n\tconst { hostname } = settings.options;\n\tconst refuse = (line: string) =>\n\t\tbegin(() => turnAway(socket, raw, secure, `${line}\\r\\n`));\n\tif (slots.size >= settings.maxConnections) {\n\t\trefuse(`421 4.3.2 ${hostname} Too many connections, try later`);\n\t\treturn;\n\t}\n\tconst key = clientKey(address);\n\tif (slots.of(key) >= settings.maxConnectionsPerClient) {\n\t\trefuse(\n\t\t\t`421 4.7.0 ${hostname} Too many connections from your address, try later`,\n\t\t);\n\t\treturn;\n\t}\n\tconst transport = transportOf(socket, raw, address, settings, secure, slots);\n\tconst connection = new Connection(settings, transport);\n\tslots.take(connection, key);\n\tsocket.data.connection = connection;\n\t// What the client sent behind the header, before its greeting.\n\tif (first && first.length > 0 && !proxied) {\n\t\treceived(socket, settings, first);\n\t}\n\tbegin(() => void connection.open());\n}\n\n/** Implicit TLS behind `proxyProtocol`: `node:tls` over the raw socket, bounded by `handshakeTimeout`. */\nfunction startTls(\n\tlistening: Listening,\n\tsocket: Socket<SocketState>,\n\tcontext: SecureContext,\n): ProxiedTls {\n\tconst { settings } = listening;\n\tsocket.data.handshaking = true;\n\tsocket.timeout(settings.handshakeTimeout);\n\tconst tls = new ProxiedTls(socket as Socket<unknown>, context, {\n\t\tsecure: () => handshake(listening, socket, true),\n\t\tdata: (bytes) => received(socket, settings, bytes),\n\t\tdrain: () => socket.data.transport?.drain(),\n\t});\n\tsocket.data.tls = tls;\n\treturn tls;\n}\n",
26
+ "import { addressBytes } from './address';\n\n/** One entry of `trusted`: a network, as its bytes and how many of its bits count. */\ninterface Network {\n\treadonly bytes: Uint8Array;\n\treadonly bits: number;\n}\n\n/** An entry as a network, or why it is not one. */\nfunction networkOf(entry: unknown): Network | string {\n\tif (typeof entry !== 'string') return `${String(entry)} is not a string`;\n\tconst [address = '', prefix, extra] = entry.split('/');\n\tconst raw = addressBytes(address);\n\tif (!raw || extra !== undefined) {\n\t\treturn `\"${entry}\" is neither an IP address nor a CIDR`;\n\t}\n\t// `::ffff:10.0.0.0/104` is `10.0.0.0/8`: the address became its IPv4 bytes.\n\tconst mapped = raw.length === 4 && address.includes(':');\n\tconst width = raw.length * 8;\n\tif (prefix === undefined) return { bytes: raw, bits: width };\n\tlet bits = /^\\d{1,3}$/.test(prefix) ? Number(prefix) : -1;\n\tif (mapped) bits -= 96;\n\tif (bits < 0 || bits > width) {\n\t\treturn `\"${entry}\" has a prefix length out of range`;\n\t}\n\tif (bits === 0) {\n\t\treturn `\"${entry}\" has a prefix length of 0, which trusts every peer`;\n\t}\n\treturn { bytes: raw, bits };\n}\n\nfunction contains(network: Network, address: Uint8Array): boolean {\n\tif (network.bytes.length !== address.length) return false;\n\tconst whole = network.bits >> 3;\n\tfor (let at = 0; at < whole; at++) {\n\t\tif (network.bytes[at] !== address[at]) return false;\n\t}\n\tconst rest = network.bits & 7;\n\tif (rest === 0) return true;\n\tconst mask = (0xff << (8 - rest)) & 0xff;\n\treturn (\n\t\t((network.bytes[whole] as number) & mask) ===\n\t\t((address[whole] as number) & mask)\n\t);\n}\n\n/**\n * `proxyProtocol.trusted` as a test of a peer's address: IPv4 and IPv6\n * addresses and CIDRs, an IPv4-mapped address or peer matched as its IPv4\n * address. An entry that is neither throws, through `invalid`, and so does\n * an empty list (it would trust nobody, which is no proxy at all), a zone\n * (`fe80::1%eth0`) and a prefix of 0, which would trust everyone.\n */\nexport function trustedPeers(\n\tentries: unknown,\n\tinvalid: (message: string) => Error,\n): (peer: string) => boolean {\n\tif (!Array.isArray(entries) || entries.length === 0) {\n\t\tthrow invalid(\n\t\t\t'proxyProtocol.trusted must list the addresses or CIDRs of the proxies, at least one',\n\t\t);\n\t}\n\tconst networks = entries.map((entry: unknown) => {\n\t\tconst network = networkOf(entry);\n\t\tif (typeof network === 'string') {\n\t\t\tthrow invalid(`proxyProtocol.trusted: ${network}`);\n\t\t}\n\t\treturn network;\n\t});\n\treturn (peer) => {\n\t\tconst address = addressBytes(peer);\n\t\treturn (\n\t\t\taddress !== undefined &&\n\t\t\tnetworks.some((network) => contains(network, address))\n\t\t);\n\t};\n}\n",
27
+ "import { SmtpError } from '../errors';\nimport type { SmtpServerOptions } from './options';\nimport { trustedPeers } from './proxy/trusted';\n\n/** The options with their defaults, checked once. */\nexport interface Settings {\n\treadonly options: SmtpServerOptions;\n\treadonly mode: 'mx' | 'submission';\n\treadonly maxMessageSize: number;\n\treadonly maxRecipients: number;\n\treadonly maxConnections: number;\n\treadonly maxConnectionsPerClient: number;\n\treadonly maxErrors: number;\n\treadonly timeout: number;\n\treadonly hookTimeout: number;\n\treadonly handshakeTimeout: number;\n\treadonly greetingDelay: number;\n\t/** With `proxyProtocol`: whether a peer is a proxy trusted to send a PROXY header. */\n\treadonly trusts?: (peer: string) => boolean;\n\tisLocal(domain: string): boolean | Promise<boolean>;\n}\n\n/** The longest delay `setTimeout` takes, in whole seconds: past 2^31 − 1 ms it fires after 1 ms. */\nconst MAX_TIMER_SECONDS = Math.floor(2_147_483_647 / 1000);\n\nconst invalid = (message: string) =>\n\tnew SmtpError('INVALID_OPTION', `createSmtpServer(): ${message}`);\n\nfunction positive(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tif (value === undefined) return fallback;\n\tif (!Number.isSafeInteger(value) || value < 1) {\n\t\tthrow invalid(`${name} must be a positive integer, not ${value}`);\n\t}\n\treturn value;\n}\n\n/** `positive`, and short enough for `setTimeout`, which a longer delay makes fire at once. */\nfunction timer(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tconst seconds = positive(name, value, fallback);\n\tif (seconds > MAX_TIMER_SECONDS) {\n\t\tthrow invalid(\n\t\t\t`${name} must be at most ${MAX_TIMER_SECONDS} seconds, not ${seconds}`,\n\t\t);\n\t}\n\treturn seconds;\n}\n\nfunction nonNegative(\n\tname: string,\n\tvalue: number | undefined,\n\tfallback: number,\n): number {\n\tif (value === undefined) return fallback;\n\tif (!Number.isFinite(value) || value < 0) {\n\t\tthrow invalid(\n\t\t\t`${name} must be a number of seconds, 0 or more, not ${value}`,\n\t\t);\n\t}\n\treturn value;\n}\n\n/** `localDomains` as a lookup; the domain it is given is lower case. */\nfunction localLookup(\n\tlocal: SmtpServerOptions['localDomains'],\n): (domain: string) => boolean | Promise<boolean> {\n\tif (typeof local === 'function') return local;\n\tif (\n\t\tArray.isArray(local) &&\n\t\tlocal.every((domain: unknown) => typeof domain === 'string')\n\t) {\n\t\tconst domains = new Set(\n\t\t\t(local as readonly string[]).map((domain) => domain.toLowerCase()),\n\t\t);\n\t\treturn (domain) => domains.has(domain);\n\t}\n\tthrow invalid('localDomains must be an array of domains or a function');\n}\n\nexport function settingsOf(options: SmtpServerOptions): Settings {\n\tif (\n\t\ttypeof options.hostname !== 'string' ||\n\t\t!/^[A-Za-z0-9.-]+$/.test(options.hostname)\n\t) {\n\t\tthrow invalid(`\"${options.hostname}\" is not a host name`);\n\t}\n\tif (typeof options.onData !== 'function') {\n\t\tthrow invalid('onData must be a function: it is where messages go');\n\t}\n\tif (options.implicitTls && !options.tls) {\n\t\tthrow invalid('implicitTls needs tls: { key, cert }');\n\t}\n\tif (options.mode === 'submission' && !options.authenticate) {\n\t\tthrow invalid(\n\t\t\t'submission takes mail only from authenticated users, so it needs authenticate',\n\t\t);\n\t}\n\tif (options.authenticate && !options.tls) {\n\t\tthrow invalid(\n\t\t\t'authenticate needs tls: { key, cert }, since AUTH is offered only once encrypted',\n\t\t);\n\t}\n\tconst isLocal = localLookup(options.localDomains);\n\tconst timeout = positive('timeout', options.timeout, 300);\n\tconst greetingDelay = nonNegative('greetingDelay', options.greetingDelay, 0);\n\tif (greetingDelay >= timeout) {\n\t\tthrow invalid(\n\t\t\t`greetingDelay (${greetingDelay} s) must be shorter than timeout (${timeout} s), or every client times out before the greeting`,\n\t\t);\n\t}\n\treturn {\n\t\toptions,\n\t\tmode: options.mode ?? 'mx',\n\t\tmaxMessageSize: positive(\n\t\t\t'maxMessageSize',\n\t\t\toptions.maxMessageSize,\n\t\t\t25 * 1024 * 1024,\n\t\t),\n\t\tmaxRecipients: positive('maxRecipients', options.maxRecipients, 100),\n\t\tmaxConnections: positive('maxConnections', options.maxConnections, 1000),\n\t\tmaxConnectionsPerClient: positive(\n\t\t\t'maxConnectionsPerClient',\n\t\t\toptions.maxConnectionsPerClient,\n\t\t\t10,\n\t\t),\n\t\tmaxErrors: positive('maxErrors', options.maxErrors, 10),\n\t\ttimeout,\n\t\thookTimeout: timer('hookTimeout', options.hookTimeout, 60),\n\t\thandshakeTimeout: positive(\n\t\t\t'handshakeTimeout',\n\t\t\toptions.handshakeTimeout,\n\t\t\t10,\n\t\t),\n\t\tgreetingDelay,\n\t\t...(options.proxyProtocol === undefined\n\t\t\t? {}\n\t\t\t: { trusts: trustedPeers(options.proxyProtocol?.trusted, invalid) }),\n\t\tisLocal: (domain) => isLocal(domain.toLowerCase()),\n\t};\n}\n",
28
+ "/**\n * The connections a server holds, and how many each client holds, by\n * `clientKey`. `release` is idempotent: every close handler calls it.\n */\nexport class Slots<T> {\n\treadonly #open = new Map<T, string | undefined>();\n\treadonly #perClient = new Map<string, number>();\n\n\tget size(): number {\n\t\treturn this.#open.size;\n\t}\n\n\t/** How many connections the client `key` holds. */\n\tof(key: string | undefined): number {\n\t\treturn key === undefined ? 0 : (this.#perClient.get(key) ?? 0);\n\t}\n\n\ttake(connection: T, key: string | undefined): void {\n\t\tthis.#open.set(connection, key);\n\t\tif (key !== undefined) this.#perClient.set(key, this.of(key) + 1);\n\t}\n\n\trelease(connection: T): void {\n\t\tif (!this.#open.has(connection)) return;\n\t\tconst key = this.#open.get(connection);\n\t\tthis.#open.delete(connection);\n\t\tif (key === undefined) return;\n\t\tconst left = this.of(key) - 1;\n\t\tif (left > 0) this.#perClient.set(key, left);\n\t\telse this.#perClient.delete(key);\n\t}\n\n\tconnections(): T[] {\n\t\treturn [...this.#open.keys()];\n\t}\n}\n",
29
+ "import { createSecureContext, type SecureContext } from 'node:tls';\n\n/** `key` or `cert` as `Bun.listen` takes them: text, bytes or a file. */\ntype TlsMaterial = string | Uint8Array | Bun.BunFile;\n\n/**\n * `tls` read whole — a file included — and checked as a `node:tls` context:\n * what implicit TLS behind a proxy runs on, and, without a proxy, the check\n * that makes a key or certificate that cannot be read or used fail\n * `listen()` the same way. `fail` turns the reason into the package's own\n * error, the `node:tls` or file error as its `cause`.\n */\nexport async function tlsContext(\n\ttls: { readonly key: TlsMaterial; readonly cert: TlsMaterial },\n\tfail: (message: string, cause: unknown) => Error,\n): Promise<SecureContext> {\n\tconst read = async (value: TlsMaterial) =>\n\t\ttypeof value === 'string'\n\t\t\t? value\n\t\t\t: Buffer.from(value instanceof Uint8Array ? value : await value.bytes());\n\ttry {\n\t\treturn createSecureContext({\n\t\t\tkey: await read(tls.key),\n\t\t\tcert: await read(tls.cert),\n\t\t});\n\t} catch (cause) {\n\t\tconst reason = cause instanceof Error ? cause.message : String(cause);\n\t\tthrow fail(`listen(): tls: { key, cert } cannot be used: ${reason}`, cause);\n\t}\n}\n",
30
+ "import type { Socket, TCPSocketListener } from 'bun';\nimport { SmtpError } from '../errors';\nimport { type Listening, listenerHandlers } from './admission';\nimport type { Connection } from './connection';\nimport { handlers, type SocketState } from './listener';\nimport type { SmtpServerOptions } from './options';\nimport { settingsOf } from './settings';\nimport { Slots } from './slots';\nimport { tlsContext } from './tls-context';\n\n/** A key or certificate `listen` cannot use: `INVALID_OPTION`, the reason as its `cause`. */\nconst invalidTls = (message: string, cause: unknown) =>\n\tnew SmtpError('INVALID_OPTION', message, { cause });\n\n/** What a `listen` that a `stop()` came before says. */\nconst STOPPED = 'listen(): stop() was called before the server bound its port';\n\n/** Binds the port, once `listen`'s guard passed. */\nasync function bind(\n\toptions: SmtpServerOptions,\n\tlistening: Omit<Listening, 'proxied'>,\n\tport: number,\n\thostname: string,\n\tstopped: () => boolean,\n): Promise<TCPSocketListener<SocketState>> {\n\t// Implicit TLS: the key and certificate are checked first, so one\n\t// that cannot be used fails here alike, with a proxy or without.\n\tconst context =\n\t\tlistening.secure && options.tls\n\t\t\t? await tlsContext(options.tls, invalidTls)\n\t\t\t: undefined;\n\t// `stop()` came while the key was being read: nothing is bound.\n\tif (stopped()) {\n\t\tthrow new SmtpError('STOPPED', STOPPED);\n\t}\n\t// Behind a proxy: a clear listener, TLS after the header.\n\tconst proxied = listening.settings.trusts ? context : undefined;\n\treturn Bun.listen<SocketState>({\n\t\thostname,\n\t\tport,\n\t\t...(listening.secure && options.tls && !proxied\n\t\t\t? { tls: { key: options.tls.key, cert: options.tls.cert } }\n\t\t\t: {}),\n\t\tsocket: {\n\t\t\t...handlers(listening.settings),\n\t\t\t...listenerHandlers({\n\t\t\t\t...listening,\n\t\t\t\t...(proxied ? { proxied } : {}),\n\t\t\t}),\n\t\t},\n\t});\n}\n\nexport interface SmtpServer {\n\t/** Starts listening; resolves once the port is bound. Once only: a second call throws. */\n\tlisten(options: {\n\t\tport: number;\n\t\thostname?: string;\n\t}): Promise<{ port: number; hostname: string }>;\n\t/** Stops listening; `closeConnections` hangs up on every client too. */\n\tstop(closeConnections?: boolean): void;\n\t/** Open connections. */\n\treadonly connections: number;\n}\n\n/**\n * An SMTP server (RFC 5321) on `Bun.listen`: EHLO with PIPELINING, SIZE,\n * 8BITMIME, SMTPUTF8 and ENHANCEDSTATUSCODES; STARTTLS (RFC 3207) or\n * implicit TLS (RFC 8314); AUTH PLAIN and LOGIN over TLS only (RFC 4954);\n * policy through hooks. It never relays without AUTH: a recipient outside\n * `localDomains` is refused to an unauthenticated session, whatever the\n * hooks say.\n */\nexport function createSmtpServer(options: SmtpServerOptions): SmtpServer {\n\tconst settings = settingsOf(options);\n\tlet listener: TCPSocketListener<SocketState> | undefined;\n\tconst slots = new Slots<Connection>();\n\t/** Implicit TLS sockets still in their handshake, for `stop(true)`. */\n\tconst handshaking = new Set<Socket<SocketState>>();\n\tconst secure = options.implicitTls === true;\n\t/** `listen` has not resolved yet: it may be reading the TLS material, before it binds. */\n\tlet starting = false;\n\t/** `stop()` was called while `starting`: `listen` leaves nothing bound. */\n\tlet stopRequested = false;\n\treturn {\n\t\tget connections() {\n\t\t\treturn slots.size;\n\t\t},\n\t\tasync listen({ port, hostname = '0.0.0.0' }) {\n\t\t\tif (listener || starting) {\n\t\t\t\tthrow new SmtpError(\n\t\t\t\t\t'ALREADY_LISTENING',\n\t\t\t\t\tlistener\n\t\t\t\t\t\t? `listen(): the server is already listening on ${listener.hostname}:${listener.port}`\n\t\t\t\t\t\t: 'listen(): the server is already starting to listen',\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Set before the first await: a second call meanwhile throws, never binds.\n\t\t\tstarting = true;\n\t\t\tstopRequested = false;\n\t\t\ttry {\n\t\t\t\tconst bound = await bind(\n\t\t\t\t\toptions,\n\t\t\t\t\t{ settings, slots, handshaking, secure },\n\t\t\t\t\tport,\n\t\t\t\t\thostname,\n\t\t\t\t\t() => stopRequested,\n\t\t\t\t);\n\t\t\t\t// `stop()` came before `listen` resolved: nothing is left listening.\n\t\t\t\tif (stopRequested) {\n\t\t\t\t\tbound.stop(true);\n\t\t\t\t\tthrow new SmtpError('STOPPED', STOPPED);\n\t\t\t\t}\n\t\t\t\tlistener = bound;\n\t\t\t\treturn { port: listener.port, hostname: listener.hostname };\n\t\t\t} finally {\n\t\t\t\tstarting = false;\n\t\t\t}\n\t\t},\n\t\tstop(closeConnections = false) {\n\t\t\tif (starting) stopRequested = true;\n\t\t\tlistener?.stop(closeConnections);\n\t\t\tlistener = undefined;\n\t\t\tif (!closeConnections) return;\n\t\t\t// Bun's `stop(true)` closes the sockets the listener holds, and a\n\t\t\t// socket STARTTLS moved to TLS is no longer one of them: hang up on\n\t\t\t// every connection here, as a timeout does. A socket still in its\n\t\t\t// handshake has no TLS to say 421 on: it is reset.\n\t\t\tconst stuck = new Set<Connection | undefined>();\n\t\t\tfor (const socket of [...handshaking]) {\n\t\t\t\tstuck.add(socket.data?.connection);\n\t\t\t\thandshaking.delete(socket);\n\t\t\t\tsocket.terminate();\n\t\t\t}\n\t\t\tfor (const connection of slots.connections()) {\n\t\t\t\tif (!stuck.has(connection)) connection.close();\n\t\t\t}\n\t\t},\n\t};\n}\n"
21
31
  ],
22
- "mappings": ";;;;;;;;;;AAQO,SAAS,YAAY,CAAC,MAAuB;AAAA,EACnD,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAAA,EAC9B,IAAI,QAAQ;AAAA,IAAG,OAAO,EAAE,MAAM,KAAK,YAAY,GAAG,UAAU,GAAG;AAAA,EAC/D,OAAO;AAAA,IACN,MAAM,KAAK,MAAM,GAAG,KAAK,EAAE,YAAY;AAAA,IACvC,UAAU,KAAK,MAAM,QAAQ,CAAC,EAAE,KAAK;AAAA,EACtC;AAAA;AAeM,SAAS,gBAAgB,CAC/B,UACA,SAC0B;AAAA,EAC1B,MAAM,QAAQ,IAAI,OAAO,IAAI,8BAA8B,GAAG,EAAE,KAC/D,QACD;AAAA,EACA,IAAI,CAAC;AAAA,IAAO;AAAA,EACZ,MAAM,OAAO,WAAU,MAAM,IAAc,YAAY,MAAM;AAAA,EAC7D,IAAI,CAAC;AAAA,IAAM;AAAA,EACX,MAAM,aAAqC,CAAC;AAAA,EAC5C,WAAW,QAAS,MAAM,GAAc,KAAK,EAAE,MAAM,KAAK,GAAG;AAAA,IAC5D,IAAI,SAAS;AAAA,MAAI;AAAA,IACjB,MAAM,SAAS,KAAK,QAAQ,GAAG;AAAA,IAC/B,MAAM,OAAO,SAAS,IAAI,OAAO,KAA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