/** * Simple MIME decoder for compose message box * Handles basic email content without creating nested structures */ interface ParsedContent { html: string | null; text: string | null; } export async function decodeComposeContent(content: string): Promise { if (!content.trim()) { return { html: null, text: null }; } try { const response = await fetch('/api/parse-email', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email: content }), }); if (!response.ok) { throw new Error('Failed to parse email'); } const parsed = await response.json(); return { html: parsed.html || null, text: parsed.text || null }; } catch (error) { console.error('Error parsing email content:', error); // Fallback to basic content handling return { html: content, text: content }; } } export async function encodeComposeContent(content: string): Promise { if (!content.trim()) { throw new Error('Email content is empty'); } // Create MIME headers const mimeHeaders = { 'MIME-Version': '1.0', 'Content-Type': 'text/html; charset="utf-8"', 'Content-Transfer-Encoding': 'quoted-printable' }; // Combine headers and content return Object.entries(mimeHeaders) .map(([key, value]) => `${key}: ${value}`) .join('\n') + '\n\n' + content; }