diff --git a/src/main/providers/imap.provider.ts b/src/main/providers/imap.provider.ts index 43f7e7e..42a48ea 100644 --- a/src/main/providers/imap.provider.ts +++ b/src/main/providers/imap.provider.ts @@ -319,6 +319,7 @@ export class ImapProvider implements IEmailProvider { bcc: compose.bcc.length ? compose.bcc.join(', ') : undefined, subject: compose.subject, text: compose.body, + html: compose.htmlBody ? this.buildHtmlBody(compose) : undefined, inReplyTo: compose.inReplyTo, references: compose.references, attachments: compose.attachments?.map((a) => ({ path: a.path, filename: a.filename })) ?? [] @@ -367,6 +368,7 @@ export class ImapProvider implements IEmailProvider { bcc: compose.bcc.length ? compose.bcc.join(', ') : undefined, subject: compose.subject, text: compose.body, + html: compose.htmlBody ? this.buildHtmlBody(compose) : undefined, messageId, inReplyTo: compose.inReplyTo, references: compose.references, @@ -625,6 +627,36 @@ export class ImapProvider implements IEmailProvider { } } + /** + * Строит полный HTML-body письма: текст пользователя (→ HTML) + HTML-блокквота оригинала. + * compose.htmlBody содержит только блокквоту; пользовательский текст берём из compose.body + * до разделителя "--- Оригинальное письмо ---". + */ + private buildHtmlBody(compose: ComposeData): string { + const SEPARATOR = '\n\n--- Оригинальное письмо ---' + const replyText = compose.body.includes(SEPARATOR) + ? compose.body.split(SEPARATOR)[0].trim() + : compose.body.trim() + + return ImapProvider.textToHtml(replyText) + (compose.htmlBody ?? '') + } + + /** + * Конвертирует plain text в минимальный HTML (параграфы + переносы строк). + */ + private static textToHtml(text: string): string { + if (!text) return '' + const escaped = text + .replace(/&/g, '&') + .replace(//g, '>') + const paragraphs = escaped.split(/\n\n+/).filter((p) => p.trim()) + if (paragraphs.length === 0) return '
' + return paragraphs + .map((p) => `${p.replace(/\n/g, '
')}
` + + body.html + + `` + ) +} + export const useComposeStore = defineStore('compose', () => { const { invoke } = useIpc() const accountsStore = useAccountsStore() @@ -87,6 +115,7 @@ export const useComposeStore = defineStore('compose', () => { bcc: [], subject: envelope.subject.startsWith('Re:') ? envelope.subject : `Re: ${envelope.subject}`, body: quoteBody(envelope, body), + htmlBody: quoteBodyHtml(envelope, body), inReplyTo: envelope.messageId, // RFC 2822: References = родительские references + messageId родителя // body.references содержит полную цепочку, полученную при загрузке тела @@ -107,7 +136,8 @@ export const useComposeStore = defineStore('compose', () => { mode: 'forward', to: [], cc: [], bcc: [], subject: envelope.subject.startsWith('Fwd:') ? envelope.subject : `Fwd: ${envelope.subject}`, - body: quoteBody(envelope, body) + body: quoteBody(envelope, body), + htmlBody: quoteBodyHtml(envelope, body) } invoke('compose:open', session) } diff --git a/src/shared/types/message.ts b/src/shared/types/message.ts index 0ed6222..3184dcf 100644 --- a/src/shared/types/message.ts +++ b/src/shared/types/message.ts @@ -58,7 +58,8 @@ export interface ComposeData { cc: string[] bcc: string[] subject: string - body: string // plain text + body: string // plain text (полная версия: текст пользователя + текстовая цитата) + htmlBody?: string // HTML-блокквота оригинала; если задана — шлём multipart/alternative attachments?: ComposeAttachment[] inReplyTo?: string // Message-ID оригинала (для ответа) references?: string // References header