import type { HandlerContext } from './derived-core.js'; import type { TwinStream } from './twin-fetch.js'; /** What a server's front answers the stream: its reply lines, the moved session, and whether the stream reads a * message's data next (`data`), an AUTH response (`auth`) or commands, or closes. */ export type SmtpAnswer = { replies: string[]; session: S; mode: 'command' | 'data' | 'auth'; close?: boolean; }; /** The bridge between a connection and the pack's front: the header that carries the pack's key, the key, a fresh * session, and the pack's answer when its front cannot answer (its words for a local error). */ export type SmtpBridge = { header: string; key: () => string; fresh: () => S; failure: (session: S) => SmtpAnswer; }; /** A connection's bytes framed as SMTP frames them, each piece posted to the pack's front (`smtpFront`) through its * fetch with the session the connection carries: commands are lines ended by CRLF; after a 354, the message's lines up * to the lone dot, their leading dot removed; after a 334, one line of AUTH response. Pipelined commands are answered * in order. */ export declare function smtpStream(fetch: (request: Request) => Response | Promise, bridge: SmtpBridge): TwinStream; /** What a pack's front does with each piece the stream carries: the greeting, a command line, a message's data, an AUTH * response (a server that takes none leaves it out). */ type SmtpServer = { open(): SmtpAnswer | Promise>; command(session: S, line: string): SmtpAnswer | Promise>; data(session: S, data: string): SmtpAnswer | Promise>; response?(session: S, response: string): SmtpAnswer | Promise>; }; /** The pack's front (its `around`): a request the stream signed with the pack's key is a piece of a connection, answered * by the pack's server; any other request is the pack's own (its doors and screens). */ export declare function smtpFront(ctx: HandlerContext, next: (request?: Request) => Promise, bridge: SmtpBridge, server: SmtpServer): Promise; /** A command's verb (upper-cased) and its argument. */ export declare function smtpCommand(line: string): { verb: string; arg: string; }; /** The session machine's word on a command from where a session stands (the manifest's states): a refusal's reply, or * undefined to go on. */ export declare function smtpOrder(ctx: Pick, machine: string, stage: string, op: string, to?: string): string | undefined; /** EHLO's multi-line 250 reply: the server's name, then each keyword. */ export declare const smtpEhlo: (keywords: string[]) => string[]; /** An address's domain, lower-cased. */ export declare const smtpDomain: (address: string) => string; /** MAIL's argument: the sender and its SIZE, BODY and SMTPUTF8 parameters, or why it is refused (the pack words it). */ export declare function smtpMailFrom(arg: string): { from: string; size?: number; smtputf8: boolean; } | { refused: 'syntax' | 'sender' | 'size'; } | { refused: 'parameter'; parameter: string; }; /** RCPT's argument: the recipient, or why it is refused (the pack words it). */ export declare function smtpRcptTo(arg: string): { to: string; } | { refused: 'syntax' | 'recipient'; } | { refused: 'parameter'; parameter: string; }; /** A transaction's state cleared, the greeting kept (RSET, a new EHLO, the end of DATA): the session's `stage`, * `greeted` and an empty `rcpt`, with whatever of the session the pack keeps across transactions (`kept`). */ export declare function smtpCleared(s: S, stage: string, kept: Omit): Omit & { stage: string; rcpt: string[]; greeted?: 'helo' | 'ehlo'; }; export {};