import { useEffect, useRef, useState } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { Mail, Reply, Paperclip } from 'lucide-react'; import { FileViewerProvider, FileViewerHeader, FileViewerBody } from 'officerdev'; import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'; import { useClient } from 'hooks/useClient'; import { useGlobal } from 'hooks/useGlobal'; import type { EmailMessage, EmailThread } from 'types'; import { useComposer, replyDraft } from './Compose'; type OpenAttachment = { filePath: string; fileName: string; root: string; }; const senderName = (from: string) => from.replace(/\s*<[^>]+>$/, '').trim() || from; const HtmlBody = ({ html }: { html: string }) => { const iframeRef = useRef(null); useEffect(() => { const iframe = iframeRef.current; if (!iframe) return; const doc = iframe.contentDocument; if (!doc) return; doc.open(); doc.write(` ${html} `); doc.close(); // Auto-size to content so each message sits at its natural height inside the stacked thread. const resize = () => { if (doc.body) iframe.style.height = `${doc.body.scrollHeight + 8}px`; }; resize(); doc.querySelectorAll('img').forEach((img) => img.addEventListener('load', resize)); const t = setTimeout(resize, 300); return () => clearTimeout(t); }, [html]); return