From 6f45fe5a10174fd33932d17dc056898f06466067 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 15 Dec 2024 12:29:30 -0800 Subject: close the mailbox --- src/email.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/email.ts') diff --git a/src/email.ts b/src/email.ts index cf588f4..337572c 100644 --- a/src/email.ts +++ b/src/email.ts @@ -26,6 +26,7 @@ interface ImapClientI { opts: Record, ) => Promise; logout: () => Promise; + mailboxClose: () => Promise; } type Email = { @@ -287,7 +288,10 @@ export const perform = ( if (O.isSome(e.imap)) { const imap = e.imap.value; return pipe( - TE.tryCatch(() => imap.logout(), toError), + TE.tryCatch( + () => imap.mailboxClose().then(() => imap.logout()), + toError, + ), TE.flatMap(() => TE.left(e)), ); } @@ -295,8 +299,13 @@ export const perform = ( }, ({ mailboxLock, deleted, imap }) => { mailboxLock.release(); - imap.logout(); - return TE.right(deleted); + return pipe( + TE.tryCatch( + () => imap.mailboxClose().then(() => imap.logout()), + toError, + ), + TE.flatMap(() => TE.right(deleted)), + ); }, ), ); -- cgit v1.2.3-70-g09d2