first commit
This commit is contained in:
32
app/api/mail/messages/[uid]/route.ts
Normal file
32
app/api/mail/messages/[uid]/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { getMailSession } from "@/lib/mail-session";
|
||||
import { getMessage } from "@/lib/imap";
|
||||
|
||||
// GET /api/mail/messages/[uid]?folder=INBOX
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ uid: string }> }
|
||||
) {
|
||||
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 });
|
||||
|
||||
const { uid } = await params;
|
||||
const folder = req.nextUrl.searchParams.get("folder") ?? "INBOX";
|
||||
|
||||
try {
|
||||
const message = await getMessage(creds, folder, parseInt(uid));
|
||||
if (!message) {
|
||||
return NextResponse.json({ error: "Mesaj bulunamadı" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json(message);
|
||||
} catch (err: any) {
|
||||
return NextResponse.json(
|
||||
{ error: "Mesaj alınamadı: " + (err?.message ?? "") },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user