compose mime
This commit is contained in:
parent
fdc70fb3b3
commit
c71df883d7
@ -90,56 +90,27 @@ export default function ComposeEmail({
|
||||
// Get the original email content
|
||||
const originalContent = replyTo?.body || forwardFrom?.body || '';
|
||||
|
||||
// Generate a unique boundary for MIME parts
|
||||
const boundary = `----=_NextPart_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||||
|
||||
// Create MIME headers
|
||||
const mimeHeaders = {
|
||||
'MIME-Version': '1.0',
|
||||
'Content-Type': `multipart/alternative; boundary="${boundary}"`,
|
||||
'From': forwardFrom?.from || replyTo?.from || '',
|
||||
'Date': new Date(forwardFrom?.date || replyTo?.date || '').toUTCString(),
|
||||
'Subject': forwardFrom?.subject || replyTo?.subject || '',
|
||||
'To': forwardFrom?.to || replyTo?.to || '',
|
||||
'Cc': forwardFrom?.cc || replyTo?.cc || '',
|
||||
};
|
||||
|
||||
// Create the reply/forward structure with proper MIME formatting
|
||||
// Create the reply/forward structure
|
||||
content = `
|
||||
<div class="compose-area" contenteditable="true" style="min-height: 100px; padding: 10px; border: 1px solid #e5e7eb; border-radius: 4px; margin-bottom: 20px;"></div>
|
||||
<div class="quoted-content" contenteditable="false" style="color: #6b7280; font-size: 0.875rem;">
|
||||
${forwardFrom ? `
|
||||
<div style="margin-bottom: 10px;">
|
||||
---------- Forwarded message ---------<br/>
|
||||
${Object.entries(mimeHeaders)
|
||||
.filter(([key, value]) => value)
|
||||
.map(([key, value]) => `${key}: ${value}<br/>`)
|
||||
.join('')}
|
||||
<br/>
|
||||
This is a multi-part message in MIME format.<br/>
|
||||
<br/>
|
||||
--${boundary}<br/>
|
||||
Content-Type: text/plain; charset="utf-8"<br/>
|
||||
Content-Transfer-Encoding: quoted-printable<br/>
|
||||
<br/>
|
||||
${originalContent.replace(/\n/g, '<br/>')}<br/>
|
||||
<br/>
|
||||
--${boundary}<br/>
|
||||
Content-Type: text/html; charset="utf-8"<br/>
|
||||
Content-Transfer-Encoding: quoted-printable<br/>
|
||||
<br/>
|
||||
${originalContent}<br/>
|
||||
<br/>
|
||||
--${boundary}--<br/>
|
||||
From: ${forwardFrom.from}<br/>
|
||||
Date: ${new Date(forwardFrom.date).toLocaleString()}<br/>
|
||||
Subject: ${forwardFrom.subject}<br/>
|
||||
To: ${forwardFrom.to}<br/>
|
||||
${forwardFrom.cc ? `Cc: ${forwardFrom.cc}<br/>` : ''}
|
||||
</div>
|
||||
` : `
|
||||
<div style="margin-bottom: 10px;">
|
||||
On ${new Date(replyTo?.date || '').toLocaleString()}, ${replyTo?.from} wrote:
|
||||
</div>
|
||||
<blockquote style="margin: 0; padding-left: 1em; border-left: 2px solid #e5e7eb;">
|
||||
${originalContent}
|
||||
</blockquote>
|
||||
`}
|
||||
<blockquote style="margin: 0; padding-left: 1em; border-left: 2px solid #e5e7eb;">
|
||||
${originalContent}
|
||||
</blockquote>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
@ -169,38 +140,17 @@ export default function ComposeEmail({
|
||||
if (!composeBodyRef.current) return;
|
||||
const content = composeBodyRef.current.innerHTML;
|
||||
|
||||
// Generate a unique boundary for MIME parts
|
||||
const boundary = `----=_NextPart_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||||
|
||||
// Create MIME headers
|
||||
const mimeHeaders = {
|
||||
'MIME-Version': '1.0',
|
||||
'Content-Type': `multipart/alternative; boundary="${boundary}"`,
|
||||
'Content-Type': 'text/html; charset="utf-8"',
|
||||
'Content-Transfer-Encoding': 'quoted-printable'
|
||||
};
|
||||
|
||||
// Create MIME message structure
|
||||
const mimeContent = `
|
||||
${Object.entries(mimeHeaders)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join('\n')}
|
||||
|
||||
This is a multi-part message in MIME format.
|
||||
|
||||
--${boundary}
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
${content.replace(/<[^>]*>/g, '')}
|
||||
|
||||
--${boundary}
|
||||
Content-Type: text/html; charset="utf-8"
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
${content}
|
||||
|
||||
--${boundary}--
|
||||
`;
|
||||
// Combine headers and content
|
||||
const mimeContent = Object.entries(mimeHeaders)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join('\n') + '\n\n' + content;
|
||||
|
||||
setComposeBody(mimeContent);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user