emailengine-app 2.85.0 → 2.87.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.
Files changed (137) hide show
  1. package/.ncurc.js +24 -6
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +97 -0
  4. package/DOCKER_DEPLOYMENT.md +2 -1
  5. package/Dockerfile +16 -3
  6. package/ENVIRONMENT.md +139 -0
  7. package/README.md +5 -1
  8. package/config/default.toml +2 -0
  9. package/copy-static-files.sh +4 -2
  10. package/data/google-crawlers.json +1 -1
  11. package/data/public_suffix_list.dat +4 -3
  12. package/lib/account-assignment.js +19 -0
  13. package/lib/account.js +285 -195
  14. package/lib/api-error-codes.js +49 -0
  15. package/lib/api-reference/model.js +6 -1
  16. package/lib/api-routes/account-routes.js +91 -32
  17. package/lib/api-routes/blocklist-routes.js +68 -2
  18. package/lib/api-routes/delivery-test-routes.js +1 -1
  19. package/lib/api-routes/gateway-routes.js +82 -10
  20. package/lib/api-routes/index.js +4 -0
  21. package/lib/api-routes/license-routes.js +2 -2
  22. package/lib/api-routes/mailbox-routes.js +3 -3
  23. package/lib/api-routes/message-routes.js +15 -7
  24. package/lib/api-routes/oauth2-app-routes.js +15 -8
  25. package/lib/api-routes/outbox-routes.js +77 -66
  26. package/lib/api-routes/permission-map.js +55 -6
  27. package/lib/api-routes/scoped-routes.js +74 -0
  28. package/lib/api-routes/settings-routes.js +11 -4
  29. package/lib/api-routes/stats-routes.js +5 -1
  30. package/lib/api-routes/submit-routes.js +25 -5
  31. package/lib/api-routes/template-routes.js +7 -6
  32. package/lib/api-routes/token-routes.js +11 -5
  33. package/lib/api-routes/webhook-delivery-routes.js +262 -0
  34. package/lib/api-routes/webhook-route-routes.js +119 -4
  35. package/lib/calendar-event.js +81 -1
  36. package/lib/consts.js +38 -46
  37. package/lib/db.js +14 -6
  38. package/lib/delivery-error.js +6 -0
  39. package/lib/deprecations.js +270 -0
  40. package/lib/email-client/base-client.js +134 -158
  41. package/lib/email-client/fallback-poll.js +62 -0
  42. package/lib/email-client/gmail-client.js +59 -11
  43. package/lib/email-client/imap/adaptive-idle-store.js +73 -0
  44. package/lib/email-client/imap/adaptive-idle.js +278 -0
  45. package/lib/email-client/imap/connection-errors.js +14 -1
  46. package/lib/email-client/imap/idle-settings.js +31 -5
  47. package/lib/email-client/imap/listing-diff.js +37 -0
  48. package/lib/email-client/imap/mailbox.js +380 -227
  49. package/lib/email-client/imap/subconnection.js +7 -29
  50. package/lib/email-client/imap/sync-operations.js +220 -127
  51. package/lib/email-client/imap-client.js +227 -163
  52. package/lib/email-client/message-builder.js +14 -79
  53. package/lib/email-client/outlook-client.js +378 -338
  54. package/lib/email-client/smtp-pool-manager.js +16 -13
  55. package/lib/email-client/sync-state-fields.js +19 -0
  56. package/lib/encrypt.js +157 -41
  57. package/lib/enum-descriptions.js +3 -1
  58. package/lib/env-setting-overrides.js +288 -0
  59. package/lib/export-worker.js +751 -0
  60. package/lib/export.js +64 -15
  61. package/lib/field-usage.js +1 -1
  62. package/lib/gateway.js +17 -1
  63. package/lib/get-raw-email.js +35 -108
  64. package/lib/health.js +75 -0
  65. package/lib/lock-run.js +119 -0
  66. package/lib/logger-consts.js +48 -0
  67. package/lib/logger.js +1 -1
  68. package/lib/lua/z-head-scores.lua +28 -0
  69. package/lib/network-errors.js +1 -1
  70. package/lib/node-version.js +24 -0
  71. package/lib/notify-attachments.js +20 -1
  72. package/lib/oauth/gmail.js +54 -29
  73. package/lib/oauth2-apps.js +630 -655
  74. package/lib/otp.js +66 -0
  75. package/lib/outbox.js +184 -54
  76. package/lib/parse-message.js +3 -3
  77. package/lib/privileged-settings.js +2 -2
  78. package/lib/queue-browser/definitions.js +11 -0
  79. package/lib/queue-browser/index.js +68 -19
  80. package/lib/queue-job-actions.js +18 -1
  81. package/lib/queue-retention.js +48 -12
  82. package/lib/queue-stats.js +11 -2
  83. package/lib/read-env-value.js +3 -0
  84. package/lib/redis-memory-warnings.js +99 -0
  85. package/lib/redis-reconnect.js +29 -0
  86. package/lib/request-timing.js +23 -0
  87. package/lib/respawn-backoff.js +35 -0
  88. package/lib/rewrite-text-nodes.js +19 -59
  89. package/lib/schemas.js +225 -41
  90. package/lib/settings.js +6 -2
  91. package/lib/smtp-auth.js +19 -1
  92. package/lib/swagger-options.js +2 -2
  93. package/lib/thread-diagnostics.js +18 -1
  94. package/lib/tls/provision.js +6 -3
  95. package/lib/token-audit-log.js +19 -20
  96. package/lib/token-permission-view.js +4 -3
  97. package/lib/tools.js +8 -41
  98. package/lib/ui-routes/admin-config-routes.js +64 -90
  99. package/lib/ui-routes/admin-entities-routes.js +2 -14
  100. package/lib/ui-routes/imap-idle-field.js +1 -1
  101. package/lib/ui-routes/outlook-subscription-view.js +1 -1
  102. package/lib/ui-routes/overridable-fields.js +84 -0
  103. package/lib/ui-routes/queue-routes.js +8 -5
  104. package/lib/ui-routes/settings-page.js +6 -0
  105. package/lib/utils/decode-headers.js +3 -12
  106. package/lib/utils/filter-empty.js +20 -0
  107. package/lib/utils/int-setting.js +48 -0
  108. package/lib/utils/tracking-settings.js +35 -0
  109. package/lib/web-safe-html.js +18 -105
  110. package/lib/webhook-delivery.js +461 -0
  111. package/lib/webhook-failures.js +132 -0
  112. package/lib/webhook-request.js +29 -1
  113. package/lib/webhook-routing.js +30 -1
  114. package/lib/webhook-test.js +88 -0
  115. package/lib/webhooks.js +59 -41
  116. package/lib/worker-rpc-error.js +2 -1
  117. package/package.json +28 -26
  118. package/sbom.json +600 -678
  119. package/server.js +149 -76
  120. package/static/css/flyonui.css +1 -1
  121. package/static/js/ace/ace.js +1 -1
  122. package/static/js/ee-client.js +650 -196
  123. package/static/licenses.html +49 -59
  124. package/translations/messages.pot +26 -26
  125. package/views/config/security.hbs +22 -0
  126. package/views/config/service.hbs +44 -0
  127. package/views/config/webhooks.hbs +36 -0
  128. package/views/layout/app.hbs +9 -6
  129. package/views/legal.hbs +8 -0
  130. package/views/partials/queue_retention_note.hbs +12 -8
  131. package/views/partials/ui/env-managed-alert.hbs +16 -7
  132. package/workers/api.js +112 -37
  133. package/workers/export.js +16 -631
  134. package/workers/imap.js +13 -0
  135. package/workers/smtp.js +9 -11
  136. package/workers/webhooks.js +18 -432
  137. package/lib/email-client/outlook-fallback-poll.js +0 -30
@@ -0,0 +1,270 @@
1
+ 'use strict';
2
+
3
+ // Interfaces that are scheduled for removal, and how their callers are told. Dependency-free, so
4
+ // the route modules and server.js can both use it and a test needs nothing running.
5
+ //
6
+ // - The pre-2.79 token endpoints (POST /v1/token, DELETE /v1/token/{token},
7
+ // GET /v1/tokens/account/{account}) answer with the Deprecation (RFC 9745), Sunset (RFC 8594)
8
+ // and Link rel="successor-version" headers, and each use is logged at warn, at most once an hour
9
+ // per endpoint and worker, so a busy integration does not flood the log. A route opts in with a
10
+ // `plugins.deprecation` block ({ since, successor, link }), which the one server-level
11
+ // onPreResponse extension from deprecationExt() reads, the way lib/security-headers.js reads
12
+ // `plugins.securityHeaders`.
13
+ // - The /admin/bull-board redirects to the queue browser, through the same plugins.deprecation
14
+ // block as the token endpoints.
15
+ // - The legacy SMTP server options (EENGINE_SMTP_ENABLED/_SECRET/_PORT/_HOST/_PROXY and the matching
16
+ // [smtp] config keys) only seed the SMTP server settings on a first start. Their use is logged at
17
+ // startup. The EENGINE_SMTP_TLS_* variables and [smtp] maxMessageSize / maxClients are current
18
+ // and not affected.
19
+ // - Request fields that are still accepted although what they controlled is gone or replaced
20
+ // (DEPRECATED_FIELDS). Their schema carries a custom rule from deprecatedField(), so a request
21
+ // that sends one is logged at warn, at most once an hour per field and worker, from whichever
22
+ // route and location it arrives through. The rule is on the schema rather than on the routes
23
+ // because most of these fields are shared by several routes and nested in their payloads.
24
+
25
+ const REMOVAL_DATE = '2027-01-01';
26
+
27
+ // HTTP-date form of REMOVAL_DATE, for the Sunset header
28
+ const SUNSET_HTTP_DATE = new Date(`${REMOVAL_DATE}T00:00:00Z`).toUTCString();
29
+
30
+ // When the token endpoints were deprecated: the 2.79.0 release, which renamed them
31
+ const TOKEN_ROUTES_DEPRECATED_AT = Date.parse('2026-08-18T07:47:01Z');
32
+
33
+ // When the /admin/bull-board redirects were deprecated: the 2.84.0 release, which replaced
34
+ // bull-board with the queue browser at /admin/queues
35
+ const BULL_BOARD_REDIRECTS_DEPRECATED_AT = Date.parse('2026-10-15T07:35:26Z');
36
+
37
+ const LOG_INTERVAL = 60 * 60 * 1000;
38
+
39
+ const LEGACY_SMTP_ENV = ['EENGINE_SMTP_ENABLED', 'EENGINE_SMTP_SECRET', 'EENGINE_SMTP_PORT', 'EENGINE_SMTP_HOST', 'EENGINE_SMTP_PROXY'];
40
+
41
+ // The built-in values of the legacy [smtp] keys (config/default.toml); only a different value
42
+ // means an operator set one
43
+ const LEGACY_SMTP_CONFIG_DEFAULTS = { enabled: false, port: 2525, host: '127.0.0.1', secret: '', proxy: false };
44
+
45
+ /**
46
+ * Response headers that announce a deprecated endpoint
47
+ * @param {number} deprecatedAt - When it was deprecated, in milliseconds
48
+ * @param {string} [link] - Path of the endpoint to use instead, for the Link header. Left out where
49
+ * the successor path would have to carry a request parameter, such as a token
50
+ * @returns {Object} Header name to value
51
+ */
52
+ function deprecationHeaders(deprecatedAt, link) {
53
+ const headers = {
54
+ Deprecation: `@${Math.floor(deprecatedAt / 1000)}`,
55
+ Sunset: SUNSET_HTTP_DATE
56
+ };
57
+ if (link) {
58
+ headers.Link = `<${link}>; rel="successor-version"`;
59
+ }
60
+ return headers;
61
+ }
62
+
63
+ /**
64
+ * A per-key once-per-LOG_INTERVAL gate, so a deprecated endpoint or field in constant use is
65
+ * reported each hour instead of on every request
66
+ * @param {Function} now - Clock
67
+ * @returns {Function} (key) => true when the use of key is to be logged now
68
+ */
69
+ function createLogThrottle(now) {
70
+ const lastLogged = new Map();
71
+ return key => {
72
+ const time = now();
73
+ if (lastLogged.has(key) && time - lastLogged.get(key) < LOG_INTERVAL) {
74
+ return false;
75
+ }
76
+ lastLogged.set(key, time);
77
+ return true;
78
+ };
79
+ }
80
+
81
+ /**
82
+ * Server-level onPreResponse extension for deprecated endpoints. A route declares itself with
83
+ * `options.plugins.deprecation`:
84
+ * - `since` - when it was deprecated, in milliseconds
85
+ * - `successor` - the endpoint to use instead, as logged, e.g. "POST /v1/tokens"
86
+ * - `link` - optional, its path for the Link header, see deprecationHeaders()
87
+ * Every response of such a route, errors included, carries the headers, and its use is logged
88
+ * @param {Object} opts
89
+ * @param {Object} opts.logger - pino logger
90
+ * @param {Function} [opts.now] - Clock, for tests
91
+ * @returns {Function} The extension method
92
+ */
93
+ function deprecationExt(opts) {
94
+ const { logger, now = Date.now } = opts;
95
+ // per method and path, so every deprecated endpoint in use is reported
96
+ const shouldLog = createLogThrottle(now);
97
+
98
+ return function deprecationResponse(request, h) {
99
+ const deprecation = request.route && request.route.settings.plugins && request.route.settings.plugins.deprecation;
100
+ if (!deprecation) {
101
+ return h.continue;
102
+ }
103
+
104
+ const response = request.response;
105
+ const target = response && response.isBoom ? response.output.headers : response && response.headers;
106
+ if (target) {
107
+ Object.assign(target, deprecationHeaders(deprecation.since, deprecation.link));
108
+ }
109
+
110
+ const method = request.method.toUpperCase();
111
+ if (shouldLog(`${method} ${request.route.path}`)) {
112
+ logger.warn({
113
+ msg: 'Deprecated API endpoint called',
114
+ method,
115
+ path: request.route.path,
116
+ successor: deprecation.successor,
117
+ removal: REMOVAL_DATE,
118
+ // the token's id (its hash), as the rate limiter logs it, never the token itself
119
+ token: (request.auth && request.auth.artifacts && request.auth.artifacts.id) || undefined
120
+ });
121
+ }
122
+
123
+ return h.continue;
124
+ };
125
+ }
126
+
127
+ /**
128
+ * The legacy SMTP server options an operator set
129
+ * @param {Object} opts
130
+ * @param {Function} opts.hasEnvValue - Whether an environment value is set (lib/read-env-value)
131
+ * @param {Object} [opts.smtpConfig] - The [smtp] section of the loaded config
132
+ * @returns {string[]} Option names, environment variables first
133
+ */
134
+ function legacySmtpOptionsInUse({ hasEnvValue, smtpConfig }) {
135
+ const used = LEGACY_SMTP_ENV.filter(name => hasEnvValue(name));
136
+ for (const [key, defaultValue] of Object.entries(LEGACY_SMTP_CONFIG_DEFAULTS)) {
137
+ const value = smtpConfig && smtpConfig[key];
138
+ if (value === undefined || value === null) {
139
+ continue;
140
+ }
141
+ // config values can arrive as strings from --smtp.port=2525 style arguments
142
+ if (String(value) !== String(defaultValue)) {
143
+ used.push(`[smtp] ${key}`);
144
+ }
145
+ }
146
+ return used;
147
+ }
148
+
149
+ // The request fields deprecatedField() reports, with what to use instead (`successor`, as logged)
150
+ // and what the schema says about them (`note`, completed with the removal date). Removed after
151
+ // REMOVAL_DATE. A field is left out of the published API document unless `published` is set
152
+ const DEPRECATED_FIELDS = {
153
+ documentStore: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
154
+ syncFrom: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
155
+ documentStoreEnabled: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
156
+ generateRiskAssessment: { successor: 'nothing, the risk assessment was removed', note: 'Deprecated - This feature has been removed' },
157
+ openAiGenerateEmbeddings: {
158
+ successor: 'nothing, embeddings generation was removed in 2.82.0',
159
+ note: 'Deprecated - embeddings generation has been removed'
160
+ },
161
+ trackSentMessages: {
162
+ successor: 'the trackClicks and trackOpens settings',
163
+ note: 'Enable tracking features for outgoing messages. Deprecated, use trackClicks and trackOpens instead',
164
+ removedAfter: true
165
+ },
166
+ 'oauth2.authority': {
167
+ successor: 'the authority setting of the OAuth2 application',
168
+ note: 'Deprecated - Authority is set by the OAuth2 application configuration'
169
+ },
170
+ tenant: {
171
+ successor: 'the tenant ID as the authority of the OAuth2 application',
172
+ note: 'Deprecated, set the tenant ID as authority instead',
173
+ published: true
174
+ }
175
+ };
176
+
177
+ /**
178
+ * Reports uses of deprecated request fields, at most once per LOG_INTERVAL per field
179
+ * @param {Object} opts
180
+ * @param {Function} opts.getLogger - Returns the logger, resolved on the first report
181
+ * @param {Function} [opts.now] - Clock, for tests
182
+ * @returns {Function} (field) => void
183
+ */
184
+ function createFieldReporter(opts) {
185
+ const { getLogger, now = Date.now } = opts;
186
+ const shouldLog = createLogThrottle(now);
187
+
188
+ return function reportDeprecatedField(field) {
189
+ if (!shouldLog(field)) {
190
+ return;
191
+ }
192
+ getLogger().warn({
193
+ msg: 'Deprecated request field used',
194
+ field,
195
+ successor: DEPRECATED_FIELDS[field].successor,
196
+ removal: REMOVAL_DATE
197
+ });
198
+ };
199
+ }
200
+
201
+ // Resolved lazily: lib/schemas.js requires this module, and the logger has no business loading
202
+ // before something is actually reported
203
+ let defaultReporter = createFieldReporter({ getLogger: () => require('./logger') });
204
+
205
+ /**
206
+ * A joi custom rule that reports the use of a deprecated field and passes its value on unchanged.
207
+ * Joi runs it only for a value that is present, after `.empty()`, so an empty string sent by a form
208
+ * is not a use.
209
+ * @param {string} field - DEPRECATED_FIELDS key
210
+ * @returns {Array} Arguments for joi's `.custom()`
211
+ */
212
+ function deprecatedField(field) {
213
+ if (!Object.hasOwn(DEPRECATED_FIELDS, field)) {
214
+ throw new Error(`${field} is not a deprecated field`);
215
+ }
216
+ return [
217
+ value => {
218
+ defaultReporter(field);
219
+ return value;
220
+ },
221
+ `deprecated field ${field}`
222
+ ];
223
+ }
224
+
225
+ /**
226
+ * Marks a joi schema as a deprecated request field: reports its use (deprecatedField()), describes
227
+ * it from DEPRECATED_FIELDS with the removal date, and keeps it out of the API document unless the
228
+ * field is listed as published. The one place these three are applied, so a description can not
229
+ * drift from what is logged
230
+ * @param {Object} schema - joi schema
231
+ * @param {string} field - DEPRECATED_FIELDS key
232
+ * @returns {Object} The schema
233
+ */
234
+ function deprecated(schema, field) {
235
+ const rule = deprecatedField(field);
236
+ const { note, removedAfter, published } = DEPRECATED_FIELDS[field];
237
+ const description = removedAfter ? `${note}. Removed after ${REMOVAL_DATE}` : `${note}. Accepted until ${REMOVAL_DATE}`;
238
+ let marked = schema.custom(...rule).description(description);
239
+ if (!published) {
240
+ marked = marked.meta({ swaggerHidden: true });
241
+ }
242
+ return marked;
243
+ }
244
+
245
+ /**
246
+ * Replaces the reporter deprecatedField() rules call, for tests
247
+ * @param {Function} reporter - (field) => void
248
+ * @returns {Function} The previous reporter
249
+ */
250
+ function setFieldReporter(reporter) {
251
+ const previous = defaultReporter;
252
+ defaultReporter = reporter;
253
+ return previous;
254
+ }
255
+
256
+ module.exports = {
257
+ REMOVAL_DATE,
258
+ DEPRECATED_FIELDS,
259
+ createFieldReporter,
260
+ deprecatedField,
261
+ deprecated,
262
+ setFieldReporter,
263
+ SUNSET_HTTP_DATE,
264
+ TOKEN_ROUTES_DEPRECATED_AT,
265
+ BULL_BOARD_REDIRECTS_DEPRECATED_AT,
266
+ LOG_INTERVAL,
267
+ deprecationHeaders,
268
+ deprecationExt,
269
+ legacySmtpOptionsInUse
270
+ };