/** * Content first API. * * `extract()` takes a raw RFC 5322 message and does its own MIME parsing. Most callers do not have * one: they have already parsed the message, with mailparser, postal-mime, EmailEngine or an IMAP * client, and hold `{ text, html, subject }`. Re-serialising that back into a message just to parse * it again would be wasteful and lossy. * * `analyze()` is the same pipeline entered one stage later. Stage 1 is skipped, Stages 2 to 8 are * identical, and the result has the same shape. Everything the extractor decides is derived from * the bodies themselves, so nothing is lost by not having the envelope. */ import { type ConfidenceConfig } from './classify/confidence'; import { type HistoryDocument } from './match/history'; import { type ContentAnalysisResult, type Reason } from './types'; /** * One structurally independent piece of a message body. * * A `multipart/mixed` message can carry several. The commonest shape in the working corpus, * `multipart/mixed(alternative(P,H), P)` at 3.1 percent of 320,377 messages, is an authored body * followed by a separately encoded gateway footer. They are not alternative renderings of each * other, and choosing between them deletes one. * * `text` and `html` within one section *are* alternative renderings, and at most one of them * reaches the output. */ export interface BodySection { /** Plain text of this section, already transfer and charset decoded. */ text?: string | null; /** HTML of this section, already transfer and charset decoded. */ html?: string | null; /** MIME part ids, when the caller knows them, purely for traceability in the output. */ textPartId?: string; htmlPartId?: string; /** * Where the section sits. Derived internally by `extract()`; optional for external callers, who * may supply at most one `primary`. Evidence only: an appended section is classified normally, * because gateways append substantive text as often as they append disclaimers. */ role?: 'primary' | 'appended'; } /** A message body, in whichever representations are available. */ export interface MessageContent { /** Plain text body, already transfer and charset decoded. */ text?: string | null; /** HTML body, already transfer and charset decoded. */ html?: string | null; /** * Ordered body sections, when the message has more than one. * * Array position is the canonical order; there is deliberately no second ordering field to * disagree with it. Mutually exclusive with the single `text`/`html`/`textPartId`/`htmlPartId` * fields above, which are sugar for exactly one section. Supplying both is rejected rather than * guessed at. * * This is the shared path, not an `extract()` private. Building multi section composition * inside `extract()` would give the raw message entry point a capability the content first one * cannot express, and the two entry points must not be able to disagree about the same message. */ sections?: readonly BodySection[]; /** Subject line. Optional, and never allowed to change a label on its own. */ subject?: string | null; /** Sender, as a display name and/or address. Used only as signature evidence. */ from?: string | null; /** Threading hints. Optional, used only to note whether the message looks like a reply. */ inReplyTo?: string | null; references?: readonly string[]; /** MIME part ids, when the caller knows them, purely for traceability in the output. */ textPartId?: string; htmlPartId?: string; } export interface AnalyzeOptions { confidence?: Partial; /** * Maximum characters of body content analysed, across every section. Default 8,000,000. * * A circuit breaker for the content first entry point, where there is no raw message to bound. * Sections past the limit are not analysed and the result carries `input_limit_exceeded`. */ maxContentChars?: number; /** * Earlier messages in the thread, nearest first. Each may be raw RFC 5322 or already split * content. History is optional and only ever adds evidence. */ history?: readonly (MessageContent | string | Buffer)[]; /** Pre-built history documents, for callers that resolve and cache threads themselves. */ historyDocuments?: readonly HistoryDocument[]; explain?: boolean; } /** * Result of analysing one message body. * * Extends the shared contract rather than restating it, so the two entry points cannot drift apart * again. `extract()` used to build its own object and silently drop `isReply`. */ export interface AnalyzeResult extends ContentAnalysisResult { diagnostics?: { primaryPart: string | null; blocks: { index: number; /** MIME part and section-local index, the coordinates stored annotations use. */ mimePart: string; sourceIndex: number; kind: string; label: string; confidence: number; reasons: Reason[]; evidence: { id: string; kind: string; strength: number; }[]; features: Record; preview: string; }[]; }; } /** * Name tokens from a From header, for signature detection. * * Takes the display name words and the address local part, keeping tokens long enough to be * distinctive. Short tokens are dropped because a two letter name fragment matches everywhere. */ export declare function senderTokensFrom(from: string | null | undefined): string[]; /** Turn whatever the caller supplied as history into searchable documents. */ export declare function resolveHistory(options: AnalyzeOptions): Promise; /** * Analyse an already parsed message body. * * Never throws. A body that cannot be segmented is returned whole as a single visible `UNKNOWN` * segment, because showing too much is always preferable to showing nothing. * * Segment offsets from a plain text part index its canonical text, which the result carries as * `canonicalText[mimePart]`, so a caller can slice exactly what it was given. */ export declare function analyze(content: MessageContent, options?: AnalyzeOptions): Promise; //# sourceMappingURL=analyze.d.ts.map