/** * Simple MIME decoder for compose message box * Handles basic email content without creating nested structures */ export function decodeComposeContent(content: string): string { if (!content) return ''; // Basic HTML cleaning without creating nested structures let cleaned = content // Remove script and style tags .replace(/]*>[\s\S]*?<\/script>/gi, '') .replace(/]*>[\s\S]*?<\/style>/gi, '') // Remove meta tags .replace(/]*>/gi, '') // Remove head and title .replace(/]*>[\s\S]*?<\/head>/gi, '') .replace(/]*>[\s\S]*?<\/title>/gi, '') // Remove body tags .replace(/]*>/gi, '') .replace(/<\/body>/gi, '') // Remove html tags .replace(/]*>/gi, '') .replace(/<\/html>/gi, '') // Handle basic formatting .replace(//gi, '\n') .replace(/]*>/gi, '\n') .replace(/<\/p>/gi, '\n') // Handle lists .replace(/]*>/gi, '\n') .replace(/<\/ul>/gi, '\n') .replace(/]*>/gi, '\n') .replace(/<\/ol>/gi, '\n') .replace(/]*>/gi, '• ') .replace(/<\/li>/gi, '\n') // Handle basic text formatting .replace(/]*>/gi, '**') .replace(/<\/strong>/gi, '**') .replace(/]*>/gi, '**') .replace(/<\/b>/gi, '**') .replace(/]*>/gi, '*') .replace(/<\/em>/gi, '*') .replace(/]*>/gi, '*') .replace(/<\/i>/gi, '*') // Handle links .replace(/]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, '$2 ($1)') // Handle basic entities .replace(/ /g, ' ') .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, "'") // Clean up whitespace .replace(/\s+/g, ' ') .trim(); // Do NOT wrap in additional divs return cleaned; } export function encodeComposeContent(content: string): string { if (!content) return ''; // Basic HTML encoding without adding structure const encoded = content .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') .replace(/\n/g, '
'); return encoded; }