panel 2 courier api restore
This commit is contained in:
parent
1dc167ec97
commit
353cb6c51c
@ -127,7 +127,7 @@ export default function ComposeEmail({
|
||||
).join(', ');
|
||||
};
|
||||
|
||||
// Initialize forwarded email with improved style handling
|
||||
// Initialize forwarded email with a dead simple approach
|
||||
const initializeForwardedEmail = async () => {
|
||||
if (!initialEmail) {
|
||||
console.error('No email available for forwarding');
|
||||
@ -136,77 +136,56 @@ export default function ComposeEmail({
|
||||
}
|
||||
|
||||
try {
|
||||
setSending(true); // Use sending state to show loading
|
||||
|
||||
// Format subject with Fwd: prefix if needed
|
||||
const cleanSubject = initialEmail.subject?.replace(/^(Fwd|FW|Forward):\s*/i, '').trim() || '';
|
||||
const formattedSubject = initialEmail.subject?.match(/^(Fwd|FW|Forward):/i)
|
||||
? initialEmail.subject
|
||||
: `Fwd: ${cleanSubject}`;
|
||||
const subject = initialEmail.subject || "(No subject)";
|
||||
if (!subject.match(/^(Fwd|FW|Forward):/i)) {
|
||||
setSubject(`Fwd: ${subject}`);
|
||||
} else {
|
||||
setSubject(subject);
|
||||
}
|
||||
|
||||
setSubject(formattedSubject);
|
||||
// Get email content - use whatever data we have available
|
||||
const content = initialEmail.content || initialEmail.html || initialEmail.text || '';
|
||||
|
||||
// Store the email content directly without complex parsing
|
||||
const emailContent = initialEmail.content || '';
|
||||
// Get from info - handle various possible formats
|
||||
let from = 'Unknown Sender';
|
||||
if (initialEmail.from) {
|
||||
if (Array.isArray(initialEmail.from) && initialEmail.from.length > 0) {
|
||||
from = initialEmail.from[0].address || 'Unknown';
|
||||
} else if (typeof initialEmail.from === 'string') {
|
||||
from = initialEmail.from;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a forwarding header with proper types
|
||||
const fromDisplay = Array.isArray(initialEmail.from) && initialEmail.from.length > 0
|
||||
? initialEmail.from.map(f => f.name ? `${f.name} <${f.address}>` : f.address).join(', ')
|
||||
: 'Unknown Sender';
|
||||
|
||||
const toDisplay = Array.isArray(initialEmail.to) && initialEmail.to.length > 0
|
||||
? initialEmail.to.map(t => t.name ? `${t.name} <${t.address}>` : t.address).join(', ')
|
||||
: '';
|
||||
|
||||
const ccDisplay = initialEmail.cc && Array.isArray(initialEmail.cc) && initialEmail.cc.length > 0
|
||||
? initialEmail.cc.map(c => c.name ? `${c.name} <${c.address}>` : c.address).join(', ')
|
||||
: '';
|
||||
|
||||
const dateDisplay = initialEmail.date
|
||||
? initialEmail.date instanceof Date
|
||||
? initialEmail.date.toLocaleString()
|
||||
: new Date(initialEmail.date as any).toLocaleString()
|
||||
: '';
|
||||
|
||||
const subjectDisplay = initialEmail.subject || '(No subject)';
|
||||
|
||||
// Don't try to parse the content, just wrap it in a container
|
||||
const contentDisplay = emailContent.trim()
|
||||
? `<div class="forwarded-content">${emailContent}</div>`
|
||||
: '<div style="color: #666; font-style: italic;">No content available</div>';
|
||||
|
||||
// Construct the forwarded message with direct header information
|
||||
// Hard-code a simple format that definitely works
|
||||
const forwardedContent = `
|
||||
<div style="border-top: 1px solid #e5e7eb; padding-top: 20px; margin-top: 20px;">
|
||||
<div style="color: #6b7280; font-size: 0.875rem; margin-bottom: 15px;">
|
||||
---------- Forwarded message ---------<br/>
|
||||
<strong>From:</strong> ${fromDisplay}<br/>
|
||||
<strong>Date:</strong> ${dateDisplay}<br/>
|
||||
<strong>Subject:</strong> ${subjectDisplay}<br/>
|
||||
<strong>To:</strong> ${toDisplay}<br/>
|
||||
${ccDisplay ? `<strong>Cc:</strong> ${ccDisplay}<br/>` : ''}
|
||||
</div>
|
||||
<div style="margin-top: 15px; border-left: 2px solid #e5e7eb; padding-left: 10px;">
|
||||
${contentDisplay}
|
||||
</div>
|
||||
<div style="border-top: 1px solid #ccc; margin-top: 20px; padding-top: 10px; color: #666;">
|
||||
<p>---------- Forwarded message ---------</p>
|
||||
<p><b>From:</b> ${from}</p>
|
||||
<p><b>Date:</b> ${new Date().toLocaleString()}</p>
|
||||
<p><b>Subject:</b> ${subject}</p>
|
||||
<p><b>To:</b> ${Array.isArray(initialEmail.to) && initialEmail.to.length > 0 ? initialEmail.to[0].address : ''}</p>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px; padding: 10px; border-left: 2px solid #ccc;">
|
||||
${content ? content : '<p style="color: #666; font-style: italic;">No content available</p>'}
|
||||
</div>`;
|
||||
|
||||
// Set the formatted content
|
||||
// Just set the HTML directly
|
||||
setBody(forwardedContent);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error initializing forwarded email:', error);
|
||||
// Fallback content for error case
|
||||
// Super simple fallback
|
||||
setBody(`
|
||||
<div style="border-top: 1px solid #e5e7eb; padding-top: 20px; margin-top: 20px; color: #6b7280; font-size: 0.875rem;">
|
||||
---------- Forwarded message ---------<br/>
|
||||
<strong>From:</strong> ${initialEmail.from ? JSON.stringify(initialEmail.from) : 'Unknown'}<br/>
|
||||
<strong>Date:</strong> ${initialEmail.date ? new Date(initialEmail.date as any).toLocaleString() : ''}<br/>
|
||||
<strong>Subject:</strong> ${initialEmail.subject || ''}<br/>
|
||||
<strong>To:</strong> ${initialEmail.to ? JSON.stringify(initialEmail.to) : ''}<br/>
|
||||
<div style="border-top: 1px solid #ccc; margin-top: 20px; padding-top: 10px;">
|
||||
<p>---------- Forwarded message ---------</p>
|
||||
<p><b>From:</b> ${initialEmail.from ? (Array.isArray(initialEmail.from) ? initialEmail.from[0].address : initialEmail.from) : 'Unknown'}</p>
|
||||
<p><b>Date:</b> ${new Date().toLocaleString()}</p>
|
||||
<p><b>Subject:</b> ${initialEmail.subject || ''}</p>
|
||||
<p><b>To:</b> ${initialEmail.to ? (Array.isArray(initialEmail.to) ? initialEmail.to[0].address : initialEmail.to) : ''}</p>
|
||||
</div>
|
||||
<div style="color: #ef4444; font-style: italic; margin-top: 10px;">Error loading forwarded content</div>`);
|
||||
} finally {
|
||||
setSending(false);
|
||||
<p style="color: #666; font-style: italic;">Content could not be displayed</p>`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user