import { NextResponse } from "next/server"; import { auth } from "@/auth"; import { getMailSession } from "@/lib/mail-session"; import { listFolders } from "@/lib/imap"; // GET /api/mail/folders export async function GET() { const session = await auth(); if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); const creds = await getMailSession(); if (!creds) return NextResponse.json({ error: "Mail oturumu yok" }, { status: 401 }); try { const folders = await listFolders(creds); return NextResponse.json(folders); } catch (err: any) { return NextResponse.json( { error: "Klasörler alınamadı: " + (err?.message ?? "") }, { status: 502 } ); } }