courrier multi account restore compose
This commit is contained in:
parent
e7890356e1
commit
b62ae2d849
@ -69,35 +69,30 @@ export default function EmailPanel({
|
|||||||
const [isComposing, setIsComposing] = useState<boolean>(false);
|
const [isComposing, setIsComposing] = useState<boolean>(false);
|
||||||
const [composeType, setComposeType] = useState<'new' | 'reply' | 'reply-all' | 'forward'>('new');
|
const [composeType, setComposeType] = useState<'new' | 'reply' | 'reply-all' | 'forward'>('new');
|
||||||
|
|
||||||
// Create a formatted version of the email content using the same formatter as ComposeEmail
|
// Create a formatted version of the email content
|
||||||
const formattedEmail = useMemo(() => {
|
const formattedEmail = useMemo(() => {
|
||||||
if (!email) return null;
|
if (!email) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Convert to the formatter message format - this is what ComposeEmail does
|
// Handle different content structures
|
||||||
const formatterEmail: FormatterEmailMessage = {
|
let content = '';
|
||||||
id: email.id,
|
|
||||||
messageId: email.messageId,
|
|
||||||
subject: email.subject,
|
|
||||||
from: email.from || [],
|
|
||||||
to: email.to || [],
|
|
||||||
cc: email.cc || [],
|
|
||||||
bcc: email.bcc || [],
|
|
||||||
date: email.date,
|
|
||||||
content: email.content,
|
|
||||||
html: email.html,
|
|
||||||
text: email.text,
|
|
||||||
hasAttachments: email.hasAttachments || false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get the formatted content
|
if (typeof email.content === 'string') {
|
||||||
const formattedContent = email.content || email.html || email.text || '';
|
// Direct string content
|
||||||
|
content = email.content;
|
||||||
|
} else if (email.content && typeof email.content === 'object') {
|
||||||
|
// Object with text/html properties
|
||||||
|
content = email.content.html || email.content.text || '';
|
||||||
|
} else {
|
||||||
|
// Fallback to html or text properties
|
||||||
|
content = email.html || email.text || '';
|
||||||
|
}
|
||||||
|
|
||||||
// Return a new email object with the formatted content
|
// Return a new email object with the formatted content
|
||||||
return {
|
return {
|
||||||
...email,
|
...email,
|
||||||
content: formattedContent,
|
content,
|
||||||
formattedContent
|
formattedContent: content
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error formatting email content:', error);
|
console.error('Error formatting email content:', error);
|
||||||
|
|||||||
@ -105,37 +105,33 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP
|
|||||||
.slice(0, 2);
|
.slice(0, 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Format the email content using the same formatter as ComposeEmail
|
// Format the email content
|
||||||
const formattedContent = useMemo(() => {
|
const formattedContent = useMemo(() => {
|
||||||
if (!email) return '';
|
if (!email) return '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Convert to the formatter message format - same as what ComposeEmail does
|
// Get the content in order of preference
|
||||||
const formatterEmail: FormatterEmailMessage = {
|
let content = '';
|
||||||
id: email.id,
|
|
||||||
messageId: email.messageId,
|
|
||||||
subject: email.subject,
|
|
||||||
from: email.from || [],
|
|
||||||
to: email.to || [],
|
|
||||||
cc: email.cc || [],
|
|
||||||
bcc: email.bcc || [],
|
|
||||||
date: email.date instanceof Date ? email.date : new Date(email.date),
|
|
||||||
content: email.content || '',
|
|
||||||
html: email.html,
|
|
||||||
text: email.text,
|
|
||||||
hasAttachments: email.hasAttachments || false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get the formatted content - if already formatted content is provided, use that instead
|
|
||||||
if (email.formattedContent) {
|
if (email.formattedContent) {
|
||||||
return email.formattedContent;
|
content = email.formattedContent;
|
||||||
|
} else if (typeof email.content === 'string') {
|
||||||
|
content = email.content;
|
||||||
|
} else if (email.content && typeof email.content === 'object') {
|
||||||
|
content = email.content.html || email.content.text || '';
|
||||||
|
} else {
|
||||||
|
content = email.html || email.text || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise sanitize the content for display
|
// Sanitize the content for display
|
||||||
return sanitizeHtml(email.content || email.html || email.text || '');
|
return sanitizeHtml(content, {
|
||||||
|
ADD_TAGS: ['table', 'thead', 'tbody', 'tr', 'td', 'th'],
|
||||||
|
ADD_ATTR: ['target', 'rel', 'colspan', 'rowspan', 'style', 'class', 'id', 'border'],
|
||||||
|
ALLOW_DATA_ATTR: false
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error formatting email content:', error);
|
console.error('Error formatting email content:', error);
|
||||||
return email.content || email.html || email.text || '';
|
return '';
|
||||||
}
|
}
|
||||||
}, [email]);
|
}, [email]);
|
||||||
|
|
||||||
@ -241,7 +237,7 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Email content - using the preformatted content */}
|
{/* Email content */}
|
||||||
<ScrollArea className="flex-1">
|
<ScrollArea className="flex-1">
|
||||||
<div className="space-y-2 p-6">
|
<div className="space-y-2 p-6">
|
||||||
<div className="border rounded-md overflow-hidden">
|
<div className="border rounded-md overflow-hidden">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user