emailengine-app 2.79.1 → 2.79.3

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 (87) hide show
  1. package/.github/workflows/deploy.yml +92 -39
  2. package/.github/workflows/release.yaml +94 -34
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +85 -0
  5. package/bin/emailengine.js +8 -1
  6. package/config/default.toml +6 -0
  7. package/copy-static-files.sh +23 -2
  8. package/data/google-crawlers.json +1 -1
  9. package/lib/account.js +138 -18
  10. package/lib/api-routes/account-routes.js +13 -1
  11. package/lib/api-routes/index.js +12 -0
  12. package/lib/api-routes/mailbox-routes.js +6 -0
  13. package/lib/api-routes/mcp-oauth-routes.js +259 -0
  14. package/lib/api-routes/mcp-routes.js +172 -0
  15. package/lib/api-routes/message-routes.js +125 -4
  16. package/lib/api-routes/outbox-routes.js +7 -0
  17. package/lib/api-routes/permission-map.js +97 -1
  18. package/lib/api-routes/route-helpers.js +16 -4
  19. package/lib/api-routes/route-metadata.js +24 -4
  20. package/lib/api-routes/submit-routes.js +41 -0
  21. package/lib/api-routes/template-routes.js +7 -0
  22. package/lib/api-routes/token-routes.js +4 -2
  23. package/lib/consts.js +30 -1
  24. package/lib/email-client/base-client.js +235 -163
  25. package/lib/email-client/gmail-client.js +99 -22
  26. package/lib/email-client/imap/mailbox.js +140 -66
  27. package/lib/email-client/imap-client.js +74 -68
  28. package/lib/email-client/outlook-client.js +29 -14
  29. package/lib/enum-descriptions.js +2 -1
  30. package/lib/field-usage.js +17 -1
  31. package/lib/logger.js +43 -3
  32. package/lib/lua/s-list-accounts.lua +5 -2
  33. package/lib/mcp/index.js +29 -0
  34. package/lib/mcp/inject.js +70 -0
  35. package/lib/mcp/json-schema.js +120 -0
  36. package/lib/mcp/listen.js +171 -0
  37. package/lib/mcp/oauth.js +324 -0
  38. package/lib/mcp/protocol.js +489 -0
  39. package/lib/mcp/resources.js +139 -0
  40. package/lib/mcp/tools.js +655 -0
  41. package/lib/openapi/index.js +3 -1
  42. package/lib/response-stream.js +52 -21
  43. package/lib/routes-ui.js +4 -0
  44. package/lib/schemas.js +24 -3
  45. package/lib/token-permission-view.js +104 -8
  46. package/lib/tokens.js +34 -5
  47. package/lib/tools.js +96 -0
  48. package/lib/ui-routes/account-routes.js +43 -1
  49. package/lib/ui-routes/admin-config-routes.js +114 -1
  50. package/lib/ui-routes/admin-entities-routes.js +54 -5
  51. package/lib/ui-routes/auth-routes.js +13 -0
  52. package/lib/ui-routes/mcp-consent-routes.js +330 -0
  53. package/lib/ui-routes/route-helpers.js +116 -1
  54. package/lib/utils/network.js +9 -1
  55. package/lib/web-safe-html.js +61 -0
  56. package/lib/webhooks.js +3 -8
  57. package/package.json +15 -14
  58. package/sbom.json +1 -1
  59. package/scripts/README.md +25 -0
  60. package/scripts/build-icon.js +77 -0
  61. package/server.js +21 -9
  62. package/static/css/flyonui.css +1 -1
  63. package/static/css/src/app.tailwind.css +98 -0
  64. package/static/emailengine.ico +0 -0
  65. package/static/js/ui.js +465 -1
  66. package/static/licenses.html +85 -135
  67. package/translations/messages.pot +103 -103
  68. package/views/config/mcp.hbs +361 -0
  69. package/views/config/oauth/index.hbs +7 -0
  70. package/views/layout/prompt.hbs +62 -0
  71. package/views/mcp/authorize.hbs +136 -0
  72. package/views/partials/head_assets.hbs +3 -3
  73. package/views/partials/mcp_access_levels.hbs +13 -0
  74. package/views/partials/mcp_account_limit.hbs +14 -0
  75. package/views/partials/mcp_tool_count.hbs +19 -0
  76. package/views/partials/side_menu.hbs +1 -0
  77. package/views/partials/ui/account-picker.hbs +59 -0
  78. package/views/partials/ui/code-block.hbs +26 -0
  79. package/views/partials/ui/menu-item.hbs +5 -0
  80. package/views/partials/ui/radio.hbs +41 -0
  81. package/views/partials/ui/tab.hbs +15 -10
  82. package/views/partials/ui/tabs.hbs +8 -5
  83. package/views/templates/template.hbs +4 -3
  84. package/views/tokens/index.hbs +8 -2
  85. package/views/tokens/new.hbs +514 -243
  86. package/winconf.js +148 -48
  87. package/workers/api.js +198 -48
@@ -18,7 +18,8 @@ const psl = require('psl');
18
18
 
19
19
  const settings = require('../settings');
20
20
  const { redis } = require('../db');
21
- const { accountsExist } = require('../account');
21
+ const { toolGrants } = require('../mcp/tools');
22
+ const { Account, accountsExist, accountSummary } = require('../account');
22
23
  const { REDIS_PREFIX, DEFAULT_PAGE_SIZE } = require('../consts');
23
24
  const { oauth2ProviderData } = require('../oauth2-apps');
24
25
  const exampleDocumentsPayloads = require('../payload-examples-documents.json');
@@ -434,9 +435,123 @@ async function resolveKnownAccounts(entries) {
434
435
  return accountsExist(redis, Array.from(new Set(entries.map(entry => entry.account).filter(Boolean))));
435
436
  }
436
437
 
438
+ // How many accounts one suggestion request answers with. The picker is a search box, not a
439
+ // listing: past a screenful the answer to "I cannot see mine" is to type more of it, and a longer
440
+ // list only makes the response slower to fetch and harder to scan.
441
+ const ACCOUNT_SUGGESTION_LIMIT = 10;
442
+
443
+ /**
444
+ * One account as the account picker renders it.
445
+ *
446
+ * The picker shows the same three things everywhere it appears - who the account belongs to, which
447
+ * address it syncs, and whether it is connected - so the shape is built once here rather than by
448
+ * each page that feeds it. `state` is the badge descriptor the account listings already use, so a
449
+ * suggestion row cannot describe a connection differently from the page it was picked on.
450
+ *
451
+ * @param {Object} entry - an account record, from listAccounts() or accountSummary()
452
+ * @returns {Object} `{ account, name, email, state: { type, name } }`
453
+ */
454
+ function accountPickerEntry(entry) {
455
+ // No lastErrorState is passed on purpose: the picker has room for a state, not for the reason
456
+ // behind it, and that reason is the only thing the label needs translating for
457
+ const badge = accountStateLabel(entry.state, {});
458
+
459
+ return {
460
+ account: entry.account,
461
+ name: entry.name || '',
462
+ email: entry.email || '',
463
+ state: { type: badge.type, name: badge.name }
464
+ };
465
+ }
466
+
467
+ /**
468
+ * Account suggestions for the account picker, shared by every page that carries one.
469
+ *
470
+ * Search rather than a preloaded list: an instance can hold far more accounts than a page could
471
+ * usefully ship, and the id a person is looking for is one they can start typing. A listing
472
+ * failure costs the suggestions and nothing else - the picker still accepts a typed id, and the
473
+ * form that submits it resolves it server-side either way.
474
+ *
475
+ * @param {Function} call - RPC helper for talking to the main thread
476
+ * @param {Object} [opts]
477
+ * @param {String} [opts.query] - search string matched against id, name and address
478
+ * @param {Object} [opts.logger] - request logger for the failure branch
479
+ * @returns {Promise<{accounts: Array, total: Number}>}
480
+ */
481
+ async function accountSuggestions(call, opts) {
482
+ const { query, logger } = opts || {};
483
+
484
+ try {
485
+ const listing = await new Account({ redis, call }).listAccounts(false, query, 0, ACCOUNT_SUGGESTION_LIMIT);
486
+ return {
487
+ accounts: (listing.accounts || []).map(accountPickerEntry),
488
+ total: listing.total || 0
489
+ };
490
+ } catch (err) {
491
+ if (logger) {
492
+ logger.error({ msg: 'Failed to list account suggestions', err });
493
+ }
494
+ return { accounts: [], total: 0 };
495
+ }
496
+ }
497
+
498
+ /**
499
+ * The picker entry for an account a form already holds, or null when it names none.
500
+ *
501
+ * A form re-rendered after a validation error starts with an id rather than with a choice, and so
502
+ * does the token form opened from an account's own token list. Without this the picker would have
503
+ * to show the raw id back as if the person had never picked anything.
504
+ *
505
+ * @param {String} account - Account ID, possibly empty or naming a deleted account
506
+ * @param {Object} [logger] - request logger for the failure branch
507
+ * @returns {Promise<Object|null>}
508
+ */
509
+ async function accountPickerSelection(account, logger) {
510
+ if (!account) {
511
+ return null;
512
+ }
513
+
514
+ try {
515
+ const summary = await accountSummary(redis, account);
516
+ return summary ? accountPickerEntry(summary) : null;
517
+ } catch (err) {
518
+ if (logger) {
519
+ logger.error({ msg: 'Failed to resolve the selected account', account, err });
520
+ }
521
+ return null;
522
+ }
523
+ }
524
+
525
+ /**
526
+ * The MCP tool grants for a page that shows the tool count, or an empty list if the registry
527
+ * cannot be built.
528
+ *
529
+ * The three pages that mint an mcp-scoped token all want this, and all want it the same way: the
530
+ * count is a nicety and the page's real job is not, so a registry failure costs the count and
531
+ * nothing else. Wrapped once here rather than three times, so the pages cannot disagree about
532
+ * that - one of them letting the failure through would take down a token form or a consent
533
+ * decision over a line of text.
534
+ *
535
+ * @param {Object} server - the Hapi server
536
+ * @param {Object} logger - where to report a failure (a request logger, or the server's)
537
+ * @returns {Array} toolGrants() output, or []
538
+ */
539
+ function mcpToolGrants(server, logger) {
540
+ try {
541
+ return toolGrants(server);
542
+ } catch (err) {
543
+ logger.error({ msg: 'Failed to derive the MCP tool catalog', err });
544
+ return [];
545
+ }
546
+ }
547
+
437
548
  module.exports = {
438
549
  jsonErrorPayload,
550
+ mcpToolGrants,
439
551
  resolveKnownAccounts,
552
+ accountSuggestions,
553
+ accountPickerEntry,
554
+ accountPickerSelection,
440
555
  identityErrorView,
441
556
  OPEN_AI_MODELS,
442
557
  cachedTemplates,
@@ -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];
@@ -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
  };
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
 
@@ -506,13 +506,8 @@ class WebhooksHandler {
506
506
  }
507
507
  } else {
508
508
  let notifyTextSize = await settings.get('notifyTextSize');
509
- if (notifyTextSize) {
510
- for (let textType of ['html', 'plain']) {
511
- if (payload.data.text && typeof payload.data.text[textType] === 'string' && payload.data.text[textType].length > notifyTextSize) {
512
- payload.data.text[textType] = payload.data.text[textType].substr(0, notifyTextSize);
513
- payload.data.text.hasMore = true;
514
- }
515
- }
509
+ if (payload.data.text && truncateTextContents(payload.data.text, notifyTextSize)) {
510
+ payload.data.text.hasMore = true;
516
511
  }
517
512
  }
518
513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.79.1",
3
+ "version": "2.79.3",
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.4.0",
55
+ "@bull-board/hapi": "9.4.0",
55
56
  "@elastic/elasticsearch": "8.15.3",
56
57
  "@hapi/accept": "6.0.3",
57
58
  "@hapi/bell": "13.1.0",
@@ -64,21 +65,21 @@
64
65
  "@msgpack/msgpack": "3.1.3",
65
66
  "@phc/pbkdf2": "1.1.14",
66
67
  "@postalsys/bounce-classifier": "3.0.0",
67
- "@postalsys/certs": "1.0.17",
68
+ "@postalsys/certs": "1.0.18",
68
69
  "@postalsys/ee-client": "1.7.0",
69
- "@postalsys/email-ai-tools": "1.13.18",
70
+ "@postalsys/email-ai-tools": "1.13.19",
70
71
  "@postalsys/email-content": "0.1.3",
71
- "@postalsys/email-text-tools": "2.4.13",
72
+ "@postalsys/email-text-tools": "2.4.14",
72
73
  "@postalsys/gettext": "4.1.1",
73
74
  "@postalsys/joi-messages": "1.0.5",
74
75
  "@postalsys/templates": "2.0.2",
75
- "@sentry/node": "10.70.0",
76
+ "@sentry/node": "10.71.0",
76
77
  "@simplewebauthn/browser": "13.3.0",
77
78
  "@simplewebauthn/server": "13.3.2",
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,18 +90,18 @@
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
- "ioredfour": "1.4.2",
96
+ "imapflow": "1.7.6",
97
+ "ioredfour": "1.4.3",
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",
103
- "mailparser": "3.9.15",
104
+ "mailparser": "3.9.16",
104
105
  "marked": "15.0.12",
105
106
  "minimist": "1.2.8",
106
107
  "murmurhash": "2.0.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",