mail page rest
This commit is contained in:
parent
2b4818ec91
commit
0c15835b59
@ -8,7 +8,9 @@ export async function POST(request: Request) {
|
|||||||
let client: ImapFlow | null = null;
|
let client: ImapFlow | null = null;
|
||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.id) {
|
if (!session?.user?.id) {
|
||||||
|
console.error('No session or user ID found');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Unauthorized' },
|
{ error: 'Unauthorized' },
|
||||||
{ status: 401 }
|
{ status: 401 }
|
||||||
@ -18,6 +20,7 @@ export async function POST(request: Request) {
|
|||||||
const { emailId, isRead } = await request.json();
|
const { emailId, isRead } = await request.json();
|
||||||
|
|
||||||
if (!emailId || typeof isRead !== 'boolean') {
|
if (!emailId || typeof isRead !== 'boolean') {
|
||||||
|
console.error('Invalid request parameters:', { emailId, isRead });
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Invalid request parameters' },
|
{ error: 'Invalid request parameters' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@ -29,7 +32,16 @@ export async function POST(request: Request) {
|
|||||||
const folder = url.searchParams.get('folder') || 'INBOX';
|
const folder = url.searchParams.get('folder') || 'INBOX';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Initialize IMAP client with user credentials
|
||||||
client = await getImapClient();
|
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.connect();
|
||||||
await client.mailboxOpen(folder);
|
await client.mailboxOpen(folder);
|
||||||
|
|
||||||
@ -40,6 +52,7 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
|
console.error('Email not found:', emailId);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Email not found' },
|
{ error: 'Email not found' },
|
||||||
{ status: 404 }
|
{ status: 404 }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user