mail page fix design

This commit is contained in:
alma 2025-04-21 20:26:23 +02:00
parent ccff673a49
commit 47ec859fe2
2 changed files with 32 additions and 51 deletions

View File

@ -231,11 +231,10 @@ export default function ComposeEmail({
className="w-full h-full mt-1 bg-white border border-gray-300 rounded-md p-2 text-gray-900 overflow-y-auto prose max-w-none"
style={{
minHeight: '200px',
direction: 'ltr',
textAlign: 'left',
unicodeBidi: 'bidi-override'
direction: 'inherit' as const,
textAlign: 'start',
unicodeBidi: 'plaintext'
}}
dir="ltr"
/>
</div>
</div>

View File

@ -86,6 +86,10 @@ export function convertCharset(text: string, charset: string): string {
export function cleanHtml(html: string): string {
if (!html) return '';
// Detect text direction from the content
const hasRtlChars = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/.test(html);
const defaultDir = hasRtlChars ? 'rtl' : 'ltr';
// Remove or fix malformed URLs
html = html.replace(/=3D"(http[^"]+)"/g, (match, url) => {
try {
@ -100,7 +104,7 @@ export function cleanHtml(html: string): string {
return String.fromCharCode(parseInt(p1, 16));
});
// Clean up any remaining HTML issues
// Clean up any remaining HTML issues while preserving direction
html = html
// Remove style and script tags
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
@ -110,7 +114,11 @@ export function cleanHtml(html: string): string {
.replace(/<base[^>]*>/gi, '')
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '')
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '')
.replace(/<body[^>]*>/gi, '')
// Preserve body attributes
.replace(/<body[^>]*>/gi, (match) => {
const dir = match.match(/dir=["'](rtl|ltr)["']/i)?.[1] || defaultDir;
return `<body dir="${dir}">`;
})
.replace(/<\/body>/gi, '')
.replace(/<html[^>]*>/gi, '')
.replace(/<\/html>/gi, '')
@ -123,31 +131,25 @@ export function cleanHtml(html: string): string {
.replace(/<\/td>/gi, ' ')
.replace(/<th[^>]*>/gi, ' ')
.replace(/<\/th>/gi, ' ')
.replace(/<tbody[^>]*>/gi, '')
.replace(/<\/tbody>/gi, '')
.replace(/<thead[^>]*>/gi, '')
.replace(/<\/thead>/gi, '')
.replace(/<tfoot[^>]*>/gi, '')
.replace(/<\/tfoot>/gi, '')
// Handle other structural elements
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<div[^>]*>/gi, '\n')
.replace(/<\/div>/gi, '\n')
.replace(/<p[^>]*>/gi, '\n')
.replace(/<\/p>/gi, '\n')
.replace(/<h[1-6][^>]*>/gi, '\n')
.replace(/<\/h[1-6]>/gi, '\n')
// Handle lists
.replace(/<ul[^>]*>/gi, '\n')
.replace(/<\/ul>/gi, '\n')
.replace(/<ol[^>]*>/gi, '\n')
.replace(/<\/ol>/gi, '\n')
.replace(/<li[^>]*>/gi, '\n• ')
.replace(/<li[^>]*>/gi, '• ')
.replace(/<\/li>/gi, '\n')
.replace(/<blockquote[^>]*>/gi, '\n> ')
.replace(/<\/blockquote>/gi, '\n')
// Handle other block elements
.replace(/<div[^>]*>/gi, '\n')
.replace(/<\/div>/gi, '\n')
.replace(/<p[^>]*>/gi, '\n')
.replace(/<\/p>/gi, '\n')
.replace(/<br[^>]*>/gi, '\n')
.replace(/<hr[^>]*>/gi, '\n')
// Handle inline elements
.replace(/<span[^>]*>/gi, '')
.replace(/<\/span>/gi, '')
.replace(/<a[^>]*>/gi, '')
.replace(/<\/a>/gi, '')
.replace(/<strong[^>]*>/gi, '**')
.replace(/<\/strong>/gi, '**')
.replace(/<b[^>]*>/gi, '**')
@ -156,39 +158,19 @@ export function cleanHtml(html: string): string {
.replace(/<\/em>/gi, '*')
.replace(/<i[^>]*>/gi, '*')
.replace(/<\/i>/gi, '*')
// Handle HTML entities
// Handle special characters
.replace(/&nbsp;/g, ' ')
.replace(/&zwnj;/g, '')
.replace(/&raquo;/g, '»')
.replace(/&laquo;/g, '«')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&eacute;/g, 'é')
.replace(/&egrave;/g, 'è')
.replace(/&ecirc;/g, 'ê')
.replace(/&euml;/g, 'ë')
.replace(/&agrave;/g, 'à')
.replace(/&acirc;/g, 'â')
.replace(/&auml;/g, 'ä')
.replace(/&icirc;/g, 'î')
.replace(/&iuml;/g, 'ï')
.replace(/&ocirc;/g, 'ô')
.replace(/&ouml;/g, 'ö')
.replace(/&ucirc;/g, 'û')
.replace(/&uuml;/g, 'ü')
.replace(/&ccedil;/g, 'ç')
.replace(/&OElig;/g, 'Œ')
.replace(/&oelig;/g, 'œ')
.replace(/&AElig;/g, 'Æ')
.replace(/&aelig;/g, 'æ')
.replace(/&#39;/g, "'")
// Clean up whitespace
.replace(/^\s+$/gm, '')
.replace(/\n{3,}/g, '\n\n')
.replace(/\s+/g, ' ')
.trim();
return html;
// Wrap in a div with the detected direction
return `<div dir="${defaultDir}">${html}</div>`;
}
export function parseEmailHeaders(headers: string): { contentType: string; encoding: string; charset: string } {