courrier multi account restore compose
This commit is contained in:
parent
6638347f92
commit
53b95dd240
@ -108,39 +108,23 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('EmailPreview: Raw email content:', {
|
console.log('EmailPreview: Full email object:', JSON.stringify(email, null, 2));
|
||||||
content: email.content,
|
|
||||||
html: email.html,
|
|
||||||
text: email.text,
|
|
||||||
formattedContent: email.formattedContent
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get the content in order of preference
|
// Get the content in order of preference
|
||||||
let content = '';
|
let content = '';
|
||||||
|
|
||||||
// If content is an object with html/text
|
// If content is an object with html/text
|
||||||
if (email.content && typeof email.content === 'object') {
|
if (email.content && typeof email.content === 'object') {
|
||||||
console.log('EmailPreview: Using object content:', email.content);
|
console.log('EmailPreview: Using object content:', JSON.stringify(email.content, null, 2));
|
||||||
content = email.content.html || email.content.text || '';
|
content = email.content.html || email.content.text || '';
|
||||||
}
|
}
|
||||||
// If content is a string
|
// If content is a string
|
||||||
else if (typeof email.content === 'string') {
|
else if (typeof email.content === 'string') {
|
||||||
console.log('EmailPreview: Using direct string content');
|
console.log('EmailPreview: Using direct string content:', email.content);
|
||||||
content = email.content;
|
content = email.content;
|
||||||
}
|
}
|
||||||
// Fallback to html/text properties
|
|
||||||
else {
|
|
||||||
console.log('EmailPreview: Using html/text properties');
|
|
||||||
content = email.html || email.text || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// If content is empty, try to get it from the formattedContent property
|
console.log('EmailPreview: Final content before sanitization:', content);
|
||||||
if (!content && email.formattedContent) {
|
|
||||||
console.log('EmailPreview: Using formattedContent property');
|
|
||||||
content = email.formattedContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('EmailPreview: Content before sanitization:', content);
|
|
||||||
|
|
||||||
// Sanitize the content for display
|
// Sanitize the content for display
|
||||||
const sanitizedContent = DOMPurify.sanitize(content, {
|
const sanitizedContent = DOMPurify.sanitize(content, {
|
||||||
|
|||||||
@ -44,43 +44,45 @@ export function useEmailFetch({ onEmailLoaded, onError }: UseEmailFetchProps = {
|
|||||||
|
|
||||||
// Fetch email with proper error handling and cancellation
|
// Fetch email with proper error handling and cancellation
|
||||||
const fetchEmail = useCallback(async (emailId: string, accountId: string, folder: string) => {
|
const fetchEmail = useCallback(async (emailId: string, accountId: string, folder: string) => {
|
||||||
|
if (!emailId || !accountId || !folder) {
|
||||||
|
console.error('Missing required parameters for fetchEmail');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(prev => ({ ...prev, loading: true, error: null }));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Cancel any in-flight request
|
console.log('useEmailFetch: Fetching email with params:', { emailId, accountId, folder });
|
||||||
if (abortControllerRef.current) {
|
|
||||||
abortControllerRef.current.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new abort controller
|
|
||||||
abortControllerRef.current = new AbortController();
|
|
||||||
|
|
||||||
// Validate parameters
|
|
||||||
validateFetchParams(emailId, accountId, folder);
|
|
||||||
|
|
||||||
setState(prev => ({ ...prev, loading: true, error: null }));
|
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/courrier/${emailId}?accountId=${encodeURIComponent(accountId)}&folder=${encodeURIComponent(folder)}`,
|
`/api/courrier/${emailId}?accountId=${encodeURIComponent(accountId)}&folder=${encodeURIComponent(folder)}`,
|
||||||
{
|
{
|
||||||
signal: abortControllerRef.current.signal
|
signal: abortControllerRef.current?.signal
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
throw new Error(`Failed to fetch email: ${response.statusText}`);
|
||||||
throw new Error(errorData.error || 'Failed to fetch email');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('useEmailFetch: Raw API response:', JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
if (!data) {
|
// Transform the data if needed
|
||||||
throw new Error('Email not found');
|
const transformedEmail = {
|
||||||
}
|
...data,
|
||||||
|
content: data.content || {
|
||||||
|
text: data.text || '',
|
||||||
|
html: data.html || ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setState({ email: data, loading: false, error: null });
|
console.log('useEmailFetch: Transformed email:', JSON.stringify(transformedEmail, null, 2));
|
||||||
onEmailLoaded?.(data);
|
|
||||||
|
setState({ email: transformedEmail, loading: false, error: null });
|
||||||
|
onEmailLoaded?.(transformedEmail);
|
||||||
|
|
||||||
// Mark as read if not already
|
// Mark as read if not already
|
||||||
if (!data.flags?.seen) {
|
if (!transformedEmail.flags?.seen) {
|
||||||
try {
|
try {
|
||||||
await fetch(`/api/courrier/${emailId}/mark-read`, {
|
await fetch(`/api/courrier/${emailId}/mark-read`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -97,6 +99,7 @@ export function useEmailFetch({ onEmailLoaded, onError }: UseEmailFetchProps = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error('useEmailFetch: Error fetching email:', err);
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Failed to load email';
|
const errorMessage = err instanceof Error ? err.message : 'Failed to load email';
|
||||||
setState(prev => ({ ...prev, loading: false, error: errorMessage }));
|
setState(prev => ({ ...prev, loading: false, error: errorMessage }));
|
||||||
onError?.(errorMessage);
|
onError?.(errorMessage);
|
||||||
|
|||||||
@ -533,12 +533,12 @@ export async function getEmailContent(
|
|||||||
})),
|
})),
|
||||||
content: {
|
content: {
|
||||||
text: parsedEmail.text || '',
|
text: parsedEmail.text || '',
|
||||||
html: rawHtml
|
html: rawHtml || ''
|
||||||
},
|
},
|
||||||
folder: actualFolder,
|
folder: actualFolder,
|
||||||
contentFetched: true,
|
contentFetched: true,
|
||||||
size: size || 0,
|
size: size || 0,
|
||||||
accountId: accountId || 'default' // Add accountId to the email object
|
accountId: accountId || 'default'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cache the email content with account-specific key
|
// Cache the email content with account-specific key
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user