compose mime

This commit is contained in:
alma 2025-04-24 17:56:34 +02:00
parent c71df883d7
commit c03e28e969

View File

@ -138,7 +138,21 @@ export default function ComposeEmail({
// Modified input handler to work with the single contentEditable area
const handleInput = (e: React.FormEvent<HTMLDivElement>) => {
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<HTMLInputElement>) => {
if (!e.target.files) return;
@ -401,7 +461,7 @@ export default function ComposeEmail({
</Button>
<Button
className="bg-blue-600 text-white hover:bg-blue-700"
onClick={handleSend}
onClick={handleSendEmail}
>
Send
</Button>