mail page ui correction maj compose 10

This commit is contained in:
alma 2025-04-16 12:32:32 +02:00
parent c2395e51d1
commit 2dc237e733

View File

@ -641,7 +641,7 @@ export default function MailPage() {
// Parse the original email content using MIME decoder // Parse the original email content using MIME decoder
const parsedEmail = parseFullEmail(selectedEmailData.body); const parsedEmail = parseFullEmail(selectedEmailData.body);
const decodedBody = parsedEmail.text || parsedEmail.html || selectedEmailData.body; const decodedBody = parsedEmail?.text || parsedEmail?.html || selectedEmailData.body;
// Format the date properly // Format the date properly
const emailDate = new Date(selectedEmailData.date).toLocaleString('en-US', { const emailDate = new Date(selectedEmailData.date).toLocaleString('en-US', {
@ -662,22 +662,44 @@ export default function MailPage() {
case 'replyAll': case 'replyAll':
to = selectedEmailData.from; to = selectedEmailData.from;
// Extract CC addresses from the original email, excluding our own address
const originalCc = selectedEmailData.cc || ''; // Get our email address from the selected account
const ourEmail = accounts.find(acc => acc.id === selectedEmailData.accountId)?.email || ''; const ourEmail = accounts.find(acc => acc.id === selectedEmailData.accountId)?.email || '';
const ccAddresses = originalCc
.split(',') // Handle CC addresses
const ccList = new Set<string>();
// Add original TO recipients (except ourselves and the person we're replying to)
selectedEmailData.to.split(',')
.map(addr => addr.trim()) .map(addr => addr.trim())
.filter(addr => addr !== ourEmail && addr !== selectedEmailData.from); .filter(addr => addr !== ourEmail && addr !== selectedEmailData.from)
cc = ccAddresses.join(', '); .forEach(addr => ccList.add(addr));
// Add original CC recipients (if any)
if (selectedEmailData.cc) {
selectedEmailData.cc.split(',')
.map(addr => addr.trim())
.filter(addr => addr !== ourEmail && addr !== selectedEmailData.from)
.forEach(addr => ccList.add(addr));
}
// Convert Set to string
cc = Array.from(ccList).join(', ');
// If we have CC recipients, show the CC field
if (cc) {
setShowCc(true);
}
content = `\n\nOn ${emailDate}, ${selectedEmailData.fromName} wrote:\n> ${decodedBody.split('\n').join('\n> ')}`; content = `\n\nOn ${emailDate}, ${selectedEmailData.fromName} wrote:\n> ${decodedBody.split('\n').join('\n> ')}`;
break; break;
case 'forward': case 'forward':
// Include original attachments if any // Safely handle attachments
const attachmentInfo = parsedEmail.attachments.length > 0 const attachments = parsedEmail?.attachments || [];
const attachmentInfo = attachments.length > 0
? '\n\n-------- Attachments --------\n' + ? '\n\n-------- Attachments --------\n' +
parsedEmail.attachments.map(att => att.filename).join('\n') attachments.map(att => att.filename).join('\n')
: ''; : '';
content = `\n\n---------- Forwarded message ----------\n` + content = `\n\n---------- Forwarded message ----------\n` +
@ -687,6 +709,11 @@ export default function MailPage() {
`To: ${selectedEmailData.to}\n` + `To: ${selectedEmailData.to}\n` +
(selectedEmailData.cc ? `Cc: ${selectedEmailData.cc}\n` : '') + (selectedEmailData.cc ? `Cc: ${selectedEmailData.cc}\n` : '') +
`\n\n${decodedBody}${attachmentInfo}`; `\n\n${decodedBody}${attachmentInfo}`;
// Handle attachments if present
if (attachments.length > 0) {
handleForwardedAttachments(attachments);
}
break; break;
} }
@ -695,19 +722,6 @@ export default function MailPage() {
setComposeTo(to); setComposeTo(to);
setComposeCc(cc); setComposeCc(cc);
setComposeBody(content); setComposeBody(content);
// Show CC field if there are CC recipients
if (cc) {
setShowCc(true);
}
// Handle attachments for forwarded emails
if (type === 'forward' && parsedEmail.attachments.length > 0) {
// You'll need to implement attachment handling here
// This could involve creating File objects from the attachment data
// or storing the attachment information to be processed when sending
handleForwardedAttachments(parsedEmail.attachments);
}
}; };
// Handle forwarded attachments // Handle forwarded attachments
@ -717,6 +731,7 @@ export default function MailPage() {
encoding: string; encoding: string;
content: string; content: string;
}>) => { }>) => {
try {
// Store attachment information in state // Store attachment information in state
setAttachments(attachments.map(att => ({ setAttachments(attachments.map(att => ({
name: att.filename, name: att.filename,
@ -724,6 +739,9 @@ export default function MailPage() {
content: att.content, content: att.content,
encoding: att.encoding encoding: att.encoding
}))); })));
} catch (error) {
console.error('Error handling attachments:', error);
}
}; };
// Modified send function to handle MIME encoding // Modified send function to handle MIME encoding
@ -743,12 +761,12 @@ export default function MailPage() {
]; ];
// Add attachments if any // Add attachments if any
if (attachments.length > 0) { if (attachments && attachments.length > 0) {
for (const attachment of attachments) { for (const attachment of attachments) {
mimeContent = mimeContent.concat([ mimeContent = mimeContent.concat([
`--${boundary}`, `--${boundary}`,
`Content-Type: ${attachment.type}`, `Content-Type: ${attachment.type}`,
`Content-Transfer-Encoding: base64`, `Content-Transfer-Encoding: ${attachment.encoding}`,
`Content-Disposition: attachment; filename="${attachment.name}"`, `Content-Disposition: attachment; filename="${attachment.name}"`,
'', '',
attachment.content, attachment.content,