@lowdefy/connection-smtp 5.3.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,17 +13,37 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
+ import resolveMailFilter from '../resolveMailFilter.js';
16
17
  import send from '../send.js';
17
18
  import schema from './schema.js';
18
- async function SMTPMailSend({ request, connection }) {
19
+ async function SMTPMailSend({ request, connection, environment }) {
19
20
  const messages = type.isArray(request) ? request : [
20
21
  request
21
22
  ];
23
+ // The current environment can switch email off (config.environments.<env>.email.enabled: false):
24
+ // nothing is sent, and each message reports it was not.
25
+ if (environment?.email?.enabled === false) {
26
+ return {
27
+ response: 'Mail is disabled in this environment.',
28
+ results: messages.map(()=>({
29
+ messageId: null,
30
+ to: null,
31
+ disabled: true
32
+ }))
33
+ };
34
+ }
35
+ const filter = resolveMailFilter({
36
+ connection,
37
+ environment
38
+ });
22
39
  const results = [];
23
40
  // Send sequentially so a single SMTP connection or pool is not overwhelmed.
24
41
  for (const mail of messages){
25
42
  results.push(await send({
26
- connection,
43
+ connection: {
44
+ ...connection,
45
+ filter
46
+ },
27
47
  mail
28
48
  }));
29
49
  }
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ // The connection's own filter wins over the current environment's delivery filter
17
+ // (config.environments.<env>.email.filter) when it sets at least one field. `false` turns
18
+ // filtering off, the environment's too — for mail that must reach the real recipient in every
19
+ // environment. An unset connection filter, or one whose fields all resolve to null (a
20
+ // `_secret` that is not set on this deployment, say), falls back to the environment's, so a
21
+ // missing value can never switch the safety net off.
22
+ function setsAField(filter) {
23
+ if (!type.isObject(filter)) return false;
24
+ return [
25
+ 'replaceAddress',
26
+ 'allowlist',
27
+ 'regex'
28
+ ].some((field)=>!type.isNone(filter[field]));
29
+ }
30
+ function resolveMailFilter({ connection, environment }) {
31
+ if (connection.filter === false) return null;
32
+ if (setsAField(connection.filter)) return connection.filter;
33
+ return environment?.email?.filter ?? null;
34
+ }
35
+ export default resolveMailFilter;
@@ -101,12 +101,18 @@ export default {
101
101
  description: 'Default email address replies should be sent to.'
102
102
  },
103
103
  // null allowed on all filter values because they come from _secret;
104
- // unset secrets resolve null - an unset filter field is disabled.
104
+ // unset secrets resolve null - an unset filter field is disabled. An unset
105
+ // (null) filter falls back to the current environment's email filter;
106
+ // false turns filtering off, the environment's too.
105
107
  filter: {
106
108
  type: [
107
109
  'object',
108
- 'null'
110
+ 'null',
111
+ 'boolean'
109
112
  ],
113
+ not: {
114
+ const: true
115
+ },
110
116
  additionalProperties: false,
111
117
  properties: {
112
118
  replaceAddress: {
@@ -23,6 +23,7 @@ async function send({ connection, mail }) {
23
23
  if (filtered === null) {
24
24
  return {
25
25
  messageId: null,
26
+ to: null,
26
27
  filtered: true
27
28
  };
28
29
  }
@@ -39,8 +40,11 @@ async function send({ connection, mail }) {
39
40
  html: filtered.html,
40
41
  attachments: filtered.attachments
41
42
  });
43
+ // Return the post-filter to so callers can record where mail actually went
44
+ // when a connection filter (replaceAddress/allowlist/regex) rewrites it.
42
45
  return {
43
46
  messageId: info.messageId,
47
+ to: filtered.to,
44
48
  accepted: info.accepted,
45
49
  rejected: info.rejected
46
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/connection-smtp",
3
- "version": "5.3.0",
3
+ "version": "6.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -36,12 +36,12 @@
36
36
  "dist/*"
37
37
  ],
38
38
  "dependencies": {
39
- "@lowdefy/helpers": "5.3.0",
40
- "nodemailer": "9.0.3"
39
+ "@lowdefy/helpers": "6.1.0",
40
+ "nodemailer": "9.1.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@jest/globals": "28.1.3",
44
- "@lowdefy/ajv": "5.3.0",
44
+ "@lowdefy/ajv": "6.1.0",
45
45
  "@swc/cli": "0.8.1",
46
46
  "@swc/core": "1.15.32",
47
47
  "@swc/jest": "0.2.39",