diff --git a/app/api/courrier/delete/route.ts b/app/api/courrier/delete/route.ts index 1b0e618a..34b018cb 100644 --- a/app/api/courrier/delete/route.ts +++ b/app/api/courrier/delete/route.ts @@ -87,7 +87,21 @@ export async function POST(request: Request) { // Move messages to trash for (const emailId of emailIds) { - await client.messageMove(emailId, trashFolder); + try { + // Convert the emailId to a number if it's a string + const uid = typeof emailId === 'string' ? parseInt(emailId, 10) : emailId; + + // Debug logging for troubleshooting + console.log(`[DELETE API] Moving email with UID ${uid} to trash folder "${trashFolder}"`); + + // Use the correct syntax for messageMove method + await client.messageMove(uid.toString(), trashFolder, { uid: true }); + + console.log(`[DELETE API] Successfully moved email ${uid} to trash`); + } catch (moveError) { + console.error(`[DELETE API] Error moving email ${emailId} to trash:`, moveError); + // Continue with other emails even if one fails + } } }