diff --git a/config/mail/content.ts b/config/mail/content.ts index 2a502f7..8d3044e 100644 --- a/config/mail/content.ts +++ b/config/mail/content.ts @@ -1,4 +1,8 @@ -import { Attachment, resolveAttachment } from "./attachments.ts"; +import { + Attachment, + resolveAttachment, + ResolvedAttachment, +} from "./attachments.ts"; import { quotedPrintableEncode } from "./encoding.ts"; export interface Content { @@ -8,7 +12,25 @@ export interface Content { relatedAttachments?: Attachment[]; } -export function resolveContent({ +export interface ResolvedContent { + mimeType: string; + content: string; + transferEncoding?: string; + relatedAttachments: ResolvedAttachment[]; +} + +export function resolveContent(content: Content): ResolvedContent { + return { + mimeType: content.mimeType, + content: content.content, + transferEncoding: content.transferEncoding, + relatedAttachments: content.relatedAttachments + ? content.relatedAttachments.map((v) => resolveAttachment(v)) + : [], + }; +} + +export function resolveMessage({ text, html, relatedAttachments, @@ -18,8 +40,8 @@ export function resolveContent({ html?: string; relatedAttachments?: Attachment[]; mimeContent?: Content[]; -}): Content[] { - const newContent = [...mimeContent ?? []]; +}): ResolvedContent[] { + const newContent = [...mimeContent ?? []].map((v) => resolveContent(v)); if (text === "auto" && html) { text = html @@ -33,22 +55,17 @@ export function resolveContent({ mimeType: 'text/plain; charset="utf-8"', content: quotedPrintableEncode(text), transferEncoding: "quoted-printable", + relatedAttachments: [], }); } if (html) { - const newMime: Content = { + newContent.push(resolveContent({ mimeType: 'text/html; charset="utf-8"', content: quotedPrintableEncode(html), transferEncoding: "quoted-printable", - }; - - if (relatedAttachments) { - newMime.relatedAttachments = relatedAttachments.map((attachment) => - resolveAttachment(attachment) - ); - } - newContent.push(newMime); + relatedAttachments, + })); } return newContent; diff --git a/config/mail/mod.ts b/config/mail/mod.ts index dd87936..a050ca5 100644 --- a/config/mail/mod.ts +++ b/config/mail/mod.ts @@ -3,7 +3,7 @@ import { resolveAttachment, ResolvedAttachment, } from "./attachments.ts"; -import { Content, resolveContent } from "./content.ts"; +import { Content, ResolvedContent, resolveMessage } from "./content.ts"; import { isSingleMail, mailList, @@ -49,7 +49,7 @@ export interface ResolvedSendConfig { from: saveMailObject; date: string; subject: string; - mimeContent: Content[]; + mimeContent: ResolvedContent[]; inReplyTo?: string; replyTo?: saveMailObject; references?: string; @@ -86,7 +86,7 @@ export function resolveSendConfig(config: SendConfig): ResolvedSendConfig { bcc: parseMailList(bcc), from: parseSingleEmail(from), date, - mimeContent: resolveContent({ + mimeContent: resolveMessage({ mimeContent, html, relatedAttachments,