courrier refactor rebuild 2
This commit is contained in:
parent
a51a4c303d
commit
19cff1ce7c
@ -9,8 +9,29 @@
|
||||
*/
|
||||
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
import { formatDateRelative } from './date-formatter';
|
||||
// Instead of importing, implement the formatDateRelative function directly
|
||||
// import { formatDateRelative } from './date-formatter';
|
||||
|
||||
/**
|
||||
* Format a date in a relative format
|
||||
* Simple implementation for email display
|
||||
*/
|
||||
function formatDateRelative(date: Date): string {
|
||||
if (!date) return '';
|
||||
|
||||
try {
|
||||
return date.toLocaleString('en-US', {
|
||||
weekday: 'short',
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
} catch (e) {
|
||||
return date.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset any existing hooks to start clean
|
||||
DOMPurify.removeAllHooks();
|
||||
@ -368,18 +389,13 @@ export function encodeComposeContent(content: string): string {
|
||||
.join('\n') + '\n\n' + content;
|
||||
}
|
||||
|
||||
// Email formatter functions for various email actions
|
||||
export function formatReplyEmail(email: any): string {
|
||||
// Legacy email formatter functions - renamed to avoid conflicts
|
||||
export function formatReplyEmailLegacy(email: any): string {
|
||||
const originalSender = email.sender?.name || email.sender?.email || 'Unknown Sender';
|
||||
const originalDate = formatDateRelative(new Date(email.date));
|
||||
|
||||
const sanitizedBody = sanitizeHtml(email.content || '', {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
||||
allowedAttributes: {
|
||||
...sanitizeHtml.defaults.allowedAttributes,
|
||||
img: ['src', 'alt', 'width', 'height']
|
||||
}
|
||||
});
|
||||
// Use our own sanitizeHtml function consistently
|
||||
const sanitizedBody = sanitizeHtml(email.content || '');
|
||||
|
||||
return `
|
||||
<p></p>
|
||||
@ -390,7 +406,7 @@ export function formatReplyEmail(email: any): string {
|
||||
`.trim();
|
||||
}
|
||||
|
||||
export function formatForwardedEmail(email: any): string {
|
||||
export function formatForwardedEmailLegacy(email: any): string {
|
||||
const originalSender = email.sender?.name || email.sender?.email || 'Unknown Sender';
|
||||
const originalRecipients = email.to?.map((recipient: any) =>
|
||||
recipient.name || recipient.email
|
||||
@ -398,13 +414,8 @@ export function formatForwardedEmail(email: any): string {
|
||||
const originalDate = formatDateRelative(new Date(email.date));
|
||||
const originalSubject = email.subject || 'No Subject';
|
||||
|
||||
const sanitizedBody = sanitizeHtml(email.content || '', {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
||||
allowedAttributes: {
|
||||
...sanitizeHtml.defaults.allowedAttributes,
|
||||
img: ['src', 'alt', 'width', 'height']
|
||||
}
|
||||
});
|
||||
// Use our own sanitizeHtml function consistently
|
||||
const sanitizedBody = sanitizeHtml(email.content || '');
|
||||
|
||||
return `
|
||||
<p></p>
|
||||
@ -422,7 +433,7 @@ export function formatForwardedEmail(email: any): string {
|
||||
|
||||
export function formatReplyToAllEmail(email: any): string {
|
||||
// For reply all, we use the same format as regular reply
|
||||
return formatReplyEmail(email);
|
||||
return formatReplyEmailLegacy(email);
|
||||
}
|
||||
|
||||
// Utility function to get the reply subject line
|
||||
|
||||
Loading…
Reference in New Issue
Block a user