build fix
This commit is contained in:
parent
81fc913133
commit
5e59b92af8
@ -9,12 +9,73 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
EmailMessage,
|
EmailMessage,
|
||||||
EmailContent,
|
|
||||||
EmailAddress,
|
EmailAddress,
|
||||||
EmailAttachment,
|
EmailAttachment
|
||||||
EmailFlags
|
} from '@/lib/types';
|
||||||
} from '@/types/email';
|
|
||||||
import { normalizeEmailContent } from './email-utils';
|
// Define a local interface for email flags structure
|
||||||
|
interface EmailFlags {
|
||||||
|
seen: boolean;
|
||||||
|
flagged: boolean;
|
||||||
|
answered: boolean;
|
||||||
|
deleted: boolean;
|
||||||
|
draft: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize email content from various formats to our standard structure
|
||||||
|
*/
|
||||||
|
function normalizeEmailContent(email: any): { text: string; html: string; isHtml: boolean; direction: string } {
|
||||||
|
// Initialize with default values
|
||||||
|
let text = '';
|
||||||
|
let html = '';
|
||||||
|
let isHtml = false;
|
||||||
|
|
||||||
|
// Extract content from various possible formats
|
||||||
|
if (email.content) {
|
||||||
|
if (typeof email.content === 'string') {
|
||||||
|
// If content is a string, determine if it's HTML or plain text
|
||||||
|
if (email.content.includes('<html') || email.content.includes('<body') || email.content.includes('<div')) {
|
||||||
|
html = email.content;
|
||||||
|
text = email.content.replace(/<[^>]*>/g, ''); // Basic HTML stripping
|
||||||
|
isHtml = true;
|
||||||
|
} else {
|
||||||
|
text = email.content;
|
||||||
|
html = '';
|
||||||
|
}
|
||||||
|
} else if (typeof email.content === 'object') {
|
||||||
|
// If content is already an object, try to read text/html properties
|
||||||
|
text = email.content.text || email.content.plainText || '';
|
||||||
|
html = email.content.html || '';
|
||||||
|
isHtml = !!email.content.isHtml || !!html;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Try to find content in other common properties
|
||||||
|
if (email.html) {
|
||||||
|
html = email.html;
|
||||||
|
isHtml = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email.text) {
|
||||||
|
text = email.text;
|
||||||
|
} else if (email.plainText) {
|
||||||
|
text = email.plainText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have HTML but no text, create a basic text version
|
||||||
|
if (html && !text) {
|
||||||
|
text = html.replace(/<[^>]*>/g, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return standardized content object
|
||||||
|
return {
|
||||||
|
text,
|
||||||
|
html,
|
||||||
|
isHtml,
|
||||||
|
direction: 'ltr' // Default to left-to-right
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a legacy email format to our standardized EmailMessage format
|
* Convert a legacy email format to our standardized EmailMessage format
|
||||||
@ -85,7 +146,6 @@ export function adaptLegacyEmail(legacyEmail: any): EmailMessage {
|
|||||||
return {
|
return {
|
||||||
id: legacyEmail.id || legacyEmail.uid?.toString() || `email-${Date.now()}`,
|
id: legacyEmail.id || legacyEmail.uid?.toString() || `email-${Date.now()}`,
|
||||||
messageId: legacyEmail.messageId,
|
messageId: legacyEmail.messageId,
|
||||||
uid: typeof legacyEmail.uid === 'number' ? legacyEmail.uid : undefined,
|
|
||||||
subject: legacyEmail.subject || '(No subject)',
|
subject: legacyEmail.subject || '(No subject)',
|
||||||
from: Array.isArray(legacyEmail.from) ? legacyEmail.from : [],
|
from: Array.isArray(legacyEmail.from) ? legacyEmail.from : [],
|
||||||
to: Array.isArray(legacyEmail.to) ? legacyEmail.to : [],
|
to: Array.isArray(legacyEmail.to) ? legacyEmail.to : [],
|
||||||
@ -96,8 +156,11 @@ export function adaptLegacyEmail(legacyEmail: any): EmailMessage {
|
|||||||
preview: legacyEmail.preview || '',
|
preview: legacyEmail.preview || '',
|
||||||
content: normalizedContent,
|
content: normalizedContent,
|
||||||
attachments: normalizedAttachments,
|
attachments: normalizedAttachments,
|
||||||
folder: legacyEmail.folder || undefined,
|
folder: legacyEmail.folder || 'INBOX',
|
||||||
size: typeof legacyEmail.size === 'number' ? legacyEmail.size : undefined
|
contentFetched: true,
|
||||||
|
size: typeof legacyEmail.size === 'number' ? legacyEmail.size : 0,
|
||||||
|
hasAttachments: normalizedAttachments.length > 0,
|
||||||
|
accountId: legacyEmail.accountId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user