84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
import type { EmailMailboxProvider } from "./mailbox-list.vm.js";
|
|
import type { EmailLinkBadge } from "./inbox-list.vm.js";
|
|
|
|
/**
|
|
* VA-P23 · message/thread detail view-model (M09 Block F detail). Pure: the
|
|
* loader sanitizes the bodies SERVER-SIDE (emailHtmlSanitizer) and passes the
|
|
* safe HTML in — this VM never sees raw provider HTML. Thread = every mirror
|
|
* with the same providerThreadId, chronological; all but the focused message
|
|
* collapse by default.
|
|
*/
|
|
|
|
export interface EmailThreadMessageVM {
|
|
readonly id: string;
|
|
readonly direction: "inbound" | "outbound";
|
|
readonly fromName: string | null;
|
|
readonly fromAddress: string;
|
|
readonly toSummary: string;
|
|
readonly ccSummary: string | null;
|
|
readonly subject: string | null;
|
|
/** SANITIZED html (or escaped plain-text render) — safe to inject. */
|
|
readonly safeBodyHtml: string;
|
|
readonly blockedImageCount: number;
|
|
readonly sentAt: string;
|
|
readonly isRead: boolean;
|
|
readonly isFocused: boolean;
|
|
readonly collapsedByDefault: boolean;
|
|
}
|
|
|
|
export interface EmailAttachmentVM {
|
|
readonly attachmentId: string;
|
|
readonly filename: string;
|
|
readonly sizeBytes: number;
|
|
/** Set once imported into v1-Files (download runs via the Files auth-proxy). */
|
|
readonly importedFileId: string | null;
|
|
readonly downloadHref: string | null;
|
|
}
|
|
|
|
export interface EmailMatchStateVM {
|
|
readonly links: readonly EmailLinkBadge[];
|
|
readonly confidence: "high" | "medium" | "low" | "manual" | "none";
|
|
/** i18n key: auto-detected vs manually assigned hint (M09 Block F). */
|
|
readonly sourceKey: string;
|
|
readonly isManual: boolean;
|
|
}
|
|
|
|
export interface EmailMessageDetailData {
|
|
readonly focusedId: string;
|
|
readonly subject: string | null;
|
|
readonly mailbox: { readonly emailAddress: string; readonly provider: EmailMailboxProvider };
|
|
readonly thread: readonly EmailThreadMessageVM[];
|
|
readonly attachments: readonly EmailAttachmentVM[];
|
|
readonly match: EmailMatchStateVM;
|
|
readonly canWrite: boolean;
|
|
readonly replyHref: string;
|
|
readonly forwardHref: string;
|
|
readonly backHref: string;
|
|
readonly allowExternalImages: boolean;
|
|
}
|
|
|
|
export type EmailMessageDetailVM = VMState<EmailMessageDetailData>;
|
|
|
|
export function emailMatchSourceKey(confidence: EmailMatchStateVM["confidence"]): string {
|
|
return confidence === "manual" ? "emailInbox.detail.match.manual" : confidence === "none" ? "emailInbox.detail.match.none" : "emailInbox.detail.match.auto";
|
|
}
|
|
|
|
export function buildEmailMessageDetailVM(data: EmailMessageDetailData): EmailMessageDetailVM {
|
|
return { status: "ready", data };
|
|
}
|
|
|
|
/** Address list → compact display summary ("Max <max@x.de>, anna@y.de"). */
|
|
export function summarizeAddresses(list: unknown): string {
|
|
if (!Array.isArray(list)) return "";
|
|
return list
|
|
.map((entry) => {
|
|
if (!entry || typeof entry !== "object") return "";
|
|
const address = String((entry as { address?: unknown }).address ?? "");
|
|
const name = (entry as { name?: unknown }).name;
|
|
return typeof name === "string" && name.trim() ? `${name} <${address}>` : address;
|
|
})
|
|
.filter(Boolean)
|
|
.join(", ");
|
|
}
|