mail page rest

This commit is contained in:
alma 2025-04-21 14:11:01 +02:00
parent 2b4818ec91
commit 0c15835b59

View File

@ -8,7 +8,9 @@ export async function POST(request: Request) {
let client: ImapFlow | null = null;
try {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
console.error('No session or user ID found');
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@ -18,6 +20,7 @@ export async function POST(request: Request) {
const { emailId, isRead } = await request.json();
if (!emailId || typeof isRead !== 'boolean') {
console.error('Invalid request parameters:', { emailId, isRead });
return NextResponse.json(
{ error: 'Invalid request parameters' },
{ status: 400 }
@ -29,7 +32,16 @@ export async function POST(request: Request) {
const folder = url.searchParams.get('folder') || 'INBOX';
try {
// Initialize IMAP client with user credentials
client = await getImapClient();
if (!client) {
console.error('Failed to initialize IMAP client');
return NextResponse.json(
{ error: 'Failed to initialize email client' },
{ status: 500 }
);
}
await client.connect();
await client.mailboxOpen(folder);
@ -40,6 +52,7 @@ export async function POST(request: Request) {
});
if (!message) {
console.error('Email not found:', emailId);
return NextResponse.json(
{ error: 'Email not found' },
{ status: 404 }