diff --git a/src/main/lib/compose-attachments.ts b/src/main/lib/compose-attachments.ts new file mode 100644 index 0000000..ca8285b --- /dev/null +++ b/src/main/lib/compose-attachments.ts @@ -0,0 +1,18 @@ +import type { Attachment } from 'nodemailer/lib/mailer' +import type { ComposeData } from '../../shared/types/message' + +export function buildComposeAttachments(compose: ComposeData): Attachment[] { + return [ + ...(compose.attachments ?? []).map((attachment) => ({ + path: attachment.path, + filename: attachment.filename + })), + ...(compose.inlineImages ?? []).map((image) => ({ + filename: image.filename, + content: Buffer.from(image.base64, 'base64'), + contentType: image.contentType, + cid: image.cid, + contentDisposition: 'inline' as const + })) + ] +} diff --git a/src/main/providers/imap.provider.ts b/src/main/providers/imap.provider.ts index f183bb5..0e43ed7 100644 --- a/src/main/providers/imap.provider.ts +++ b/src/main/providers/imap.provider.ts @@ -1,3 +1,4 @@ +import { buildComposeAttachments } from '../lib/compose-attachments' import { ImapFlow } from 'imapflow' import { simpleParser } from 'mailparser' import nodemailer from 'nodemailer' @@ -421,9 +422,7 @@ export class ImapProvider implements IEmailProvider { const fullText = compose.quotedText ? compose.body + '\n\n' + compose.quotedText : compose.body - const fullHtml = compose.htmlBody - ? ImapProvider.textToHtml(compose.body) + compose.htmlBody - : undefined + const fullHtml = ImapProvider.buildComposeHtml(compose) if (process.env.NODE_ENV !== 'production') { console.log('[SMTP] host=%s port=%d secure=%s from=%j to=%j', @@ -440,7 +439,7 @@ export class ImapProvider implements IEmailProvider { html: fullHtml, inReplyTo: compose.inReplyTo, references: compose.references, - attachments: compose.attachments?.map((a) => ({ path: a.path, filename: a.filename })) ?? [] + attachments: buildComposeAttachments(compose) }) // Сохраняем в папку Sent (best-effort) @@ -482,9 +481,7 @@ export class ImapProvider implements IEmailProvider { const fullText = compose.quotedText ? compose.body + '\n\n' + compose.quotedText : compose.body - const fullHtml = compose.htmlBody - ? ImapProvider.textToHtml(compose.body) + compose.htmlBody - : undefined + const fullHtml = ImapProvider.buildComposeHtml(compose) const mail = await transporter.sendMail({ from, @@ -498,7 +495,7 @@ export class ImapProvider implements IEmailProvider { inReplyTo: compose.inReplyTo, references: compose.references, date: new Date(), - attachments: compose.attachments?.map((a) => ({ path: a.path, filename: a.filename })) ?? [] + attachments: buildComposeAttachments(compose) }) const chunks: Buffer[] = [] await new Promise((res, rej) => { @@ -752,9 +749,12 @@ export class ImapProvider implements IEmailProvider { } } - /** - * Конвертирует plain text в минимальный HTML (параграфы + переносы строк). - */ + private static buildComposeHtml(compose: ComposeData): string | undefined { + if (!compose.contentHtml && !compose.htmlBody) return undefined + const quote: string = compose.htmlBody ?? ImapProvider.textToHtml(compose.quotedText ?? '') + return (compose.contentHtml ?? ImapProvider.textToHtml(compose.body)) + quote + } + private static textToHtml(text: string): string { if (!text) return '' const escaped = text diff --git a/src/renderer/src/components/ComposeEditor.vue b/src/renderer/src/components/ComposeEditor.vue new file mode 100644 index 0000000..db46f1f --- /dev/null +++ b/src/renderer/src/components/ComposeEditor.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/src/renderer/src/views/ComposeView.vue b/src/renderer/src/views/ComposeView.vue index 1c175f9..694b669 100644 --- a/src/renderer/src/views/ComposeView.vue +++ b/src/renderer/src/views/ComposeView.vue @@ -3,6 +3,7 @@ import { ref, computed, onMounted, onUnmounted, nextTick, toRaw } from 'vue' import type { ComposeSession, ComposeAttachment } from '@shared/types/message' import { useIpc } from '../composables/useIpc' import AppIcon from '../components/AppIcon.vue' +import ComposeEditor from '../components/ComposeEditor.vue' const { invoke } = useIpc() @@ -27,7 +28,7 @@ const bccInput = ref('') const toInputEl = ref(null) const ccInputEl = ref(null) const bccInputEl = ref(null) -const bodyEl = ref(null) +const bodyEl = ref | null>(null) // ── Quote ───────────────────────────────────────────────── const quoteExpanded = ref(true) @@ -111,6 +112,7 @@ let dragCounter = 0 // ── Status ──────────────────────────────────────────────── const sending = ref(false) +const readingClipboard = ref(false) const sendError = ref('') // ── Init ────────────────────────────────────────────────── @@ -242,6 +244,7 @@ function onDrop(e: DragEvent): void { // ── Send ────────────────────────────────────────────────── async function handleSend(): Promise { + if (sending.value || readingClipboard.value) return commitInput('to'); commitInput('cc'); commitInput('bcc') await nextTick() @@ -251,6 +254,7 @@ async function handleSend(): Promise { sending.value = true sendError.value = '' try { + const content = bodyEl.value?.readContent() const sess = toRaw(session.value) const result = await invoke('messages:send', { accountId: sess.accountId, @@ -259,7 +263,9 @@ async function handleSend(): Promise { cc: [...cc.value], bcc: [...bcc.value], subject: subject.value, - body: body.value, + body: content?.text ?? body.value, + contentHtml: content?.html, + inlineImages: content?.images, quotedText: quotedText.value || undefined, htmlBody: htmlBody.value || undefined, attachments: attachments.value.map(({ path, filename, size }) => ({ path, filename, size })), @@ -412,10 +418,12 @@ const totalAttachSize = computed(() =>
-