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
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Lives here rather than in lib/tools.js so that pure modules and tests can use it: tools.js
4
+ // opens Redis, which drags a connection into anything that only wants to collect header values.
5
+
6
+ /**
7
+ * Appends one value to a header map keyed by lowercased header name.
8
+ *
9
+ * Header names come from the remote server, so any sender can pick one that names an
10
+ * Object.prototype member. On a plain object `headers['__proto__']` reads back the prototype
11
+ * instead of an array, and assigning to it hands the value to the prototype setter rather than
12
+ * storing a key - so a bare `!headers[key]` probe pushes onto something that is not an array and
13
+ * throws. Lowercasing leaves exactly two such names, "__proto__" and "constructor", and both are
14
+ * dropped rather than collected: storing them would need an own "__proto__" key, which msgpack
15
+ * refuses to decode (test/msgpack-compat-test.js) and which hands webhook consumers a prototype
16
+ * pollution gadget of their own.
17
+ *
18
+ * Only the accumulate-by-assignment shape is guarded here. A header block parsed by libmime
19
+ * arrives with these names already set as own properties, which this cannot detect, so
20
+ * lib/utils/decode-headers.js drops them after the fact for the IMAP and bounce paths.
21
+ *
22
+ * The array is read before the `in` probe on purpose. `in` walks the prototype chain and has no
23
+ * fast path for the freshly lowercased (non-internalized) key, which made it roughly twice the
24
+ * cost of the whole loop; reading first keeps `in` on the miss path only.
25
+ *
26
+ * @param {Object} headers - Map of lowercased header name to array of values
27
+ * @param {String} key - Lowercased header name
28
+ * @param {String} value - Value to append
29
+ * @returns {Boolean} True when the value was stored, false when the name was skipped
30
+ */
31
+ function pushHeaderValue(headers, key, value) {
32
+ let values = headers[key];
33
+
34
+ if (Array.isArray(values)) {
35
+ values.push(value);
36
+ return true;
37
+ }
38
+
39
+ // Not an array: either the name is unused, or it resolves to a prototype member
40
+ if (key in headers) {
41
+ return false;
42
+ }
43
+
44
+ headers[key] = [value];
45
+ return true;
46
+ }
47
+
48
+ module.exports = { pushHeaderValue };
@@ -58,7 +58,15 @@ function parseComparableCidr(range) {
58
58
  let [parsed, bits] = ipaddr.parseCIDR(range);
59
59
 
60
60
  if (parsed.kind() === 'ipv6' && parsed.isIPv4MappedAddress()) {
61
- return [parsed.toIPv4Address(), Math.max(bits - 96, 0)];
61
+ // A prefix shorter than the 96-bit mapped block does not describe an IPv4 subnet: it spans
62
+ // out of the mapped range entirely. Clamping the remainder to zero turned such an entry
63
+ // into 0.0.0.0/0 - one mistyped digit in an allowlist and every IPv4 address matched, which
64
+ // is the one direction an allowlist must never fail in. Refused instead, so the caller logs
65
+ // it as the configuration error it is and the entry matches nothing.
66
+ if (bits < 96) {
67
+ throw new Error(`IPv4-mapped range ${range} has a prefix shorter than the 96-bit mapped block`);
68
+ }
69
+ return [parsed.toIPv4Address(), bits - 96];
62
70
  }
63
71
 
64
72
  return [parsed, bits];
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ // Lives here rather than in lib/tools.js so that pure modules and tests can use it: tools.js opens
4
+ // Redis, which drags a connection into anything that only wants to parse a message.
5
+
6
+ // Names that resolve to an Object.prototype member. Header names come from the message, so any
7
+ // sender can pick one, and the maps built from them are plain objects:
8
+ //
9
+ // - assigning "__proto__" hands the value to the prototype setter and swaps the map's prototype
10
+ // instead of storing a key, and defining it as an own property instead leaves a key
11
+ // lib/msgpack.js refuses to decode - so a map carrying one encodes into webhook logs and message
12
+ // payloads that can never be read back
13
+ // - "constructor" is inert on its own, but lib/utils/header-map.js cannot represent it, so keeping
14
+ // it would describe the same message differently depending on the transport that fetched it
15
+ //
16
+ // The names a message supplies arrive lowercased, which leaves exactly these two. Kept as an
17
+ // explicit list rather than an `in {}` probe so that what gets dropped is readable at a glance, and
18
+ // so that names like "toString" - which cannot collide with a lowercased key, and which no real
19
+ // header or subtype uses either - are not dropped as a side effect.
20
+ const UNSAFE_KEYS = ['__proto__', 'constructor'];
21
+
22
+ /**
23
+ * Tells whether a key is one a plain-object map built from a message must not carry - header names,
24
+ * but also anything else the message names, such as the MIME subtype lib/email-client/imap/mailbox.js
25
+ * groups text parts by.
26
+ *
27
+ * Applied at the parse boundary (lib/utils/decode-headers.js), and again after any transform that
28
+ * rebuilds a key from a name. A transform can manufacture one of these out of an input the parse
29
+ * boundary had no reason to drop: toCamelCase() turns "_-_proto__" into "__proto__", so a guard
30
+ * that only ran before it never saw the name it exists to catch.
31
+ *
32
+ * @param {String} key - Key to test
33
+ * @returns {Boolean} True when the key must be dropped
34
+ */
35
+ function isUnsafeKey(key) {
36
+ return UNSAFE_KEYS.includes(key);
37
+ }
38
+
39
+ /**
40
+ * The stricter test for a key REBUILT from a name by a case-changing transform. After
41
+ * toCamelCase() a key is no longer lowercase-only: "to-string" camelCases into "toString" and
42
+ * "has-own-property" into "hasOwnProperty", so the transform can manufacture any Object.prototype
43
+ * member name out of an input the parse boundary had no reason to drop. Assigning one creates an
44
+ * own property that shadows the method on the published object, and the first consumer that
45
+ * string-coerces the report - or calls hasOwnProperty() on it - throws.
46
+ *
47
+ * Probed with `in` against Object.prototype itself (whose own chain ends at null, so this reads
48
+ * exactly its member set, __proto__ and constructor included) rather than extending the list
49
+ * above: the set tracks the runtime, and the parse-boundary check deliberately stays narrower -
50
+ * see the note on UNSAFE_KEYS about not dropping names a lowercased key cannot collide with.
51
+ *
52
+ * @param {String} key - Key to test, after the transform that rebuilt it
53
+ * @returns {Boolean} True when the key must be dropped
54
+ */
55
+ function isUnsafeTransformedKey(key) {
56
+ return key in Object.prototype;
57
+ }
58
+
59
+ module.exports = { UNSAFE_KEYS, isUnsafeKey, isUnsafeTransformedKey };
@@ -395,7 +395,68 @@ async function messageWebSafeHtml(messageData) {
395
395
  return mimeHtml(source);
396
396
  }
397
397
 
398
+ /**
399
+ * The web-safe form of a fetched text response.
400
+ *
401
+ * Both MIME parts go in and one rendering comes out: the HTML is generated from whichever parts
402
+ * exist, so the plaintext part beside it would be the same message a second time. A caller that
403
+ * wants the parts as the server stored them simply does not ask for this.
404
+ *
405
+ * A response carrying neither body is handed back untouched - there is nothing to render, and an
406
+ * empty `html` claiming to be web-safe says more than the message does.
407
+ *
408
+ * @param {Object} textData - `{ plain, html, hasMore }` as fetched
409
+ * @returns {Promise<Object>} `{ html, webSafe: true, hasMore }`, or the input when there is no body
410
+ */
411
+ async function webSafeTextResponse(textData) {
412
+ if (!textData || (!textData.plain && !textData.html)) {
413
+ return textData;
414
+ }
415
+
416
+ return {
417
+ html: await messageWebSafeHtml({ text: { html: textData.html, plain: textData.plain } }),
418
+ webSafe: true,
419
+ hasMore: !!textData.hasMore
420
+ };
421
+ }
422
+
423
+ /**
424
+ * Expands the `webSafeHtml` shorthand into the options it stands for, and settles
425
+ * `embedAttachedImages` either way.
426
+ *
427
+ * One spelling of the expansion, which the message-retrieval paths had three drifting copies of -
428
+ * a shorthand that means different things per provider is not a shorthand. Called at the facade
429
+ * (Account.getMessage) and again inside the Gmail and Graph clients, which are reachable on their
430
+ * own; it is idempotent, so the second call on those paths is a no-op rather than a second policy.
431
+ *
432
+ * `embedAttachedImages` is the one part a caller may keep: inlining every referenced attachment as
433
+ * a data URI is what makes a web-safe body renderable in a browser with no second request, and it
434
+ * is also what multiplies its size, which is the wrong trade for anything that reads the body
435
+ * rather than displays it (the MCP tools, an export, a classifier). An explicit `false` therefore
436
+ * wins over the shorthand and the `cid:` references are left as they are; the sanitizing and the
437
+ * single-rendering promise are unaffected.
438
+ *
439
+ * The tri-state that makes that possible - the query schema deliberately carries no default, so
440
+ * absent stays distinguishable from an explicit false - is resolved to a boolean here rather than
441
+ * left for four backends to each read as truthy or not. Absent means the shorthand decides.
442
+ *
443
+ * @param {Object} options - request options, modified in place
444
+ * @returns {Object} the same options object
445
+ */
446
+ function applyWebSafeHtmlOptions(options) {
447
+ if (options.webSafeHtml) {
448
+ options.textType = '*';
449
+ options.preProcessHtml = true;
450
+ }
451
+
452
+ options.embedAttachedImages = options.embedAttachedImages === undefined ? !!options.webSafeHtml : !!options.embedAttachedImages;
453
+
454
+ return options;
455
+ }
456
+
398
457
  module.exports = {
399
458
  messageWebSafeHtml,
459
+ webSafeTextResponse,
460
+ applyWebSafeHtmlOptions,
400
461
  collapseThreadHistory
401
462
  };
@@ -65,14 +65,18 @@ function describeEffectiveRouting(opts) {
65
65
  },
66
66
 
67
67
  // Enabled custom routes deliver independently of the default route, each gated by its
68
- // own filter function instead of the webhookEvents allowlist
68
+ // own filter function instead of the webhookEvents allowlist. The worker requires that
69
+ // filter to exist (lib/webhooks.js pushToQueue skips a route without a compiled
70
+ // function), so a route whose `hasFilter` marker is false is flagged rather than
71
+ // presented as delivering - it never fires anything.
69
72
  customRoutes: []
70
73
  .concat(opts.routes || [])
71
74
  .filter(isDeliverableRoute)
72
75
  .map(route => ({
73
76
  id: route.id,
74
77
  name: route.name,
75
- targetUrl: route.targetUrl
78
+ targetUrl: route.targetUrl,
79
+ missingFilter: route.hasFilter === false
76
80
  }))
77
81
  };
78
82
  }
package/lib/webhooks.js CHANGED
@@ -7,7 +7,7 @@ const logger = require('./logger');
7
7
  const { REDIS_PREFIX, MESSAGE_NEW_NOTIFY } = require('./consts');
8
8
  const { SubScript } = require('./sub-script');
9
9
  const settings = require('./settings');
10
- const { filterListPage } = require('./tools');
10
+ const { filterListPage, truncateTextContents } = require('./tools');
11
11
  const { buildRetentionPolicy } = require('./queue-retention');
12
12
  const { isDeliverableRoute } = require('./webhook-routing');
13
13
 
@@ -349,6 +349,34 @@ class WebhooksHandler {
349
349
  }
350
350
  }
351
351
 
352
+ // Filter-presence markers for the routes asked about, as a Map of id -> boolean. The
353
+ // delivery gate in pushToQueue() requires a compiled filter function, so anything
354
+ // describing routes to an operator (the account page's routing card) has to know which
355
+ // routes carry a script at all. Reads only the content entries of the given ids.
356
+ async getFilterInfo(ids) {
357
+ let result = new Map();
358
+ if (!ids || !ids.length) {
359
+ return result;
360
+ }
361
+
362
+ let entries = await this.redis.hmgetBuffer(
363
+ this.getWebhooksContentKey(),
364
+ ids.map(id => `${id}:content`)
365
+ );
366
+
367
+ for (let i = 0; i < ids.length; i++) {
368
+ let content = null;
369
+ try {
370
+ content = entries[i] ? msgpack.decode(entries[i]) : null;
371
+ } catch (err) {
372
+ logger.error({ msg: 'Failed to process webhook', webhook: ids[i], entry: entries[i] && entries[i].toString('base64'), err });
373
+ }
374
+ result.set(ids[i], !!(content && content.fn));
375
+ }
376
+
377
+ return result;
378
+ }
379
+
352
380
  async getHandler(id) {
353
381
  let webhookData = await this.get(id);
354
382
 
@@ -478,13 +506,8 @@ class WebhooksHandler {
478
506
  }
479
507
  } else {
480
508
  let notifyTextSize = await settings.get('notifyTextSize');
481
- if (notifyTextSize) {
482
- for (let textType of ['html', 'plain']) {
483
- if (payload.data.text && typeof payload.data.text[textType] === 'string' && payload.data.text[textType].length > notifyTextSize) {
484
- payload.data.text[textType] = payload.data.text[textType].substr(0, notifyTextSize);
485
- payload.data.text.hasMore = true;
486
- }
487
- }
509
+ if (payload.data.text && truncateTextContents(payload.data.text, notifyTextSize)) {
510
+ payload.data.text.hasMore = true;
488
511
  }
489
512
  }
490
513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.79.0",
3
+ "version": "2.79.2",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -21,6 +21,7 @@
21
21
  "lint:src": "npx eslint 'lib/**/*.js' 'workers/**/*.js' server.js",
22
22
  "swagger": "./getswagger.sh",
23
23
  "build:css": "tailwindcss -i static/css/src/app.tailwind.css -o static/css/flyonui.css --minify",
24
+ "build:icon": "node scripts/build-icon.js",
24
25
  "build-source": "rm -rf node_modules && npm install && rm -rf node_modules && npm ci --omit=dev && rm -rf node_modules/ace-builds node_modules/@postalsys/ee-client && ./prepare-bundle-deps.sh && ./update-info.sh",
25
26
  "build-dist": "pkg --compress Brotli package.json && npm install && node winconf.js",
26
27
  "build-dist-fast": "pkg --debug package.json && npm install && node winconf.js",
@@ -50,8 +51,8 @@
50
51
  },
51
52
  "homepage": "https://emailengine.app/",
52
53
  "dependencies": {
53
- "@bull-board/api": "9.0.0",
54
- "@bull-board/hapi": "9.0.0",
54
+ "@bull-board/api": "9.3.2",
55
+ "@bull-board/hapi": "9.3.2",
55
56
  "@elastic/elasticsearch": "8.15.3",
56
57
  "@hapi/accept": "6.0.3",
57
58
  "@hapi/bell": "13.1.0",
@@ -78,7 +79,7 @@
78
79
  "@zone-eu/mailsplit": "5.4.15",
79
80
  "@zone-eu/wild-config": "1.7.6",
80
81
  "ace-builds": "1.44.0",
81
- "bullmq": "6.1.2",
82
+ "bullmq": "6.2.0",
82
83
  "compare-versions": "6.1.1",
83
84
  "dotenv": "17.4.2",
84
85
  "encoding-japanese": "2.2.0",
@@ -89,14 +90,14 @@
89
90
  "hapi-auth-bearer-token": "8.0.0",
90
91
  "hapi-pino": "13.0.0",
91
92
  "he": "1.2.0",
92
- "html-to-text": "10.0.0",
93
+ "html-to-text": "10.0.1",
93
94
  "ical.js": "1.5.0",
94
95
  "iconv-lite": "0.7.3",
95
- "imapflow": "1.7.1",
96
+ "imapflow": "1.7.2",
96
97
  "ioredfour": "1.4.2",
97
98
  "ioredis": "6.0.0",
98
99
  "ipaddr.js": "2.5.0",
99
- "joi": "18.2.3",
100
+ "joi": "18.2.5",
100
101
  "libbase64": "1.3.0",
101
102
  "libmime": "5.4.2",
102
103
  "libqp": "2.1.1",
@@ -127,7 +128,7 @@
127
128
  "acorn-walk": "8.3.5",
128
129
  "chai": "4.5.0",
129
130
  "eerawlog": "1.5.5",
130
- "eslint": "10.8.1",
131
+ "eslint": "10.9.0",
131
132
  "flyonui": "2.4.1",
132
133
  "pino-pretty": "13.1.3",
133
134
  "prettier": "3.9.6",