"use client"; import type { MailMessage } from "@/app/dashboard/mail/page"; import { formatBytes } from "@/lib/format"; function getFileIcon(contentType: string, filename: string): string { if (contentType.startsWith("image/")) return "🖼️"; if (contentType === "application/pdf") return "📄"; if (contentType.includes("zip") || contentType.includes("rar") || contentType.includes("tar")) return "📦"; if (contentType.includes("word") || filename.endsWith(".doc") || filename.endsWith(".docx")) return "📝"; if (contentType.includes("sheet") || contentType.includes("excel") || filename.endsWith(".xls")) return "📊"; if (contentType.includes("presentation") || filename.endsWith(".ppt")) return "📑"; if (contentType.startsWith("video/")) return "🎬"; if (contentType.startsWith("audio/")) return "🎵"; return "📎"; } function canPreview(contentType: string): boolean { return contentType.startsWith("image/") || contentType === "application/pdf"; } export default function MessageView({ message, onReply, onDelete, folder }: { message: MailMessage; onReply: () => void; onDelete: () => void; folder: string; }) { const from = message.from[0]; const date = new Date(message.date).toLocaleString("tr-TR", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", }); const downloadUrl = (filename: string) => `/api/mail/messages/${message.uid}/attachments?folder=${encodeURIComponent(folder)}&filename=${encodeURIComponent(filename)}`; const handleAttachment = (att: { filename: string; contentType: string }, preview: boolean) => { const url = downloadUrl(att.filename); if (preview && canPreview(att.contentType)) { window.open(url, "_blank"); } else { const a = document.createElement("a"); a.href = url; a.download = att.filename; a.click(); } }; return (
{/* Header */}

{message.subject}

{/* Meta */}
{(from?.name || from?.address)?.[0]?.toUpperCase() ?? "?"}
{from?.name || from?.address}
{from?.address} {message.to.length > 0 && <> → {message.to.map((t) => t.address).join(", ")}}
{date}
{/* Attachments */} {message.attachments.length > 0 && (
📎 {message.attachments.length} ek
{message.attachments.map((att, i) => (
handleAttachment(att, false)}> {getFileIcon(att.contentType, att.filename)} {att.filename} {formatBytes(att.size)} {canPreview(att.contentType) && ( )}
))}
)} {/* Body */}
{message.html ? (