emailengine-app 2.89.0 → 2.90.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 (72) hide show
  1. package/.ncurc.js +19 -8
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +44 -0
  4. package/Dockerfile +5 -1
  5. package/bin/healthcheck.js +1 -1
  6. package/copy-static-files.sh +0 -8
  7. package/data/google-crawlers.json +1 -1
  8. package/encrypt.js +1 -4
  9. package/lib/account/field-codec.js +396 -0
  10. package/lib/account.js +158 -453
  11. package/lib/api-routes/account-routes.js +42 -6
  12. package/lib/api-routes/route-metadata.js +5 -2
  13. package/lib/api-routes/submit-routes.js +15 -2
  14. package/lib/api-token-auth.js +342 -274
  15. package/lib/arf-detect.js +174 -149
  16. package/lib/attachment-size.js +29 -0
  17. package/lib/autodetect-imap-settings.js +83 -234
  18. package/lib/consts.js +1 -5
  19. package/lib/db.js +1 -4
  20. package/lib/email-client/base-client.js +907 -780
  21. package/lib/email-client/gmail-client.js +557 -450
  22. package/lib/email-client/imap/cid-parts.js +61 -0
  23. package/lib/email-client/imap/mailbox.js +376 -422
  24. package/lib/email-client/imap/sync-operations.js +239 -178
  25. package/lib/email-client/new-message-steps.js +168 -2
  26. package/lib/email-client/outlook/graph-message.js +266 -0
  27. package/lib/email-client/outlook/subscription-expiry.js +30 -0
  28. package/lib/email-client/outlook-client.js +652 -808
  29. package/lib/get-raw-email.js +338 -232
  30. package/lib/get-secret.js +1 -4
  31. package/lib/license-subscription.js +60 -0
  32. package/lib/load-env.js +48 -0
  33. package/lib/logger.js +1 -4
  34. package/lib/mcp/tools.js +244 -207
  35. package/lib/metric-values.js +76 -0
  36. package/lib/metrics.js +320 -0
  37. package/lib/oauth/gmail.js +39 -120
  38. package/lib/oauth/http-request.js +195 -0
  39. package/lib/oauth/mail-ru.js +24 -58
  40. package/lib/oauth/outlook.js +37 -137
  41. package/lib/oauth/pubsub/google.js +176 -117
  42. package/lib/oauth2-apps.js +440 -463
  43. package/lib/openapi/build-document.js +10 -10
  44. package/lib/read-env-value.js +1 -1
  45. package/lib/route-descriptors.js +78 -0
  46. package/lib/schemas.js +10 -1
  47. package/lib/sentry-integrations.js +299 -0
  48. package/lib/sentry.js +75 -27
  49. package/lib/sso-routes.js +249 -0
  50. package/lib/sso.js +29 -6
  51. package/lib/ui-routes/account-edit-form.js +198 -0
  52. package/lib/ui-routes/account-page.js +241 -0
  53. package/lib/ui-routes/account-routes.js +12 -318
  54. package/lib/ui-routes/auth-routes.js +10 -10
  55. package/lib/ui-view-context.js +328 -0
  56. package/lib/utils/public-suffix.js +22 -101
  57. package/lib/web-safe-html.js +20 -7
  58. package/lib/worker-metrics.js +82 -0
  59. package/list-generate.js +2 -5
  60. package/package.json +23 -19
  61. package/sbom.json +267 -908
  62. package/scripts/refresh-test-tokens.js +1 -1
  63. package/server.js +320 -676
  64. package/static/css/flyonui.css +1 -1
  65. package/static/css/src/app.tailwind.css +18 -0
  66. package/static/js/ee-client.js +2619 -645
  67. package/static/js/ui.js +12 -2
  68. package/static/licenses.html +219 -737
  69. package/translations/messages.pot +64 -53
  70. package/views/accounts/browse.hbs +19 -1
  71. package/workers/api.js +20 -451
  72. package/data/public_suffix_list.dat +0 -16698
@@ -16,6 +16,8 @@
16
16
  * removed when they run out, which is how every earlier release behaved.
17
17
  */
18
18
 
19
+ const { compareVersions, parseVersion } = require('./utils/version');
20
+
19
21
  const HOUR = 60 * 60 * 1000;
20
22
  const DAY = 24 * HOUR;
21
23
 
@@ -154,6 +156,61 @@ function expiredSuspension(subexp, subsusp, now) {
154
156
  return { code: 'SubscriptionInactive', error: 'Subscription inactive', since: new Date(deadline).toISOString() };
155
157
  }
156
158
 
159
+ /**
160
+ * Whether the record of the last successful validation no longer covers this instance, so the
161
+ * scheduled online check is allowed to run. It is covered while the version that validated (kv,
162
+ * hex) is this release or a later one and the record's own expiry (ks, hex ms) has not passed;
163
+ * an unreadable or missing record means checking again, which also rewrites it
164
+ * @param {Object} input
165
+ * @param {string|null} input.kv - the stored validated version
166
+ * @param {string|null} input.ks - the stored record expiry
167
+ * @param {string} input.version - the running version
168
+ * @param {number} input.now
169
+ * @returns {boolean}
170
+ */
171
+ function needsVersionRecheck({ kv, ks, version, now }) {
172
+ if (!ks || typeof ks !== 'string' || new Date(parseInt(ks, 16)) < now) {
173
+ return true;
174
+ }
175
+ let validatedVersion = kv && typeof kv === 'string' ? Buffer.from(kv, 'hex').toString() : null;
176
+ return !(parseVersion(validatedVersion) && compareVersions(version, validatedVersion) <= 0);
177
+ }
178
+
179
+ /**
180
+ * Which license the periodic check concerns, and whether a passed deadline suspends it before
181
+ * the license server is asked
182
+ * @param {Object} licenseInfo - the running license state (`active`, `suspension`, `details`)
183
+ * @param {Object} input
184
+ * @param {number|string|null} input.subexp - the stored deadline
185
+ * @param {string|null} input.subsusp - the stored suspension
186
+ * @param {number} input.now
187
+ * @returns {{subscriptionLicense: boolean, localSuspension: (Object|null)}} subscriptionLicense says
188
+ * the online check applies (a suspended license is still registered and still checked, which is
189
+ * how it resumes); localSuspension is the suspension record to apply now, or null
190
+ */
191
+ function subscriptionCheckState(licenseInfo, { subexp, subsusp, now }) {
192
+ let subscriptionLicense = (licenseInfo.active || !!licenseInfo.suspension) && isSubscriptionLicense(licenseInfo.details);
193
+ let localSuspension = subscriptionLicense && !licenseInfo.suspension ? expiredSuspension(subexp, subsusp, now) : null;
194
+ return { subscriptionLicense, localSuspension };
195
+ }
196
+
197
+ /**
198
+ * What a license check does to the licensed workers
199
+ * @param {boolean} licenseActive
200
+ * @param {number} suspendedTypes - how many worker types are suspended now
201
+ * @returns {'suspend'|'resume'|null} suspend every licensed worker type, respawn the suspended
202
+ * ones, or leave them as they are
203
+ */
204
+ function workerSuspensionChange(licenseActive, suspendedTypes) {
205
+ if (!licenseActive && !suspendedTypes) {
206
+ return 'suspend';
207
+ }
208
+ if (licenseActive && suspendedTypes) {
209
+ return 'resume';
210
+ }
211
+ return null;
212
+ }
213
+
157
214
  /**
158
215
  * What a start of EmailEngine does before any worker runs
159
216
  * @param {Object} input
@@ -230,6 +287,9 @@ module.exports = {
230
287
  decide,
231
288
  startupPlan,
232
289
  expiredSuspension,
290
+ needsVersionRecheck,
291
+ subscriptionCheckState,
292
+ workerSuspensionChange,
233
293
  checkInterval,
234
294
  subscriptionView,
235
295
  isSuspended,
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Loads `.env` from the working directory into process.env with Node's own parser
4
+ // (process.loadEnvFile, Node 21.7+), which replaced the dotenv package. Variables that are
5
+ // already set are never overwritten, the same as dotenv did.
6
+ //
7
+ // Dependency-free on purpose: server.js loads it before it checks the Node.js version, so it has
8
+ // to load on any release. On a release without process.loadEnvFile it does nothing, and the
9
+ // version check that follows tells the operator to upgrade.
10
+
11
+ /**
12
+ * Loads an env file, if there is one.
13
+ *
14
+ * A missing file is the normal case and is silent. A file that exists but cannot be read is
15
+ * reported on stderr and otherwise ignored, as dotenv ignored it: the instance then starts with
16
+ * the environment it was given rather than not at all.
17
+ *
18
+ * @param {string} [path='.env'] Resolved against the working directory
19
+ * @returns {boolean} Whether a file was loaded
20
+ */
21
+ function loadEnvFile(path = '.env') {
22
+ if (typeof process.loadEnvFile !== 'function') {
23
+ return false;
24
+ }
25
+ try {
26
+ process.loadEnvFile(path);
27
+ return true;
28
+ } catch (err) {
29
+ if (err.code !== 'ENOENT') {
30
+ process.stderr.write(`Could not load ${path}: ${err.message}\n`);
31
+ }
32
+ return false;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Loads `.env` once per process, however many modules ask. A worker thread starts with a copy of
38
+ * the main thread's process.env, marker included, so it does not load the file again; the tests set
39
+ * the marker themselves to keep a developer's own .env out of a child process.
40
+ */
41
+ function loadEnvOnce() {
42
+ if (!process.env.EE_ENV_LOADED) {
43
+ loadEnvFile();
44
+ process.env.EE_ENV_LOADED = 'true';
45
+ }
46
+ }
47
+
48
+ module.exports = { loadEnvFile, loadEnvOnce };
package/lib/logger.js CHANGED
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- if (!process.env.EE_ENV_LOADED) {
4
- require('dotenv').config({ quiet: true });
5
- process.env.EE_ENV_LOADED = 'true';
6
- }
3
+ require('./load-env').loadEnvOnce();
7
4
 
8
5
  const config = require('@zone-eu/wild-config');
9
6
  const pino = require('pino');