@@ -341,27 +341,39 @@ export async function fetchEmails() {
341
341
if ( processedUids . length > 0 ) {
342
342
try {
343
343
const mailboxes = await client . list ( ) ;
344
- const trashMailbox = mailboxes . find (
344
+
345
+ let trashPath = "Trash" ;
346
+
347
+ const ovhTrash = mailboxes . find (
345
348
( box ) =>
346
- box . specialUse === "\\Trash" ||
347
- box . path . toLowerCase ( ) . includes ( "trash" ) ||
348
- box . path . toLowerCase ( ) . includes ( "corbeille" )
349
+ box . path === "INBOX.INBOX.Trash" || box . path === "INBOX.Trash"
349
350
) ;
350
351
351
- const trashPath = trashMailbox ? trashMailbox . path : "Trash" ;
352
+ if ( ovhTrash ) {
353
+ trashPath = ovhTrash . path ;
354
+ } else {
355
+ const trashMailbox = mailboxes . find (
356
+ ( box ) =>
357
+ box . specialUse === "\\Trash" ||
358
+ box . path . toLowerCase ( ) . includes ( "trash" ) ||
359
+ box . path . toLowerCase ( ) . includes ( "corbeille" )
360
+ ) ;
361
+
362
+ if ( trashMailbox ) {
363
+ trashPath = trashMailbox . path ;
364
+ }
365
+ }
352
366
353
367
console . log (
354
- `🗑️ Déplacement de ${ processedUids . length } emails traités vers la corbeille ...`
368
+ `🗑️ Déplacement de ${ processedUids . length } emails vers ${ trashPath } ...`
355
369
) ;
356
370
await client . messageMove ( processedUids , trashPath ) ;
357
371
console . log (
358
372
`✅ ${ processedUids . length } emails déplacés vers la corbeille`
359
373
) ;
360
374
} catch ( moveError ) {
361
- console . error (
362
- "❌ Erreur lors du déplacement des emails vers la corbeille:" ,
363
- moveError
364
- ) ;
375
+ console . error ( "❌ Erreur lors du déplacement des emails:" , moveError ) ;
376
+ console . error ( moveError ) ;
365
377
}
366
378
}
367
379
} finally {
0 commit comments