From c03e28e969de6f7414cbdbd5984dc2ba4f7f91f9 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 24 Apr 2025 17:56:34 +0200 Subject: [PATCH] compose mime --- components/ComposeEmail.tsx | 64 +++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index d2e6895b..85370310 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -138,7 +138,21 @@ export default function ComposeEmail({ // Modified input handler to work with the single contentEditable area const handleInput = (e: React.FormEvent) => { if (!composeBodyRef.current) return; - const content = composeBodyRef.current.innerHTML; + + // Get the compose area content + const composeArea = composeBodyRef.current.querySelector('.compose-area'); + if (!composeArea) return; + + // Get the quoted content if it exists + const quotedContent = composeBodyRef.current.querySelector('.quoted-content'); + + // Combine compose area and quoted content + const content = composeArea.innerHTML + (quotedContent ? quotedContent.outerHTML : ''); + + if (!content.trim()) { + console.warn('Email content is empty'); + return; + } // Create MIME headers const mimeHeaders = { @@ -159,6 +173,52 @@ export default function ComposeEmail({ } }; + const handleSendEmail = async () => { + // Ensure we have content before sending + if (!composeBodyRef.current) { + console.error('Compose body ref is not available'); + return; + } + + const composeArea = composeBodyRef.current.querySelector('.compose-area'); + if (!composeArea) { + console.error('Compose area not found'); + return; + } + + // Get the current content + const composeContent = composeArea.innerHTML; + if (!composeContent.trim()) { + console.error('Email content is empty'); + return; + } + + // Get the quoted content if it exists + const quotedContent = composeBodyRef.current.querySelector('.quoted-content'); + const fullContent = composeContent + (quotedContent ? quotedContent.outerHTML : ''); + + // Create MIME headers + const mimeHeaders = { + 'MIME-Version': '1.0', + 'Content-Type': 'text/html; charset="utf-8"', + 'Content-Transfer-Encoding': 'quoted-printable' + }; + + // Combine headers and content + const mimeContent = Object.entries(mimeHeaders) + .map(([key, value]) => `${key}: ${value}`) + .join('\n') + '\n\n' + fullContent; + + setComposeBody(mimeContent); + + try { + await handleSend(); + setShowCompose(false); + } catch (error) { + console.error('Error sending email:', error); + } + }; + const handleFileAttachment = async (e: React.ChangeEvent) => { if (!e.target.files) return; @@ -401,7 +461,7 @@ export default function ComposeEmail({