Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(email): use STARTTLS for secure SMTP without a port (#3683)

Hampus1c8dcd4c8086
diff --git a/packages/constants/src/SmtpConstants.test.ts b/packages/constants/src/SmtpConstants.test.ts
new file mode 100644
index 000000000..7675d90da
--- /dev/null
+++ b/packages/constants/src/SmtpConstants.test.ts
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {SmtpTlsModes, smtpTlsModeFromSecure} from '@fluxer/constants/src/SmtpConstants';
+import {describe, expect, it} from 'vitest';
+
+describe('smtpTlsModeFromSecure', () => {
+ it('uses implicit TLS on port 465', () => {
+ expect(smtpTlsModeFromSecure(true, 465)).toBe(SmtpTlsModes.IMPLICIT);
+ });
+
+ it('uses starttls on the default port when no port is set', () => {
+ expect(smtpTlsModeFromSecure(true, undefined)).toBe(SmtpTlsModes.STARTTLS);
+ expect(smtpTlsModeFromSecure(true, null)).toBe(SmtpTlsModes.STARTTLS);
+ });
+
+ it('uses starttls on any other port', () => {
+ expect(smtpTlsModeFromSecure(true, 2525)).toBe(SmtpTlsModes.STARTTLS);
+ });
+
+ it('uses opportunistic TLS when secure is false', () => {
+ expect(smtpTlsModeFromSecure(false, 465)).toBe(SmtpTlsModes.OPPORTUNISTIC);
+ });
+
+ it('leaves the mode unset when secure is unset', () => {
+ expect(smtpTlsModeFromSecure(undefined, 465)).toBeNull();
+ });
+});
diff --git a/packages/constants/src/SmtpConstants.ts b/packages/constants/src/SmtpConstants.ts
index c2d1fa997..248b75dab 100644
--- a/packages/constants/src/SmtpConstants.ts
+++ b/packages/constants/src/SmtpConstants.ts
@@ -24,5 +24,5 @@ export function smtpTlsModeFromSecure(
): SmtpTlsMode | null {
if (secure == null) return null;
if (!secure) return SmtpTlsModes.OPPORTUNISTIC;
- return port == null || port === SMTP_IMPLICIT_TLS_PORT ? SmtpTlsModes.IMPLICIT : SmtpTlsModes.STARTTLS;
+ return port === SMTP_IMPLICIT_TLS_PORT ? SmtpTlsModes.IMPLICIT : SmtpTlsModes.STARTTLS;
}