"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthenticationFailure = exports.ImapFlowErrorCode = void 0; exports.createImapError = createImapError; /** * The `code` values ImapFlow sets on the errors it raises, so they can be matched without * string literals: `if (err.code === ImapFlowErrorCode.NoConnection)`. * * Parser failures use `ParserError` followed by a number (`ParserError11`) and are not listed * one by one, test them with `err.code?.startsWith('ParserError')`. Errors from the socket, TLS * or DNS layer pass through with Node's own code (`ECONNREFUSED`, `ENOTFOUND`, ...). */ exports.ImapFlowErrorCode = { // the connection is gone, the command was not (or can no longer be) completed NoConnection: 'NoConnection', EConnectionClosed: 'EConnectionClosed', StateLogout: 'StateLogout', ClosedAfterConnectText: 'ClosedAfterConnectText', ClosedAfterConnectTLS: 'ClosedAfterConnectTLS', // timeouts CONNECT_TIMEOUT: 'CONNECT_TIMEOUT', GREETING_TIMEOUT: 'GREETING_TIMEOUT', UPGRADE_TIMEOUT: 'UPGRADE_TIMEOUT', ETIMEOUT: 'ETIMEOUT', LockTimeout: 'LockTimeout', // the server ETHROTTLE: 'ETHROTTLE', UnexpectedTag: 'UnexpectedTag', MissingTag: 'MissingTag', InvalidResponse: 'InvalidResponse', ResponseProcessingFailed: 'ResponseProcessingFailed', STARTTLS_INJECTION: 'STARTTLS_INJECTION', COMPRESS_TRAILING_DATA: 'COMPRESS_TRAILING_DATA', PollFailed: 'PollFailed', NotFound: 'NotFound', MissingServerExtension: 'MissingServerExtension', // response parsing and size limits ParserError: 'ParserError', ParserErrorExchange: 'ParserErrorExchange', // an unexpected exception inside the parser, re-raised with a code; a parser bug ParserErrorInternal: 'ParserErrorInternal', MAX_IMAP_NESTING_REACHED: 'MAX_IMAP_NESTING_REACHED', LineTooLarge: 'LineTooLarge', LiteralTooLarge: 'LiteralTooLarge', ResponseTooLarge: 'ResponseTooLarge', TooManyTokens: 'TooManyTokens', // one command received more untagged responses than are kept, see MAX_COLLECTED_RESPONSES TooManyResponses: 'TooManyResponses', // invalid values in a command InvalidStringValue: 'InvalidStringValue', InvalidTokenValue: 'InvalidTokenValue', InvalidTextValue: 'InvalidTextValue', InvalidSequenceSet: 'InvalidSequenceSet', InvalidSearchQuery: 'InvalidSearchQuery', InvalidMessageContent: 'InvalidMessageContent', // download() DownloadOverflow: 'DownloadOverflow', DownloadIncomplete: 'DownloadIncomplete', // proxy connections ProxyError: 'ProxyError', EPROXY: 'EPROXY', UnsupportedProxyAddress: 'UnsupportedProxyAddress', ERR_INVALID_URL: 'ERR_INVALID_URL', // the transport option UnsupportedTransportOption: 'UnsupportedTransportOption', // API misuse InstanceReused: 'InstanceReused', // a message command (FETCH) was called while no mailbox was selected NoMailboxSelected: 'NoMailboxSelected' }; /** * Error subclass thrown when IMAP authentication fails. */ class AuthenticationFailure extends Error { constructor() { super(...arguments); this.authenticationFailed = true; } } exports.AuthenticationFailure = AuthenticationFailure; /** * Creates an {@link ImapFlowError} with a code and optional extra properties. The code is * checked by the compiler against {@link ImapFlowErrorCode}, so a typo or an undeclared * code fails the build instead of reaching consumers. * * @param message - The error message * @param code - The error code * @param props - Extra properties to set on the error * @returns The error, ready to throw or reject with */ function createImapError(message, code, props) { const error = new Error(message); error.code = code; if (props) { Object.assign(error, props); } return error; }