emailengine-app 2.79.0 → 2.79.2

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 (110) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +79 -0
  3. package/bin/emailengine.js +8 -1
  4. package/config/default.toml +6 -0
  5. package/data/google-crawlers.json +1 -1
  6. package/lib/account.js +137 -19
  7. package/lib/api-routes/account-routes.js +13 -1
  8. package/lib/api-routes/index.js +12 -0
  9. package/lib/api-routes/mailbox-routes.js +6 -0
  10. package/lib/api-routes/mcp-oauth-routes.js +259 -0
  11. package/lib/api-routes/mcp-routes.js +172 -0
  12. package/lib/api-routes/message-routes.js +125 -4
  13. package/lib/api-routes/outbox-routes.js +7 -0
  14. package/lib/api-routes/permission-map.js +101 -1
  15. package/lib/api-routes/route-helpers.js +87 -4
  16. package/lib/api-routes/route-metadata.js +24 -4
  17. package/lib/api-routes/settings-routes.js +37 -14
  18. package/lib/api-routes/submit-routes.js +41 -0
  19. package/lib/api-routes/template-routes.js +7 -0
  20. package/lib/api-routes/token-routes.js +292 -122
  21. package/lib/arf-detect.js +17 -4
  22. package/lib/bounce-detect.js +28 -17
  23. package/lib/consts.js +36 -1
  24. package/lib/db.js +6 -0
  25. package/lib/email-client/base-client.js +102 -117
  26. package/lib/email-client/gmail-client.js +91 -29
  27. package/lib/email-client/imap/mailbox.js +175 -101
  28. package/lib/email-client/imap-client.js +49 -2
  29. package/lib/email-client/outlook-client.js +20 -24
  30. package/lib/enum-descriptions.js +2 -1
  31. package/lib/field-usage.js +17 -1
  32. package/lib/lua/h-set-new-mark.lua +36 -0
  33. package/lib/lua/s-list-accounts.lua +5 -2
  34. package/lib/mcp/index.js +29 -0
  35. package/lib/mcp/inject.js +70 -0
  36. package/lib/mcp/json-schema.js +120 -0
  37. package/lib/mcp/listen.js +171 -0
  38. package/lib/mcp/oauth.js +324 -0
  39. package/lib/mcp/protocol.js +489 -0
  40. package/lib/mcp/resources.js +139 -0
  41. package/lib/mcp/tools.js +655 -0
  42. package/lib/message-port-stream.js +84 -1
  43. package/lib/oauth2-apps.js +84 -15
  44. package/lib/openapi/build-document.js +5 -1
  45. package/lib/openapi/index.js +3 -1
  46. package/lib/response-stream.js +52 -21
  47. package/lib/routes-ui.js +4 -0
  48. package/lib/schemas.js +26 -5
  49. package/lib/settings.js +23 -9
  50. package/lib/token-audit-log.js +32 -9
  51. package/lib/token-permission-view.js +104 -8
  52. package/lib/tokens.js +194 -68
  53. package/lib/tools.js +96 -0
  54. package/lib/ui-routes/account-routes.js +55 -6
  55. package/lib/ui-routes/admin-config-routes.js +114 -1
  56. package/lib/ui-routes/admin-entities-routes.js +103 -19
  57. package/lib/ui-routes/auth-routes.js +13 -0
  58. package/lib/ui-routes/mcp-consent-routes.js +330 -0
  59. package/lib/ui-routes/oauth-config-routes.js +7 -7
  60. package/lib/ui-routes/route-helpers.js +143 -1
  61. package/lib/ui-routes/suppression-list-routes.js +14 -9
  62. package/lib/utils/decode-headers.js +42 -0
  63. package/lib/utils/header-map.js +48 -0
  64. package/lib/utils/network.js +9 -1
  65. package/lib/utils/unsafe-key.js +59 -0
  66. package/lib/web-safe-html.js +61 -0
  67. package/lib/webhook-routing.js +6 -2
  68. package/lib/webhooks.js +31 -8
  69. package/package.json +9 -8
  70. package/sbom.json +1 -1
  71. package/scripts/README.md +25 -0
  72. package/scripts/build-icon.js +77 -0
  73. package/server.js +39 -17
  74. package/static/css/flyonui.css +1 -1
  75. package/static/css/src/app.tailwind.css +98 -0
  76. package/static/emailengine.ico +0 -0
  77. package/static/js/ui.js +465 -1
  78. package/static/licenses.html +42 -22
  79. package/translations/messages.pot +57 -57
  80. package/views/accounts/account.hbs +8 -8
  81. package/views/accounts/browse.hbs +1 -1
  82. package/views/accounts/edit.hbs +2 -2
  83. package/views/config/mcp.hbs +361 -0
  84. package/views/config/oauth/index.hbs +7 -0
  85. package/views/gateways/edit.hbs +1 -1
  86. package/views/gateways/gateway.hbs +2 -2
  87. package/views/gateways/index.hbs +7 -7
  88. package/views/layout/prompt.hbs +62 -0
  89. package/views/mcp/authorize.hbs +136 -0
  90. package/views/partials/accounts_table.hbs +7 -7
  91. package/views/partials/head_assets.hbs +3 -3
  92. package/views/partials/mcp_access_levels.hbs +13 -0
  93. package/views/partials/mcp_account_limit.hbs +14 -0
  94. package/views/partials/mcp_tool_count.hbs +19 -0
  95. package/views/partials/side_menu.hbs +1 -0
  96. package/views/partials/ui/account-picker.hbs +59 -0
  97. package/views/partials/ui/code-block.hbs +26 -0
  98. package/views/partials/ui/menu-item.hbs +5 -0
  99. package/views/partials/ui/radio.hbs +41 -0
  100. package/views/partials/ui/tab.hbs +15 -10
  101. package/views/partials/ui/tabs.hbs +8 -5
  102. package/views/suppression-lists/list.hbs +1 -1
  103. package/views/templates/index.hbs +2 -2
  104. package/views/templates/template.hbs +5 -4
  105. package/views/tokens/index.hbs +30 -4
  106. package/views/tokens/new.hbs +517 -239
  107. package/winconf.js +148 -48
  108. package/workers/api.js +239 -95
  109. package/workers/imap.js +65 -72
  110. package/workers/webhooks.js +21 -1
package/scripts/README.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Scripts
2
2
 
3
+ ## build-icon.js
4
+
5
+ Regenerates `static/emailengine.ico` from `static/logo.png`. The result is committed, so run
6
+ this only when the logo artwork changes - a normal build does not need ImageMagick.
7
+
8
+ ### Usage
9
+
10
+ ```bash
11
+ brew install imagemagick
12
+ npm run build:icon
13
+ ```
14
+
15
+ ### What it does
16
+
17
+ Builds a 7-image icon (256, 128, 64, 48, 32, 24, 16), PNG-compressing the two largest members
18
+ and using uncompressed 32-bit DIBs for the rest.
19
+
20
+ ### Notes
21
+
22
+ - Do not replace it with a plain `magick -define icon:auto-resize=...` call. ImageMagick writes
23
+ every member as an uncompressed BMP, and the resulting icon is large enough to break the
24
+ packaged Windows executable outright. The header comment in the script explains why.
25
+ - `winconf.js` prints the remaining `.rsrc` headroom on every build. That number is the budget
26
+ for any future icon or resource change.
27
+
3
28
  ## refresh-test-tokens.js
4
29
 
5
30
  Helper script to refresh OAuth2 tokens for Gmail test accounts.
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Regenerates static/emailengine.ico, the icon winconf.js stamps into the Windows executable.
5
+ // Run it when the logo artwork changes; the result is committed, so a normal build needs
6
+ // neither this script nor ImageMagick.
7
+ //
8
+ // The members are assembled here rather than by a single `magick -define icon:auto-resize=...`
9
+ // call because ImageMagick writes every one of them as an uncompressed BMP, and a 256x256 BMP
10
+ // alone is 270KB. The resulting icon is large enough to break the packaged exe - see the comment
11
+ // on payloadOffset() in winconf.js - so the two biggest sizes are PNG-compressed instead, which
12
+ // keeps the whole file around 63KB.
13
+
14
+ const { load } = require('resedit/cjs');
15
+ const { execFileSync } = require('child_process');
16
+ const { mkdtempSync, readFileSync, writeFileSync, rmSync } = require('fs');
17
+ const { tmpdir } = require('os');
18
+ const { join, resolve } = require('path');
19
+
20
+ const SOURCE = resolve(__dirname, '../static/logo.png');
21
+ const TARGET = resolve(__dirname, '../static/emailengine.ico');
22
+
23
+ // Windows renders the icon at all of these: 16 in the Explorer list view and the title bar, 32
24
+ // and 48 in the larger views, 256 for the extra large one. PNG for the two biggest, an
25
+ // uncompressed 32-bit DIB for the rest, which is the convention Windows has read since Vista
26
+ const PNG_SIZES = [256, 128];
27
+ const BMP_SIZES = [64, 48, 32, 24, 16];
28
+
29
+ function magick(args) {
30
+ try {
31
+ execFileSync('magick', args, { stdio: ['ignore', 'ignore', 'pipe'] });
32
+ } catch (err) {
33
+ if (err.code === 'ENOENT') {
34
+ throw new Error('ImageMagick is required to rebuild the icon: brew install imagemagick', { cause: err });
35
+ }
36
+ throw new Error(`magick ${args.join(' ')} failed: ${String(err.stderr || err.message).trim()}`, { cause: err });
37
+ }
38
+ }
39
+
40
+ load()
41
+ .then(ResEdit => {
42
+ const workDir = mkdtempSync(join(tmpdir(), 'ee-icon-'));
43
+
44
+ try {
45
+ const icons = [];
46
+
47
+ for (let size of PNG_SIZES) {
48
+ const file = join(workDir, `png-${size}.png`);
49
+ magick([SOURCE, '-background', 'none', '-resize', `${size}x${size}`, '-strip', '-define', 'png:compression-level=9', file]);
50
+ // The dimensions have to be passed in: RawIconItem does not read them out of the
51
+ // PNG header, and without them the directory entry is written as 0x0 at 0bpp
52
+ icons.push({ data: ResEdit.Data.RawIconItem.from(readFileSync(file), size, size, 32) });
53
+ }
54
+
55
+ // ImageMagick's own DIB members are well formed, so the small sizes are taken from an
56
+ // ico it builds rather than encoded here
57
+ const smallIco = join(workDir, 'small.ico');
58
+ magick([SOURCE, '-background', 'none', '-define', `icon:auto-resize=${BMP_SIZES.join(',')}`, smallIco]);
59
+ icons.push(...ResEdit.Data.IconFile.from(readFileSync(smallIco)).icons);
60
+
61
+ const iconFile = new ResEdit.Data.IconFile();
62
+ iconFile.icons = icons;
63
+
64
+ const ico = Buffer.from(iconFile.generate());
65
+ writeFileSync(TARGET, ico);
66
+
67
+ console.log(`Wrote ${TARGET}`);
68
+ console.log(` ${icons.length} images: ${icons.map(icon => `${icon.data.width}x${icon.data.height}`).join(', ')}`);
69
+ console.log(` ${ico.length} bytes`);
70
+ } finally {
71
+ rmSync(workDir, { recursive: true, force: true });
72
+ }
73
+ })
74
+ .catch(err => {
75
+ console.error('Error building the icon:', err);
76
+ process.exit(1);
77
+ });
package/server.js CHANGED
@@ -115,6 +115,7 @@ initSentry('main');
115
115
  // Import additional dependencies
116
116
  const pathlib = require('path');
117
117
  const { redis, queueConf, notifyQueue, submitQueue, documentsQueue, exportQueue } = require('./lib/db');
118
+ const { queueStats } = require('./lib/queue-stats');
118
119
  const { packRpcError, unpackRpcError } = require('./lib/worker-rpc-error');
119
120
  const promClient = require('prom-client');
120
121
  const fs = require('fs').promises;
@@ -446,7 +447,9 @@ const preparedSettingsString = readEnvValue('EENGINE_SETTINGS') || config.settin
446
447
  if (preparedSettingsString) {
447
448
  // Parse and validate pre-configured settings
448
449
  try {
449
- const { error, value } = Joi.object(settingsSchema).validate(JSON.parse(preparedSettingsString), {
450
+ const parsedSettings = JSON.parse(preparedSettingsString);
451
+
452
+ const { error, value } = Joi.object(settingsSchema).validate(parsedSettings, {
450
453
  abortEarly: false,
451
454
  stripUnknown: true,
452
455
  convert: true
@@ -456,6 +459,22 @@ if (preparedSettingsString) {
456
459
  throw error;
457
460
  }
458
461
 
462
+ // stripUnknown drops unknown keys without an error, which silently swallows both typos
463
+ // and keys that used to be settings - most notably the legacy gmail*/outlook*/mailRu*
464
+ // OAuth2 keys that moved into the OAuth2 app registry. Booting on regardless is right
465
+ // (an upgraded install must not be bricked by a stale env variable), but the drop has
466
+ // to be visible: for the legacy keys the operator has to create an OAuth2 app instead,
467
+ // because nothing reads these values anymore.
468
+ if (parsedSettings && typeof parsedSettings === 'object') {
469
+ const droppedKeys = Object.keys(parsedSettings).filter(key => !Object.hasOwn(settingsSchema, key));
470
+ if (droppedKeys.length) {
471
+ logger.error({
472
+ msg: 'Ignoring unknown keys in the prepared settings. Settings-based OAuth2 configuration is not supported anymore - use an OAuth2 app instead',
473
+ keys: droppedKeys
474
+ });
475
+ }
476
+ }
477
+
459
478
  preparedSettings = value;
460
479
  } catch (err) {
461
480
  // A joi failure here carries every submitted setting - including smtpServerPassword,
@@ -2248,25 +2267,28 @@ async function updateQueueCounters() {
2248
2267
  // Set unresponsive workers metric
2249
2268
  metrics.unresponsiveWorkers.set(unresponsiveCount);
2250
2269
 
2251
- // Update queue metrics
2252
- for (let queue of ['notify', 'submit', 'documents']) {
2253
- const [resActive, resDelayed, resPaused, resWaiting] = await redis
2254
- .multi()
2255
- .llen(`${REDIS_PREFIX}bull:${queue}:active`)
2256
- .zcard(`${REDIS_PREFIX}bull:${queue}:delayed`)
2257
- .llen(`${REDIS_PREFIX}bull:${queue}:paused`)
2258
- .llen(`${REDIS_PREFIX}bull:${queue}:wait`)
2259
- .exec();
2260
- let countError = resActive[0] || resDelayed[0] || resPaused[0] || resWaiting[0];
2261
- if (countError) {
2262
- logger.error({ msg: 'Queue length count failed', queue, err: countError });
2270
+ // Update queue metrics through BullMQ's own API (lib/queue-stats.js). Counting raw
2271
+ // llen/zcard against BullMQ's private key layout broke silently in the 5.x -> 6.x bump: the
2272
+ // `:paused` list no longer exists (a paused queue holds its jobs in `wait`), and a leftover
2273
+ // `0:` wait-list marker from a 5.x install counts as a phantom waiting job. The `paused`
2274
+ // gauge is kept at the 0 the getter reports so existing dashboards keep their series.
2275
+ for (let [queue, queueObj] of [
2276
+ ['notify', notifyQueue],
2277
+ ['submit', submitQueue],
2278
+ ['documents', documentsQueue]
2279
+ ]) {
2280
+ let stats;
2281
+ try {
2282
+ stats = await queueStats(queueObj);
2283
+ } catch (err) {
2284
+ logger.error({ msg: 'Queue length count failed', queue, err });
2263
2285
  return false;
2264
2286
  }
2265
2287
 
2266
- metrics.queues.set({ queue: `${queue}`, state: `active` }, Number(resActive[1]) || 0);
2267
- metrics.queues.set({ queue: `${queue}`, state: `delayed` }, Number(resDelayed[1]) || 0);
2268
- metrics.queues.set({ queue: `${queue}`, state: `paused` }, Number(resPaused[1]) || 0);
2269
- metrics.queues.set({ queue: `${queue}`, state: `waiting` }, Number(resWaiting[1]) || 0);
2288
+ metrics.queues.set({ queue: `${queue}`, state: `active` }, stats.active);
2289
+ metrics.queues.set({ queue: `${queue}`, state: `delayed` }, stats.delayed);
2290
+ metrics.queues.set({ queue: `${queue}`, state: `paused` }, stats.paused);
2291
+ metrics.queues.set({ queue: `${queue}`, state: `waiting` }, stats.waiting);
2270
2292
  }
2271
2293
 
2272
2294
  // Update Redis metrics