emailengine-app 2.79.6 → 2.79.8

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 (109) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +32 -0
  3. package/DOCKER_DEPLOYMENT.md +2 -0
  4. package/bin/emailengine.js +29 -13
  5. package/config/default.toml +13 -3
  6. package/data/google-crawlers.json +7 -1
  7. package/docker-compose.yml +12 -3
  8. package/install.sh +2 -0
  9. package/lib/api-routes/account-routes.js +14 -3
  10. package/lib/api-routes/mailbox-routes.js +4 -1
  11. package/lib/api-routes/message-routes.js +6 -5
  12. package/lib/api-routes/outbox-routes.js +7 -4
  13. package/lib/api-routes/settings-routes.js +34 -25
  14. package/lib/api-routes/stats-routes.js +8 -1
  15. package/lib/api-routes/submit-routes.js +2 -1
  16. package/lib/api-routes/template-routes.js +3 -2
  17. package/lib/bounce-detect.js +45 -0
  18. package/lib/consts.js +9 -3
  19. package/lib/egress-filter.js +39 -4
  20. package/lib/email-client/base-client.js +274 -24
  21. package/lib/email-client/gmail/gmail-api.js +15 -7
  22. package/lib/email-client/gmail-client.js +121 -64
  23. package/lib/email-client/imap/mailbox.js +18 -59
  24. package/lib/email-client/imap-client.js +53 -29
  25. package/lib/email-client/notification-handler.js +11 -2
  26. package/lib/email-client/outlook/graph-api.js +106 -90
  27. package/lib/email-client/outlook-client.js +222 -106
  28. package/lib/generate-text-preview.js +10 -5
  29. package/lib/headers-rewriter.js +1 -1
  30. package/lib/llm-pre-process.js +4 -1
  31. package/lib/mcp/json-schema.js +50 -2
  32. package/lib/outbox.js +22 -5
  33. package/lib/passkeys.js +39 -7
  34. package/lib/pre-process.js +4 -1
  35. package/lib/rewrite-text-nodes.js +12 -1
  36. package/lib/schemas.js +27 -5
  37. package/lib/settings.js +19 -1
  38. package/lib/sso.js +60 -7
  39. package/lib/submit-progress.js +29 -0
  40. package/lib/templates.js +11 -0
  41. package/lib/tools.js +115 -53
  42. package/lib/ui-routes/account-routes.js +79 -12
  43. package/lib/ui-routes/admin-config-routes.js +7 -21
  44. package/lib/ui-routes/admin-entities-routes.js +42 -12
  45. package/lib/ui-routes/auth-routes.js +242 -87
  46. package/lib/ui-routes/dashboard-routes.js +1 -1
  47. package/lib/ui-routes/internals-routes.js +2 -0
  48. package/lib/ui-routes/mcp-consent-routes.js +5 -2
  49. package/lib/ui-routes/network-config-routes.js +12 -3
  50. package/lib/ui-routes/oauth-config-routes.js +12 -1
  51. package/lib/ui-routes/route-helpers.js +41 -6
  52. package/lib/ui-routes/settings-page.js +10 -0
  53. package/lib/ui-routes/suppression-list-routes.js +16 -5
  54. package/lib/ui-routes/unsubscribe-routes.js +22 -3
  55. package/lib/webhooks.js +14 -2
  56. package/package.json +17 -17
  57. package/sbom.json +1 -1
  58. package/server.js +63 -35
  59. package/static/css/flyonui.css +1 -1
  60. package/static/css/src/app.tailwind.css +55 -0
  61. package/static/js/app.js +4 -35
  62. package/static/js/passkey-register.js +50 -1
  63. package/static/js/public.js +128 -0
  64. package/static/js/ui.js +183 -6
  65. package/static/licenses.html +371 -770
  66. package/translations/messages.pot +66 -66
  67. package/views/account/passkeys.hbs +141 -0
  68. package/views/account/password.hbs +11 -0
  69. package/views/account/security.hbs +318 -326
  70. package/views/accounts/account.hbs +90 -115
  71. package/views/accounts/register/imap-server.hbs +18 -12
  72. package/views/config/ai.hbs +2 -0
  73. package/views/config/branding.hbs +2 -0
  74. package/views/config/document-store/index.hbs +6 -6
  75. package/views/config/email-processing.hbs +2 -0
  76. package/views/config/imap-proxy.hbs +2 -0
  77. package/views/config/license.hbs +4 -1
  78. package/views/config/logging.hbs +3 -1
  79. package/views/config/mcp.hbs +2 -0
  80. package/views/config/network.hbs +2 -0
  81. package/views/config/oauth/app.hbs +3 -3
  82. package/views/config/oauth/edit.hbs +1 -1
  83. package/views/config/oauth/new.hbs +1 -1
  84. package/views/config/security.hbs +2 -0
  85. package/views/config/service.hbs +2 -0
  86. package/views/config/smtp.hbs +2 -0
  87. package/views/config/webhooks.hbs +9 -6
  88. package/views/error.hbs +6 -0
  89. package/views/layout/app.hbs +6 -3
  90. package/views/layout/login.hbs +1 -1
  91. package/views/layout/prompt.hbs +1 -1
  92. package/views/layout/public.hbs +1 -1
  93. package/views/legal.hbs +1 -1
  94. package/views/partials/filter_editor_js.hbs +1 -1
  95. package/views/partials/gateway_js.hbs +7 -6
  96. package/views/partials/oauth_form.hbs +5 -5
  97. package/views/partials/ui/btn.hbs +8 -2
  98. package/views/partials/ui/confirm-modal.hbs +2 -3
  99. package/views/partials/ui/empty-state.hbs +25 -0
  100. package/views/partials/ui/env-managed-alert.hbs +19 -0
  101. package/views/partials/webhook_form.hbs +1 -1
  102. package/views/partials/webhooks_editor_functions.hbs +5 -5
  103. package/views/unsubscribe.hbs +6 -0
  104. package/workers/api.js +193 -81
  105. package/workers/imap.js +32 -3
  106. package/workers/smtp.js +7 -0
  107. package/workers/submit.js +25 -1
  108. package/workers/webhooks.js +13 -17
  109. package/lib/reconnection-manager.js +0 -106
package/lib/tools.js CHANGED
@@ -5,7 +5,6 @@
5
5
  const msgpack = require('./msgpack');
6
6
  const enumMessageFlags = require('./enum-message-flags');
7
7
  const Joi = require('joi');
8
- const he = require('he');
9
8
  const packageData = require('../package.json');
10
9
  const settings = require('./settings');
11
10
  // Safe to require at load time despite db.js opening Redis clients: settings.js above already
@@ -95,6 +94,12 @@ const RETRY_OPTS = {
95
94
  // get a dispatcher that resolves through the egress policy (lib/webhook-egress.js) rather than the
96
95
  // shared resolver. It is built here because its lifetime is tied to the other agents': a proxy
97
96
  // setting change swaps them all out together.
97
+ //
98
+ // Deliberately NOT a RetryAgent. A webhook is a POST the receiver acts on, and RETRY_OPTS retries
99
+ // POSTs on a dropped socket or a 429: a receiver that processed the event and then reset the
100
+ // connection, or a stale keep-alive socket, would get the same event up to six times with an
101
+ // identical X-EE-Wh-Id and attempts-made 0, invisible to the worker's logs and metrics. Retrying
102
+ // is the notify queue's job, where every attempt is counted, logged and spaced out by backoff.
98
103
  function buildWebhookDispatcher(proxied, existing) {
99
104
  const lookup = createWebhookLookup();
100
105
 
@@ -102,13 +107,13 @@ function buildWebhookDispatcher(proxied, existing) {
102
107
  // only vet the route to the proxy itself. There is nothing to bind; fall back to the shared
103
108
  // dispatcher and leave assertAllowedUrl() as the advisory check it can only be in that setup.
104
109
  if (proxied || !lookup) {
105
- return httpAgent.retry;
110
+ return httpAgent.fetch;
106
111
  }
107
112
 
108
113
  // Nothing a reload changes can affect a dedicated dispatcher - the policy is fixed at startup
109
114
  // and the Agent never references httpAgent.fetch - so reuse it rather than discarding warm
110
115
  // sockets. Saving the network settings form reloads on any field, not just a proxy one.
111
- return existing || new RetryAgent(new Agent(Object.assign({}, AGENT_OPTS, { connect: { lookup } })), RETRY_OPTS);
116
+ return existing || new Agent(Object.assign({}, AGENT_OPTS, { connect: { lookup } }));
112
117
  }
113
118
 
114
119
  // Shared mutable object -- consumers import the object reference and access
@@ -232,7 +237,7 @@ async function _doReloadHttpProxyAgent() {
232
237
  let oldFetch = httpAgent.fetch;
233
238
  // Only a dedicated dispatcher is ours to close; when webhooks share the general one it is
234
239
  // closed via oldFetch. Read before anything is swapped, while the comparison still holds.
235
- let oldWebhook = httpAgent.webhook !== httpAgent.retry ? httpAgent.webhook : null;
240
+ let oldWebhook = httpAgent.webhook !== httpAgent.fetch ? httpAgent.webhook : null;
236
241
 
237
242
  try {
238
243
  if (enabled && proxyUrl) {
@@ -263,7 +268,7 @@ async function _doReloadHttpProxyAgent() {
263
268
  httpProxyEnabled: !!enabled,
264
269
  httpProxyUrl: enabled && proxyUrl ? proxyUrl : null,
265
270
  webhookEgressPolicy: WEBHOOK_EGRESS_POLICY,
266
- webhookEgressPinned: httpAgent.webhook !== httpAgent.retry
271
+ webhookEgressPinned: httpAgent.webhook !== httpAgent.fetch
267
272
  });
268
273
 
269
274
  // Closing is graceful, so it waits for whatever is still in flight to drain. Overlap the
@@ -400,10 +405,29 @@ function cidReferenceRegex() {
400
405
  return new RegExp(CID_REFERENCE_SOURCE, 'g');
401
406
  }
402
407
 
408
+ // Both the SMTP server and the IMAP proxy read the TLS certificate into their server options once,
409
+ // when their worker starts, rather than per handshake, so a newly issued certificate only reaches
410
+ // them through a reload. The list lives here rather than at each call site because the bug this
411
+ // replaces was exactly that: the renewal path reloaded the SMTP server and forgot the IMAP proxy,
412
+ // which then went on offering the expired certificate until something unrelated restarted it.
413
+ async function reloadTlsServers(call, logger, context) {
414
+ for (let cmd of ['smtpReload', 'imapProxyReload']) {
415
+ try {
416
+ await call({ cmd });
417
+ } catch (err) {
418
+ // Caught per command so a server that fails to come back does not cost the other one
419
+ // its new certificate, and so the failure is not reported as an acquisition failure.
420
+ logger.error(Object.assign({ msg: 'Failed to reload server after certificate change', cmd, err }, context || {}));
421
+ }
422
+ }
423
+ }
424
+
403
425
  module.exports = {
404
426
  // keep the re-export, lib/utils/to-camel-case.js holds it so pure modules can use it too
405
427
  toCamelCase,
406
428
 
429
+ reloadTlsServers,
430
+
407
431
  cidReferenceRegex,
408
432
 
409
433
  /**
@@ -758,6 +782,35 @@ module.exports = {
758
782
  return `${REDIS_PREFIX}iam:${account}:h:${module.exports.mailboxPathHash(path)}`;
759
783
  },
760
784
 
785
+ // Splits basic-auth credentials embedded in a URL ("https://user:pass@host/") into the
786
+ // Authorization header value to send and the URL to send it to, which no longer carries them.
787
+ // The URL parser keeps userinfo percent-encoded, so each part is decoded before being joined:
788
+ // a password typed as "p@ss" arrives here as "p%40ss", and it is the typed form the receiver
789
+ // compares against. A malformed escape keeps the raw value rather than throwing. No HTML entity
790
+ // handling takes place: an earlier version ran he.encode() over the parts, which turned every
791
+ // "&", "<", ">" or quote in a password into an entity reference and made it fail forever.
792
+ splitUrlCredentials(url) {
793
+ const decode = value => {
794
+ try {
795
+ return decodeURIComponent(value);
796
+ } catch {
797
+ return value;
798
+ }
799
+ };
800
+
801
+ let parsed = new URL(url);
802
+ let username = decode(parsed.username);
803
+ let password = decode(parsed.password);
804
+
805
+ parsed.username = '';
806
+ parsed.password = '';
807
+
808
+ return {
809
+ url: parsed,
810
+ authorization: username || password ? `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}` : null
811
+ };
812
+ },
813
+
761
814
  async resolveCredentials(account, proto) {
762
815
  let authServer = await settings.get('authServer');
763
816
  if (!authServer) {
@@ -769,21 +822,9 @@ module.exports = {
769
822
  'User-Agent': `${packageData.name}/${packageData.version} (+${packageData.homepage})`
770
823
  };
771
824
 
772
- let parsed = new URL(authServer);
773
- let username, password;
774
-
775
- if (parsed.username) {
776
- username = he.decode(parsed.username);
777
- parsed.username = '';
778
- }
779
-
780
- if (parsed.password) {
781
- password = he.decode(parsed.password);
782
- parsed.password = '';
783
- }
784
-
785
- if (username || password) {
786
- headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
825
+ let { url: parsed, authorization } = module.exports.splitUrlCredentials(authServer);
826
+ if (authorization) {
827
+ headers.Authorization = authorization;
787
828
  }
788
829
 
789
830
  parsed.searchParams.set('account', account);
@@ -1317,7 +1358,13 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1317
1358
  try {
1318
1359
  redactValidationError(err);
1319
1360
 
1320
- let details = (err.details || []).map(detail => ({ message: detail.message, key: detail.context.key }));
1361
+ // `key` is the leaf name only, which cannot tell to[0].address from from.address;
1362
+ // `path` is the full dotted location. Both are kept: key is what clients already read
1363
+ let details = (err.details || []).map(detail => ({
1364
+ message: detail.message,
1365
+ key: detail.context.key,
1366
+ path: Array.isArray(detail.path) ? detail.path.join('.') : undefined
1367
+ }));
1321
1368
 
1322
1369
  request.logger.debug({
1323
1370
  msg: 'Request failed',
@@ -1347,6 +1394,9 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1347
1394
  // IP blocklist here without making it opt-in; it would break legitimate local-mail setups.
1348
1395
  let response = {};
1349
1396
 
1397
+ // Connect and greeting budget for both probes, in ms
1398
+ const VERIFY_TIMEOUT = 30 * 1000;
1399
+
1350
1400
  let proxyUrl = await settings.get('proxyUrl');
1351
1401
  let proxyEnabled = await settings.get('proxyEnabled');
1352
1402
 
@@ -1361,7 +1411,11 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1361
1411
  verifyOnly: true,
1362
1412
  includeMailboxes: accountData.mailboxes,
1363
1413
 
1364
- greetingTimeout: 90 * 1000,
1414
+ // A verification answers a person waiting at a form, so it gives up
1415
+ // well before the sync client's defaults would (the hosted form's
1416
+ // test fetch has no client-side timeout of its own)
1417
+ connectionTimeout: VERIFY_TIMEOUT,
1418
+ greetingTimeout: VERIFY_TIMEOUT,
1365
1419
 
1366
1420
  clientInfo: {
1367
1421
  name: (await settings.get('imapClientName')) || packageData.name,
@@ -1461,7 +1515,12 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1461
1515
  name,
1462
1516
  localAddress: address,
1463
1517
  transactionLog: true,
1464
- logger: smtpLogger
1518
+ logger: smtpLogger,
1519
+
1520
+ // see the IMAP side above; Nodemailer's own defaults are 2 minutes
1521
+ // to connect and 30 seconds for the greeting
1522
+ connectionTimeout: VERIFY_TIMEOUT,
1523
+ greetingTimeout: VERIFY_TIMEOUT
1465
1524
  },
1466
1525
  accountData.smtp
1467
1526
  );
@@ -1611,8 +1670,14 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1611
1670
  }
1612
1671
  },
1613
1672
 
1614
- getLogs(redis, account) {
1673
+ // Resolves to a readable stream of the account's stored log, one JSON entry per line. The rows
1674
+ // are read before the stream is handed out, so a Redis failure rejects and becomes a proper
1675
+ // error response instead of a 200 whose body trails off into an error, and it never carries a
1676
+ // stack trace into the download.
1677
+ async getLogs(redis, account) {
1615
1678
  let logKey = `${REDIS_PREFIX}iam:${account}:g`;
1679
+ let rows = await redis.lrangeBuffer(logKey, 0, -1);
1680
+
1616
1681
  let passThrough = new PassThrough();
1617
1682
 
1618
1683
  passThrough.headers = {
@@ -1620,39 +1685,36 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1620
1685
  'content-disposition': `attachment; filename=${JSON.stringify(`logs.${account}.txt`)}`
1621
1686
  };
1622
1687
 
1623
- redis
1624
- .lrangeBuffer(logKey, 0, -1)
1625
- .then(rows => {
1626
- if (!rows || !Array.isArray(rows) || !rows.length) {
1627
- return passThrough.end(`No logs found for ${account}\n`);
1628
- }
1629
- let processNext = () => {
1630
- if (!rows.length) {
1631
- return passThrough.end();
1632
- }
1688
+ if (!rows || !Array.isArray(rows) || !rows.length) {
1689
+ passThrough.end(`No logs found for ${account}\n`);
1690
+ return passThrough;
1691
+ }
1633
1692
 
1634
- let row = rows.shift();
1635
- let entry;
1636
- try {
1637
- entry = msgpack.decode(row);
1638
- } catch (err) {
1639
- entry = { error: err.stack };
1640
- }
1693
+ let processNext = () => {
1694
+ if (!rows.length) {
1695
+ return passThrough.end();
1696
+ }
1641
1697
 
1642
- if (entry) {
1643
- if (!passThrough.write(JSON.stringify(entry) + '\n')) {
1644
- return passThrough.once('drain', processNext);
1645
- }
1646
- }
1698
+ let row = rows.shift();
1699
+ let entry;
1700
+ try {
1701
+ entry = msgpack.decode(row);
1702
+ } catch (err) {
1703
+ // A row that does not decode is reported in place, so the download stays
1704
+ // complete, but with the message only - the stack names nothing the reader can act on
1705
+ entry = { error: 'Failed to decode log entry', message: err.message };
1706
+ }
1647
1707
 
1648
- setImmediate(processNext);
1649
- };
1708
+ if (entry) {
1709
+ if (!passThrough.write(JSON.stringify(entry) + '\n')) {
1710
+ return passThrough.once('drain', processNext);
1711
+ }
1712
+ }
1650
1713
 
1651
- processNext();
1652
- })
1653
- .catch(err => {
1654
- passThrough.end(`\nFailed to process logs\n${err.stack}\n`);
1655
- });
1714
+ setImmediate(processNext);
1715
+ };
1716
+
1717
+ processNext();
1656
1718
 
1657
1719
  return passThrough;
1658
1720
  },
@@ -42,7 +42,16 @@ const {
42
42
  ACCOUNT_DISPLAY_STATES,
43
43
  signedFormBlobFields: signedBlobFields
44
44
  } = require('../schemas');
45
- const { formatAccountData, cachedTemplates, identityErrorView, ACCOUNT_STATE_DISPLAY, adminUrl, accountSuggestions } = require('./route-helpers');
45
+ const {
46
+ formatAccountData,
47
+ cachedTemplates,
48
+ identityErrorView,
49
+ ACCOUNT_STATE_DISPLAY,
50
+ adminUrl,
51
+ accountSuggestions,
52
+ isClientError,
53
+ closedAfterConnectMessage
54
+ } = require('./route-helpers');
46
55
  const { webhooks: Webhooks } = require('../webhooks');
47
56
  const { describeEffectiveRouting, isDeliverableRoute } = require('../webhook-routing');
48
57
  const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
@@ -141,10 +150,6 @@ function init(args) {
141
150
 
142
151
  const accounts = await accountObject.listAccounts(request.query.state, request.query.query, request.query.page - 1, request.query.pageSize);
143
152
 
144
- if (accounts.pages < request.query.page) {
145
- request.query.page = accounts.pages;
146
- }
147
-
148
153
  for (let account of accounts.accounts) {
149
154
  let accountObject = new Account({ redis, account: account.account });
150
155
  try {
@@ -189,6 +194,13 @@ function init(args) {
189
194
  return url.pathname + url.search;
190
195
  };
191
196
 
197
+ // A page past the end lists nothing, and the view renders its page links only
198
+ // around a non-empty listing, so it would show "No accounts found" with no way
199
+ // back - send it to the last page instead
200
+ if (accounts.pages && request.query.page > accounts.pages) {
201
+ return h.redirect(getPagingUrl(accounts.pages, request.query.state, request.query.query));
202
+ }
203
+
192
204
  if (accounts.pages > accounts.page + 1) {
193
205
  nextPage = getPagingUrl(accounts.page + 2, request.query.state, request.query.query);
194
206
  }
@@ -806,6 +818,10 @@ function init(args) {
806
818
  {
807
819
  pageTitleFull: request.app.gt.gettext('Email Account Setup'),
808
820
  values,
821
+ // Nothing resolved for the domain, so the server fields come up empty - the
822
+ // page says why rather than looking like a form that forgot its defaults
823
+ autodetectFailed: !serverSettings,
824
+ autodetectDomain: request.payload.email.split('@').pop(),
809
825
  autoTest:
810
826
  values._source &&
811
827
  values.imap_auth_user &&
@@ -925,13 +941,47 @@ function init(args) {
925
941
 
926
942
  if (verifyResult) {
927
943
  if (verifyResult.imap && verifyResult.imap.error && verifyResult.imap.code) {
944
+ // The same translation the SMTP branch below does for its codes: the raw
945
+ // socket or ImapFlow error text is not something the person at the form
946
+ // can act on. Closed-after-connect keeps the TLS hint the account state
947
+ // badge shows for it, because a wrong port/TLS pairing is the usual cause.
928
948
  switch (verifyResult.imap.code) {
929
949
  case 'ENOTFOUND':
950
+ case 'EAI_AGAIN':
930
951
  verifyResult.imap.error = request.app.gt.gettext('Server hostname was not found');
931
952
  break;
932
953
  case 'AUTHENTICATIONFAILED':
933
954
  verifyResult.imap.error = request.app.gt.gettext('Invalid username or password');
934
955
  break;
956
+ case 'ETIMEDOUT':
957
+ case 'ETIMEOUT':
958
+ case 'GREETING_TIMEOUT':
959
+ verifyResult.imap.error = request.app.gt.gettext('Connection timed out');
960
+ break;
961
+ case 'ECONNREFUSED':
962
+ case 'ECONNRESET':
963
+ case 'EHOSTUNREACH':
964
+ case 'ENETUNREACH':
965
+ verifyResult.imap.error = request.app.gt.gettext('Could not connect to server');
966
+ break;
967
+ case 'ClosedAfterConnectTLS':
968
+ case 'ClosedAfterConnectText':
969
+ verifyResult.imap.error = closedAfterConnectMessage(verifyResult.imap.code, request.app.gt);
970
+ break;
971
+ case 'EPROTO':
972
+ case 'ERR_TLS_CERT_ALTNAME_INVALID':
973
+ case 'ERR_SSL_WRONG_VERSION_NUMBER':
974
+ case 'CERT_HAS_EXPIRED':
975
+ case 'DEPTH_ZERO_SELF_SIGNED_CERT':
976
+ case 'SELF_SIGNED_CERT_IN_CHAIN':
977
+ case 'UNABLE_TO_VERIFY_LEAF_SIGNATURE':
978
+ verifyResult.imap.error = request.app.gt.gettext('TLS protocol error');
979
+ break;
980
+ default:
981
+ if (/openssl|ssl routines/i.test(verifyResult.imap.error)) {
982
+ verifyResult.imap.error = request.app.gt.gettext('TLS protocol error');
983
+ }
984
+ break;
935
985
  }
936
986
  }
937
987
 
@@ -1345,9 +1395,16 @@ function init(args) {
1345
1395
  }
1346
1396
  }
1347
1397
 
1348
- let logInfo = (await settings.get('logs')) || {
1398
+ // Stored entries outlive the logging switch - turning logging off does not clear what
1399
+ // was already collected - so the download control is gated on the entries themselves,
1400
+ // not on whether logging is currently enabled. Both are snapshots taken at render
1401
+ // time, the same as everything else on this page.
1402
+ let [logSettings, storedLogCount] = await Promise.all([settings.get('logs'), redis.llen(accountObject.getLogKey())]);
1403
+
1404
+ let logInfo = logSettings || {
1349
1405
  all: false
1350
1406
  };
1407
+ let hasStoredLogs = storedLogCount > 0;
1351
1408
 
1352
1409
  accountData.path = [].concat(accountData.path || '*');
1353
1410
  if (accountData.path.includes('*')) {
@@ -1448,13 +1505,14 @@ function init(args) {
1448
1505
  return h.view(
1449
1506
  'accounts/account',
1450
1507
  {
1451
- pageTitle: `Accounts \u2013 ${accountData.email}`,
1508
+ pageTitle: `Accounts - ${accountData.email}`,
1452
1509
 
1453
1510
  menuAccounts: true,
1454
1511
  account: accountData,
1455
1512
  accountAlert,
1456
1513
  accountParked: !!disabledByAuthFailureAt,
1457
1514
  logs: logInfo,
1515
+ hasStoredLogs,
1458
1516
  smtpError: accountData.smtpStatus && accountData.smtpStatus.status === 'error',
1459
1517
 
1460
1518
  showSmtp: accountData.smtp || (accountData.oauth2 && accountData.oauth2.provider),
@@ -1536,13 +1594,22 @@ function init(args) {
1536
1594
  try {
1537
1595
  let accountObject = new Account({ redis, account: request.params.account, documentsQueue, call, secret: await getSecret() });
1538
1596
 
1539
- let deleted = await accountObject.delete();
1597
+ let { deleted } = await accountObject.delete();
1540
1598
  if (deleted) {
1541
1599
  await request.flash({ type: 'info', message: `Account deleted` });
1600
+ } else {
1601
+ await request.flash({ type: 'danger', message: `Requested account was not found` });
1542
1602
  }
1543
1603
 
1544
1604
  return h.redirect('/admin/accounts');
1545
1605
  } catch (err) {
1606
+ if (isClientError(err) && err.output.statusCode === 404) {
1607
+ // Already gone (a stale tab, a double submit): say so and land on the
1608
+ // listing rather than on the deleted account's page
1609
+ await request.flash({ type: 'danger', message: `Requested account was not found` });
1610
+ return h.redirect('/admin/accounts');
1611
+ }
1612
+
1546
1613
  await request.flash({ type: 'danger', message: `Couldn't delete account. Try again.` });
1547
1614
  request.logger.error({ msg: 'Failed to delete the account', err, account: request.params.account, remoteAddress: request.app.ip });
1548
1615
  return h.redirect(adminUrl`/admin/accounts/${request.params.account}`);
@@ -1857,7 +1924,7 @@ function init(args) {
1857
1924
  return h.view(
1858
1925
  'accounts/browse',
1859
1926
  {
1860
- pageTitle: `Browse \u2013 ${accountData.email}`,
1927
+ pageTitle: `Browse - ${accountData.email}`,
1861
1928
 
1862
1929
  menuAccounts: true,
1863
1930
  account: request.params.account,
@@ -1937,7 +2004,7 @@ function init(args) {
1937
2004
  return h.view(
1938
2005
  'accounts/edit',
1939
2006
  {
1940
- pageTitle: `Accounts \u2013 ${accountData.email}`,
2007
+ pageTitle: `Accounts - ${accountData.email}`,
1941
2008
 
1942
2009
  menuAccounts: true,
1943
2010
  account: request.params.account,
@@ -2100,7 +2167,7 @@ function init(args) {
2100
2167
  return h.view(
2101
2168
  'accounts/edit',
2102
2169
  {
2103
- pageTitle: `Accounts \u2013 ${accountData.email}`,
2170
+ pageTitle: `Accounts - ${accountData.email}`,
2104
2171
 
2105
2172
  menuAccounts: true,
2106
2173
  account: request.params.account,
@@ -2157,7 +2224,7 @@ function init(args) {
2157
2224
  .view(
2158
2225
  'accounts/edit',
2159
2226
  {
2160
- pageTitle: `Accounts \u2013 ${accountData.email}`,
2227
+ pageTitle: `Accounts - ${accountData.email}`,
2161
2228
 
2162
2229
  menuAccounts: true,
2163
2230
  account: request.params.account,
@@ -10,7 +10,6 @@ const Joi = require('joi');
10
10
  const crypto = require('crypto');
11
11
  const config = require('@zone-eu/wild-config');
12
12
  const libmime = require('libmime');
13
- const he = require('he');
14
13
  const os = require('os');
15
14
  const packageData = require('../../package.json');
16
15
  const { simpleParser } = require('mailparser');
@@ -21,7 +20,7 @@ const consts = require('../consts');
21
20
  const getSecret = require('../get-secret');
22
21
  const timezonesList = require('timezones-list').default;
23
22
  const { redis, submitQueue, notifyQueue, documentsQueue } = require('../db');
24
- const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent } = require('../tools');
23
+ const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent, splitUrlCredentials } = require('../tools');
25
24
  const { validateWebhookTarget } = require('../webhook-egress');
26
25
  const { sendWebhookRequest } = require('../webhook-request');
27
26
  const { llmPreProcess } = require('../llm-pre-process');
@@ -369,10 +368,9 @@ function init(args) {
369
368
  timezone: request.payload.timezone
370
369
  };
371
370
 
372
- if (request.payload.serviceUrl) {
373
- let url = new URL(request.payload.serviceUrl);
374
- data.serviceUrl = url.origin;
375
- }
371
+ // Written when emptied too: the schema accepts a blank field, and skipping the
372
+ // write would leave the old URL in place after a save meant to clear it
373
+ data.serviceUrl = request.payload.serviceUrl ? new URL(request.payload.serviceUrl).origin : null;
376
374
 
377
375
  await settings.setMulti(data);
378
376
  }
@@ -1139,21 +1137,9 @@ return true;`
1139
1137
  };
1140
1138
  }
1141
1139
 
1142
- let parsed = new URL(webhooks);
1143
- let username, password;
1144
-
1145
- if (parsed.username) {
1146
- username = he.decode(parsed.username);
1147
- parsed.username = '';
1148
- }
1149
-
1150
- if (parsed.password) {
1151
- password = he.decode(parsed.password);
1152
- parsed.password = '';
1153
- }
1154
-
1155
- if (username || password) {
1156
- headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
1140
+ let { url: parsed, authorization } = splitUrlCredentials(webhooks);
1141
+ if (authorization) {
1142
+ headers.Authorization = authorization;
1157
1143
  }
1158
1144
 
1159
1145
  let customHeaders = request.payload.customHeaders