Skip to content

The open alternative to Salesforce, designed for AI.

Require STARTTLS and flag invalid mail server certificates (#28141)

Charles Bochet2a2c9d9cc2a8
diff --git a/packages/twenty-front/src/modules/accounts/types/ConnectedAccount.ts b/packages/twenty-front/src/modules/accounts/types/ConnectedAccount.ts
index db00a40d6fe..8481788a616 100644
--- a/packages/twenty-front/src/modules/accounts/types/ConnectedAccount.ts
+++ b/packages/twenty-front/src/modules/accounts/types/ConnectedAccount.ts
@@ -8,6 +8,7 @@ export type ConnectedAccount = {
handle: string;
provider: ConnectedAccountProvider;
authFailedAt: string | null;
+ authFailedReason: string | null;
// Set when the account is disconnected or frozen: synced data is kept but
// cannot be updated until the account is reconnected.
archivedAt: string | null;
diff --git a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer.tsx b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer.tsx
index d8123027915..7e4c0a87aa5 100644
--- a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer.tsx
+++ b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer.tsx
@@ -1,11 +1,7 @@
import { type ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { SettingsAccountsRowDropdownMenu } from '@/settings/accounts/components/SettingsAccountsRowDropdownMenu';
-import { SyncStatus } from '@/settings/accounts/constants/SyncStatus';
-import { computeSyncStatus } from '@/settings/accounts/utils/computeSyncStatus';
+import { SettingsConnectedAccountSyncStatus } from '@/settings/app-preferences/components/SettingsConnectedAccountSyncStatus';
import { styled } from '@linaria/react';
-import { t } from '@lingui/core/macro';
-import { isDefined } from 'twenty-shared/utils';
-import { Status } from 'twenty-ui/primitives/data-display';
import { themeCssVariables } from 'twenty-ui/theme';
const StyledRowRightContainer = styled.div`
@@ -18,47 +14,9 @@ export const SettingsAccountsConnectedAccountsRowRightContainer = ({
account,
}: {
account: ConnectedAccount;
-}) => {
- const messageChannel = account.messageChannels[0];
- const calendarChannel = account.calendarChannels[0];
-
- const isArchived = isDefined(account.archivedAt);
-
- const status = computeSyncStatus(messageChannel, calendarChannel);
-
- // Archived accounts retain their synced data but cannot be synced until they
- // are reconnected, so the live sync status is no longer relevant.
- if (isArchived) {
- return (
- <StyledRowRightContainer>
- <Status color="gray" weight="medium">{t`Sync paused`}</Status>
- <SettingsAccountsRowDropdownMenu account={account} />
- </StyledRowRightContainer>
- );
- }
-
- return (
- <StyledRowRightContainer>
- {status === SyncStatus.FAILED && (
- <Status color="red" weight="medium">{t`Sync failed`}</Status>
- )}
- {status === SyncStatus.SYNCED && (
- <Status color="green" weight="medium">{t`Synced`}</Status>
- )}
- {status === SyncStatus.NOT_SYNCED && (
- <Status color="orange" weight="medium">{t`Not synced`}</Status>
- )}
- {status === SyncStatus.IMPORTING && (
- <Status
- color="turquoise"
- weight="medium"
- loading
- >{t`Importing`}</Status>
- )}
- {status === SyncStatus.PENDING_CONFIGURATION && (
- <Status color="orange" weight="medium">{t`Setup incomplete`}</Status>
- )}
- <SettingsAccountsRowDropdownMenu account={account} />
- </StyledRowRightContainer>
- );
-};
+}) => (
+ <StyledRowRightContainer>
+ <SettingsConnectedAccountSyncStatus account={account} />
+ <SettingsAccountsRowDropdownMenu account={account} />
+ </StyledRowRightContainer>
+);
diff --git a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedDropdownConnectedAccount.ts b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedDropdownConnectedAccount.ts
index c80514239c6..269182e4198 100644
--- a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedDropdownConnectedAccount.ts
+++ b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedDropdownConnectedAccount.ts
@@ -12,6 +12,7 @@ export const mockedDropdownConnectedAccount: ConnectedAccount = {
handle: '[email protected]',
provider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
authFailedAt: null,
+ authFailedReason: null,
archivedAt: null,
scopes: null,
handleAliases: null,
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsConnectedAccountSyncStatus.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsConnectedAccountSyncStatus.tsx
index 768d1775da0..6b3714fa894 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsConnectedAccountSyncStatus.tsx
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsConnectedAccountSyncStatus.tsx
@@ -2,13 +2,14 @@ import { type ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { SyncStatus } from '@/settings/accounts/constants/SyncStatus';
import { computeSyncStatus } from '@/settings/accounts/utils/computeSyncStatus';
import { useLingui } from '@lingui/react/macro';
+import { MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON } from 'twenty-shared/constants';
import { isDefined } from 'twenty-shared/utils';
import { Status } from 'twenty-ui/primitives/data-display';
type SettingsConnectedAccountSyncStatusProps = {
account: Pick<
ConnectedAccount,
- 'archivedAt' | 'messageChannels' | 'calendarChannels'
+ 'archivedAt' | 'authFailedReason' | 'messageChannels' | 'calendarChannels'
>;
};
@@ -25,7 +26,12 @@ export const SettingsConnectedAccountSyncStatus = ({
computeSyncStatus(account.messageChannels[0], account.calendarChannels[0])
) {
case SyncStatus.FAILED:
- return <Status color="red" weight="medium">{t`Sync failed`}</Status>;
+ return account.authFailedReason ===
+ MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON ? (
+ <Status color="red" weight="medium">{t`Certificate invalid`}</Status>
+ ) : (
+ <Status color="red" weight="medium">{t`Sync failed`}</Status>
+ );
case SyncStatus.SYNCED:
return <Status color="green" weight="medium">{t`Synced`}</Status>;
case SyncStatus.NOT_SYNCED:
diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
index d8bd0033c20..5f6638c29ea 100644
--- a/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
@@ -329,11 +329,12 @@ export class GoogleAPIsService {
});
if (!isMessagingAvailable && messageChannels.length > 0) {
- await this.messagingChannelSyncStatusService.markAsFailed(
- messageChannels.map((channel) => channel.id),
+ await this.messagingChannelSyncStatusService.markAsFailed({
+ messageChannelIds: messageChannels.map((channel) => channel.id),
workspaceId,
- MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
- );
+ syncStatus:
+ MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
+ });
}
if (isMessagingAvailable) {
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts
index 2250ce4c2ac..849704654e2 100644
--- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts
@@ -18,6 +18,7 @@ import {
import { buildImapTlsOptions } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/build-imap-tls-options.util';
import { buildMailServerCertificateOptions } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/build-mail-server-certificate-options.util';
import { buildSmtpTlsOptions } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/build-smtp-tls-options.util';
+import { isMailServerCertificateError } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util';
import { SecureHttpClientService } from 'src/engine/core-modules/secure-http-client/secure-http-client.service';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
import { CalDavClientService } from 'src/modules/calendar/calendar-event-import-manager/drivers/caldav/services/caldav-client.service';
@@ -93,6 +94,24 @@ export class ImapSmtpCaldavService {
);
}
+ if (isMailServerCertificateError(error)) {
+ throw new UserInputError(
+ `IMAP server certificate could not be verified: ${error.message}`,
+ {
+ userFriendlyMessage: msg`Your email server's security certificate is invalid (expired, self-signed or issued for another hostname). Ask your email provider to fix it, then try again.`,
+ },
+ );
+ }
+
+ if (error.tlsFailed === true) {
+ throw new UserInputError(
+ `IMAP STARTTLS upgrade failed: ${error.message}`,
+ {
+ userFriendlyMessage: msg`We couldn't establish a secure STARTTLS connection with your email server. Try SSL/TLS as the connection security instead.`,
+ },
+ );
+ }
+
if (error.code === 'ECONNREFUSED') {
throw new UserInputError(
`IMAP connection refused. Please verify server and port.`,
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-imap-tls-options.util.spec.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-imap-tls-options.util.spec.ts
index 9a3cf4d62fd..19bce59baa6 100644
--- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-imap-tls-options.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-imap-tls-options.util.spec.ts
@@ -8,9 +8,10 @@ describe('buildImapTlsOptions', () => {
});
});
- it('upgrades opportunistically via STARTTLS when the server offers it', () => {
+ it('requires the STARTTLS upgrade so a stripped capability cannot downgrade to plaintext', () => {
expect(buildImapTlsOptions(EmailConnectionSecurity.STARTTLS)).toEqual({
secure: false,
+ doSTARTTLS: true,
});
});
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-smtp-tls-options.util.spec.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-smtp-tls-options.util.spec.ts
index 23f6cda5ad5..1b7bd5a8fed 100644
--- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-smtp-tls-options.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/build-smtp-tls-options.util.spec.ts
@@ -8,9 +8,10 @@ describe('buildSmtpTlsOptions', () => {
});
});
- it('upgrades opportunistically via STARTTLS when the server offers it', () => {
+ it('requires the STARTTLS upgrade so a stripped capability cannot downgrade to plaintext', () => {
expect(buildSmtpTlsOptions(EmailConnectionSecurity.STARTTLS)).toEqual({
secure: false,
+ requireTLS: true,
});
});
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/is-mail-server-certificate-error.util.spec.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/is-mail-server-certificate-error.util.spec.ts
new file mode 100644
index 00000000000..89d7028a5d9
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/__tests__/is-mail-server-certificate-error.util.spec.ts
@@ -0,0 +1,26 @@
+import { isMailServerCertificateError } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util';
+
+const buildErrorWithCode = (code: string) =>
+ Object.assign(new Error('TLS failure'), { code });
+
+describe('isMailServerCertificateError', () => {
+ it.each([
+ 'CERT_HAS_EXPIRED',
+ 'DEPTH_ZERO_SELF_SIGNED_CERT',
+ 'ERR_TLS_CERT_ALTNAME_INVALID',
+ 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
+ ])('detects %s', (code) => {
+ expect(isMailServerCertificateError(buildErrorWithCode(code))).toBe(true);
+ });
+
+ it('ignores network errors', () => {
+ expect(
+ isMailServerCertificateError(buildErrorWithCode('ECONNREFUSED')),
+ ).toBe(false);
+ });
+
+ it('ignores errors without a code', () => {
+ expect(isMailServerCertificateError(new Error('boom'))).toBe(false);
+ expect(isMailServerCertificateError(undefined)).toBe(false);
+ });
+});
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-imap-tls-options.util.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-imap-tls-options.util.ts
index be58f93f8aa..21b50ca6a65 100644
--- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-imap-tls-options.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-imap-tls-options.util.ts
@@ -12,7 +12,7 @@ export const buildImapTlsOptions = (
case EmailConnectionSecurity.SSL_TLS:
return { secure: true };
case EmailConnectionSecurity.STARTTLS:
- return { secure: false };
+ return { secure: false, doSTARTTLS: true };
case EmailConnectionSecurity.NONE:
return { secure: false, doSTARTTLS: false };
}
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-smtp-tls-options.util.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-smtp-tls-options.util.ts
index fa6fd8af77a..ef3742b19e7 100644
--- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-smtp-tls-options.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/build-smtp-tls-options.util.ts
@@ -3,6 +3,7 @@ import { EmailConnectionSecurity } from 'src/engine/core-modules/imap-smtp-calda
type SmtpTlsOptions = {
secure: boolean;
ignoreTLS?: boolean;
+ requireTLS?: boolean;
};
export const buildSmtpTlsOptions = (
@@ -12,7 +13,7 @@ export const buildSmtpTlsOptions = (
case EmailConnectionSecurity.SSL_TLS:
return { secure: true };
case EmailConnectionSecurity.STARTTLS:
- return { secure: false };
+ return { secure: false, requireTLS: true };
case EmailConnectionSecurity.NONE:
return { secure: false, ignoreTLS: true };
}
diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util.ts
new file mode 100644
index 00000000000..4e673064112
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util.ts
@@ -0,0 +1,21 @@
+import { isObject, isString } from '@sniptt/guards';
+
+const MAIL_SERVER_CERTIFICATE_ERROR_CODES = new Set([
+ 'CERT_HAS_EXPIRED',
+ 'CERT_NOT_YET_VALID',
+ 'CERT_REVOKED',
+ 'CERT_SIGNATURE_FAILURE',
+ 'CERT_UNTRUSTED',
+ 'DEPTH_ZERO_SELF_SIGNED_CERT',
+ 'ERR_TLS_CERT_ALTNAME_INVALID',
+ 'SELF_SIGNED_CERT_IN_CHAIN',
+ 'UNABLE_TO_GET_ISSUER_CERT',
+ 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
+ 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
+]);
+
+export const isMailServerCertificateError = (error: unknown): boolean =>
+ isObject(error) &&
+ 'code' in error &&
+ isString(error.code) &&
+ MAIL_SERVER_CERTIFICATE_ERROR_CODES.has(error.code);
diff --git a/packages/twenty-server/src/modules/messaging/common/services/message-channel-sync-status.service.ts b/packages/twenty-server/src/modules/messaging/common/services/message-channel-sync-status.service.ts
index 0a71950a677..2e73dad8fc0 100644
--- a/packages/twenty-server/src/modules/messaging/common/services/message-channel-sync-status.service.ts
+++ b/packages/twenty-server/src/modules/messaging/common/services/message-channel-sync-status.service.ts
@@ -333,13 +333,19 @@ export class MessageChannelSyncStatusService {
);
}
- public async markAsFailed(
- messageChannelIds: string[],
- workspaceId: string,
+ public async markAsFailed({
+ messageChannelIds,
+ workspaceId,
+ syncStatus,
+ authFailedReason = null,
+ }: {
+ messageChannelIds: string[];
+ workspaceId: string;
syncStatus:
| MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS
- | MessageChannelSyncStatus.FAILED_UNKNOWN,
- ) {
+ | MessageChannelSyncStatus.FAILED_UNKNOWN;
+ authFailedReason?: string | null;
+ }) {
if (!messageChannelIds.length) {
return;
}
@@ -388,6 +394,7 @@ export class MessageChannelSyncStatusService {
{ id: Any(connectedAccountIds), workspaceId },
{
authFailedAt: new Date(),
+ authFailedReason,
},
);
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception.ts
index 9f07a3a3feb..621f91a46d1 100644
--- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception.ts
+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception.ts
@@ -48,4 +48,5 @@ export enum MessageImportDriverExceptionCode {
CLIENT_NOT_AVAILABLE = 'CLIENT_NOT_AVAILABLE',
ACCESS_TOKEN_MISSING = 'ACCESS_TOKEN_MISSING',
CHANNEL_MISCONFIGURED = 'CHANNEL_MISCONFIGURED',
+ SERVER_CERTIFICATE_INVALID = 'SERVER_CERTIFICATE_INVALID',
}
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/__tests__/parse-imap-authentication-error.util.spec.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/__tests__/parse-imap-authentication-error.util.spec.ts
new file mode 100644
index 00000000000..c863620eb82
--- /dev/null
+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/__tests__/parse-imap-authentication-error.util.spec.ts
@@ -0,0 +1,32 @@
+import { MessageImportDriverExceptionCode } from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';
+import { type ImapFlowError } from 'src/modules/messaging/message-import-manager/drivers/imap/types/imap-error.type';
+import { parseImapAuthenticationError } from 'src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util';
+
+const buildImapFlowError = (
+ properties: Partial<ImapFlowError>,
+): ImapFlowError => Object.assign(new Error('IMAP failure'), properties);
+
+describe('parseImapAuthenticationError', () => {
+ it('flags an untrusted server certificate', () => {
+ expect(
+ parseImapAuthenticationError(
+ buildImapFlowError({ code: 'CERT_HAS_EXPIRED' }),
+ ).code,
+ ).toBe(MessageImportDriverExceptionCode.SERVER_CERTIFICATE_INVALID);
+ });
+
+ it('treats network errors as temporary', () => {
+ expect(
+ parseImapAuthenticationError(buildImapFlowError({ code: 'ECONNRESET' }))
+ .code,
+ ).toBe(MessageImportDriverExceptionCode.TEMPORARY_ERROR);
+ });
+
+ it('flags rejected credentials as insufficient permissions', () => {
+ expect(
+ parseImapAuthenticationError(
+ buildImapFlowError({ authenticationFailed: true }),
+ ).code,
+ ).toBe(MessageImportDriverExceptionCode.INSUFFICIENT_PERMISSIONS);
+ });
+});
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 65d5b9ff2df..93dcff14b01 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,5 +1,6 @@
import { isDefined } from 'twenty-shared/utils';
+import { isMailServerCertificateError } from 'src/engine/core-modules/imap-smtp-caldav-connection/utils/is-mail-server-certificate-error.util';
import {
MessageImportDriverException,
MessageImportDriverExceptionCode,
@@ -16,6 +17,14 @@ const TRANSIENT_IMAP_RESPONSE_CODES = new Set([
export const parseImapAuthenticationError = (
error: ImapFlowError,
): MessageImportDriverException => {
+ if (isMailServerCertificateError(error)) {
+ return new MessageImportDriverException(
+ `IMAP server certificate could not be verified: ${error.message}`,
+ MessageImportDriverExceptionCode.SERVER_CERTIFICATE_INVALID,
+ { cause: error },
+ );
+ }
+
if (isImapNetworkError(error)) {
return new MessageImportDriverException(
`IMAP network error: ${error.message}`,
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts
index 52baa07032c..cef8d1da9b2 100644
--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts
+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { isDefined } from 'twenty-shared/utils';
+import { MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON } from 'twenty-shared/constants';
import { MessageChannelSyncStatus } from 'twenty-shared/types';
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
import { MessageChannelEntity } from 'src/engine/metadata-modules/message-channel/entities/message-channel.entity';
@@ -111,6 +112,16 @@ export class MessageImportExceptionHandlerService {
workspaceId,
);
break;
+ case MessageImportDriverExceptionCode.SERVER_CERTIFICATE_INVALID:
+ await this.messageChannelSyncStatusService.markAsFailed({
+ messageChannelIds: [messageChannel.id],
+ workspaceId,
+ syncStatus:
+ MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
+ authFailedReason:
+ MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON,
+ });
+ break;
case MessageImportDriverExceptionCode.SYNC_CURSOR_ERROR:
await this.handleSyncCursorErrorException(
messageChannel,
@@ -162,11 +173,11 @@ export class MessageImportExceptionHandlerService {
if (
messageChannel.throttleFailureCount >= MESSAGING_THROTTLE_MAX_ATTEMPTS
) {
- await this.messageChannelSyncStatusService.markAsFailed(
- [messageChannel.id],
+ await this.messageChannelSyncStatusService.markAsFailed({
+ messageChannelIds: [messageChannel.id],
workspaceId,
- MessageChannelSyncStatus.FAILED_UNKNOWN,
- );
+ syncStatus: MessageChannelSyncStatus.FAILED_UNKNOWN,
+ });
this.exceptionHandlerService.captureExceptions(
[
@@ -247,11 +258,11 @@ export class MessageImportExceptionHandlerService {
workspace: { id: workspaceId },
});
- await this.messageChannelSyncStatusService.markAsFailed(
- [messageChannel.id],
+ await this.messageChannelSyncStatusService.markAsFailed({
+ messageChannelIds: [messageChannel.id],
workspaceId,
- MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
- );
+ syncStatus: MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
+ });
}
private async handleUnknownException(
@@ -267,11 +278,11 @@ export class MessageImportExceptionHandlerService {
},
workspace: { id: workspaceId },
});
- await this.messageChannelSyncStatusService.markAsFailed(
- [messageChannel.id],
+ await this.messageChannelSyncStatusService.markAsFailed({
+ messageChannelIds: [messageChannel.id],
workspaceId,
- MessageChannelSyncStatus.FAILED_UNKNOWN,
- );
+ syncStatus: MessageChannelSyncStatus.FAILED_UNKNOWN,
+ });
}
private async handleNotFoundException(
@@ -280,11 +291,11 @@ export class MessageImportExceptionHandlerService {
workspaceId: string,
): Promise<void> {
if (syncStep === MessageImportSyncStep.MESSAGE_LIST_FETCH) {
- await this.messageChannelSyncStatusService.markAsFailed(
- [messageChannel.id],
+ await this.messageChannelSyncStatusService.markAsFailed({
+ messageChannelIds: [messageChannel.id],
workspaceId,
- MessageChannelSyncStatus.FAILED_UNKNOWN,
- );
+ syncStatus: MessageChannelSyncStatus.FAILED_UNKNOWN,
+ });
this.exceptionHandlerService.captureExceptions(
[
diff --git a/packages/twenty-shared/src/constants/MailServerCertificateInvalidAuthFailedReason.ts b/packages/twenty-shared/src/constants/MailServerCertificateInvalidAuthFailedReason.ts
new file mode 100644
index 00000000000..b7264f68900
--- /dev/null
+++ b/packages/twenty-shared/src/constants/MailServerCertificateInvalidAuthFailedReason.ts
@@ -0,0 +1,2 @@
+export const MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON =
+ 'MAIL_SERVER_CERTIFICATE_INVALID';
diff --git a/packages/twenty-shared/src/constants/index.ts b/packages/twenty-shared/src/constants/index.ts
index e5adaa44c80..51af5849cc0 100644
--- a/packages/twenty-shared/src/constants/index.ts
+++ b/packages/twenty-shared/src/constants/index.ts
@@ -56,6 +56,7 @@ export { IANA_TIME_ZONES } from './IanaTimeZones';
export { IMAGE_IDENTIFIER_FIELD_METADATA_TYPES } from './ImageIdentifierFieldMetadataTypes';
export { INTERNAL_CREDITS_PER_DISPLAY_CREDIT } from './InternalCreditsPerDisplayCredit';
export { LABEL_IDENTIFIER_FIELD_METADATA_TYPES } from './LabelIdentifierFieldMetadataTypes';
+export { MAIL_SERVER_CERTIFICATE_INVALID_AUTH_FAILED_REASON } from './MailServerCertificateInvalidAuthFailedReason';
export { MAX_ALLOWED_IFRAME_ORIGINS } from './MaxAllowedIframeOrigins';
export { MAX_CORE_WORKFLOW_FILTER_RULES } from './MaxCoreWorkflowFilterRules';
export { MAX_CUSTOM_INDEXES_PER_OBJECT } from './MaxCustomIndexesPerObject';