diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts index 6e69f337f6..65d5b9ff2d 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts @@ -1,3 +1,5 @@ +import { isDefined } from 'twenty-shared/utils'; + import { MessageImportDriverException, MessageImportDriverExceptionCode, @@ -5,6 +7,12 @@ import { import { type ImapFlowError } from 'src/modules/messaging/message-import-manager/drivers/imap/types/imap-error.type'; import { isImapNetworkError } from 'src/modules/messaging/message-import-manager/drivers/imap/utils/is-imap-network-error.util'; +const TRANSIENT_IMAP_RESPONSE_CODES = new Set([ + 'UNAVAILABLE', + 'INUSE', + 'SERVERBUG', +]); + export const parseImapAuthenticationError = ( error: ImapFlowError, ): MessageImportDriverException => { @@ -16,6 +24,17 @@ export const parseImapAuthenticationError = ( ); } + if ( + isDefined(error.serverResponseCode) && + TRANSIENT_IMAP_RESPONSE_CODES.has(error.serverResponseCode) + ) { + return new MessageImportDriverException( + `IMAP transient error [${error.serverResponseCode}]: ${error.responseText ?? error.message}`, + MessageImportDriverExceptionCode.TEMPORARY_ERROR, + { cause: error }, + ); + } + if (error.authenticationFailed === true) { return new MessageImportDriverException( `IMAP authentication error: ${error.message}`,