import type { Email } from "@/lib/jmap/types"; import { buildForwardSubject } from "@/lib/subject-prefix"; import { emailExportFilename } from "@/lib/download-filename"; export interface ForwardAsAttachmentEntry { blobId: string; name: string; type: "message/rfc822"; size: number; } export interface ForwardAsAttachmentPayload { subject: string; attachment: ForwardAsAttachmentEntry; } /** * Build the subject and synthetic attachment entry for forwarding a * message as a message/rfc822 attachment instead of inline-quoted text * (e.g. reporting spam to an upstream gateway that expects the raw * original as an attachment, or preserving exact formatting/headers). * * Referenced by blobId, not re-uploaded - JMAP blobs are account-scoped, * not per-email, so the same blobId a message already has can be attached * to a brand new outgoing email directly. * * Returns null when the email has no blobId (nothing to reference). */ export function buildForwardAsAttachmentPayload( email: Email, forwardPrefix: string, ): ForwardAsAttachmentPayload | null { if (!email.blobId) return null; return { subject: buildForwardSubject(email.subject, forwardPrefix), attachment: { blobId: email.blobId, name: emailExportFilename(email), type: "message/rfc822", size: email.size, }, }; }