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