emailengine-app 2.77.0 → 2.79.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 (189) hide show
  1. package/.github/workflows/test.yml +80 -0
  2. package/.ncurc.js +23 -13
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +60 -0
  5. package/bin/emailengine.js +1 -1
  6. package/config/e2e.toml +2 -1
  7. package/config/test.toml +2 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +1 -1
  10. package/lib/account/expected-identity.js +88 -0
  11. package/lib/account.js +145 -61
  12. package/lib/api-reference/format.js +105 -4
  13. package/lib/api-reference/index.js +24 -7
  14. package/lib/api-reference/model.js +148 -21
  15. package/lib/api-reference/schema-tree.js +282 -28
  16. package/lib/api-routes/account-routes.js +99 -36
  17. package/lib/api-routes/behavior-notes.js +3 -0
  18. package/lib/api-routes/blocklist-routes.js +21 -47
  19. package/lib/api-routes/chat-routes.js +10 -12
  20. package/lib/api-routes/delivery-test-routes.js +6 -26
  21. package/lib/api-routes/export-routes.js +2 -0
  22. package/lib/api-routes/gateway-routes.js +52 -11
  23. package/lib/api-routes/license-routes.js +2 -0
  24. package/lib/api-routes/mailbox-routes.js +29 -26
  25. package/lib/api-routes/message-routes.js +27 -21
  26. package/lib/api-routes/oauth2-app-routes.js +11 -29
  27. package/lib/api-routes/operation-impact.js +80 -0
  28. package/lib/api-routes/outbox-routes.js +15 -5
  29. package/lib/api-routes/permission-map.js +397 -0
  30. package/lib/api-routes/route-helpers.js +223 -9
  31. package/lib/api-routes/route-metadata.js +28 -0
  32. package/lib/api-routes/settings-routes.js +30 -25
  33. package/lib/api-routes/stats-routes.js +2 -2
  34. package/lib/api-routes/submit-routes.js +53 -31
  35. package/lib/api-routes/template-routes.js +3 -0
  36. package/lib/api-routes/token-routes.js +319 -33
  37. package/lib/api-routes/webhook-route-routes.js +14 -4
  38. package/lib/append-list.js +3 -14
  39. package/lib/arf-detect.js +23 -1
  40. package/lib/auth-token.js +80 -8
  41. package/lib/autodetect-imap-settings.js +40 -16
  42. package/lib/base32.js +30 -0
  43. package/lib/bounce-detect.js +182 -62
  44. package/lib/consts.js +10 -0
  45. package/lib/db.js +20 -2
  46. package/lib/delivery-error.js +30 -1
  47. package/lib/egress-filter.js +89 -8
  48. package/lib/email-client/base-client.js +35 -113
  49. package/lib/email-client/gmail-client.js +22 -13
  50. package/lib/email-client/imap/listing-diff.js +3 -3
  51. package/lib/email-client/imap/mailbox.js +28 -93
  52. package/lib/email-client/imap/subconnection.js +10 -7
  53. package/lib/email-client/imap/sync-operations.js +46 -46
  54. package/lib/email-client/imap-client.js +39 -28
  55. package/lib/email-client/message-builder.js +15 -15
  56. package/lib/email-client/notification-handler.js +1 -1
  57. package/lib/email-client/outlook/graph-api.js +10 -4
  58. package/lib/email-client/outlook-client.js +54 -55
  59. package/lib/email-client/smtp-pool-manager.js +1 -1
  60. package/lib/enum-descriptions.js +92 -2
  61. package/lib/export.js +2 -2
  62. package/lib/field-usage.js +133 -0
  63. package/lib/gateway.js +2 -2
  64. package/lib/get-raw-email.js +1 -1
  65. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  66. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  67. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  68. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  69. package/lib/imapproxy/imap-core/lib/imap-connection.js +17 -7
  70. package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
  71. package/lib/imapproxy/imap-server.js +40 -10
  72. package/lib/license-beacon.js +5 -10
  73. package/lib/lists.js +49 -1
  74. package/lib/llm-pre-process.js +6 -6
  75. package/lib/logger.js +5 -1
  76. package/lib/metrics-collector.js +2 -2
  77. package/lib/msgpack.js +62 -0
  78. package/lib/oauth/decode-jwt-payload.js +39 -0
  79. package/lib/oauth/gmail.js +9 -12
  80. package/lib/oauth/mail-ru.js +5 -7
  81. package/lib/oauth/outlook-identity.js +61 -0
  82. package/lib/oauth/outlook.js +9 -9
  83. package/lib/oauth/pubsub/google.js +25 -10
  84. package/lib/oauth/retry-setup.js +38 -0
  85. package/lib/oauth/scope-checker.js +1 -1
  86. package/lib/oauth2-apps.js +224 -295
  87. package/lib/openapi/build-document.js +15 -7
  88. package/lib/openapi/joi-schema.js +20 -0
  89. package/lib/outbox.js +145 -14
  90. package/lib/pre-process.js +9 -9
  91. package/lib/queue-stats.js +49 -0
  92. package/lib/read-env-value.js +37 -0
  93. package/lib/reconnection-manager.js +2 -2
  94. package/lib/rewrite-text-nodes.js +4 -3
  95. package/lib/routes-ui.js +4 -0
  96. package/lib/schemas.js +223 -155
  97. package/lib/settings.js +84 -5
  98. package/lib/sub-script.js +2 -1
  99. package/lib/swagger-options.js +2 -1
  100. package/lib/templates.js +5 -5
  101. package/lib/threads.js +2 -2
  102. package/lib/token-audit-log.js +208 -0
  103. package/lib/token-permission-view.js +219 -0
  104. package/lib/token-permissions.js +172 -0
  105. package/lib/tokens.js +100 -16
  106. package/lib/tools.js +259 -85
  107. package/lib/totp.js +67 -0
  108. package/lib/ui-routes/account-routes.js +122 -26
  109. package/lib/ui-routes/admin-config-routes.js +20 -17
  110. package/lib/ui-routes/admin-entities-routes.js +66 -22
  111. package/lib/ui-routes/auth-routes.js +36 -48
  112. package/lib/ui-routes/export-routes.js +10 -4
  113. package/lib/ui-routes/oauth-config-routes.js +5 -5
  114. package/lib/ui-routes/reference-routes.js +11 -8
  115. package/lib/ui-routes/route-helpers.js +79 -2
  116. package/lib/ui-routes/settings-page.js +1 -1
  117. package/lib/ui-routes/smtp-test-routes.js +1 -1
  118. package/lib/ui-routes/suppression-list-routes.js +294 -0
  119. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  120. package/lib/utils/is-email.js +34 -0
  121. package/lib/utils/network.js +2 -2
  122. package/lib/utils/to-camel-case.js +17 -0
  123. package/lib/web-safe-html.js +1 -1
  124. package/lib/webhook-egress.js +37 -0
  125. package/lib/webhook-routing.js +80 -0
  126. package/lib/webhooks.js +21 -15
  127. package/package.json +26 -27
  128. package/sbom.json +1 -0
  129. package/server.js +81 -42
  130. package/static/css/flyonui.css +1 -1
  131. package/static/css/public.css +3 -0
  132. package/static/css/src/app.tailwind.css +159 -9
  133. package/static/js/app.js +69 -0
  134. package/static/js/reference.js +741 -10
  135. package/static/js/ui.js +43 -0
  136. package/static/licenses.html +698 -1590
  137. package/translations/README.md +64 -0
  138. package/translations/de.mo +0 -0
  139. package/translations/de.po +164 -120
  140. package/translations/en.po +200 -161
  141. package/translations/et.mo +0 -0
  142. package/translations/et.po +163 -120
  143. package/translations/fr.mo +0 -0
  144. package/translations/fr.po +163 -120
  145. package/translations/ja.mo +0 -0
  146. package/translations/ja.po +163 -120
  147. package/translations/messages.pot +94 -64
  148. package/translations/nl.mo +0 -0
  149. package/translations/nl.po +164 -120
  150. package/translations/pl.mo +0 -0
  151. package/translations/pl.po +163 -120
  152. package/views/account-identity-error.hbs +34 -0
  153. package/views/accounts/account.hbs +69 -7
  154. package/views/accounts/browse.hbs +18 -35
  155. package/views/accounts/edit.hbs +1 -0
  156. package/views/accounts/register/imap.hbs +12 -2
  157. package/views/config/logging.hbs +6 -0
  158. package/views/config/oauth/app.hbs +0 -2
  159. package/views/config/security.hbs +13 -0
  160. package/views/layout/app.hbs +29 -5
  161. package/views/oauth-scope-error.hbs +1 -1
  162. package/views/partials/oauth_form.hbs +0 -15
  163. package/views/partials/reference/disclosure.hbs +8 -2
  164. package/views/partials/reference/nav.hbs +36 -9
  165. package/views/partials/reference/operation.hbs +48 -14
  166. package/views/partials/reference/params.hbs +17 -1
  167. package/views/partials/reference/schema-node.hbs +112 -54
  168. package/views/partials/reference/schema-tools.hbs +25 -0
  169. package/views/partials/reference/token-alert.hbs +35 -10
  170. package/views/partials/reference/try-it.hbs +84 -11
  171. package/views/partials/side_menu.hbs +1 -0
  172. package/views/partials/ui/checkbox.hbs +2 -2
  173. package/views/partials/ui/tabs.hbs +7 -1
  174. package/views/reference/index.hbs +1 -1
  175. package/views/reference/token.hbs +4 -0
  176. package/views/suppression-lists/index.hbs +85 -0
  177. package/views/suppression-lists/list.hbs +87 -0
  178. package/views/templates/index.hbs +8 -2
  179. package/views/tokens/index.hbs +31 -4
  180. package/views/tokens/new.hbs +324 -2
  181. package/workers/api.js +299 -140
  182. package/workers/documents.js +46 -26
  183. package/workers/export.js +20 -8
  184. package/workers/imap-proxy.js +2 -2
  185. package/workers/imap.js +13 -7
  186. package/workers/smtp.js +13 -7
  187. package/workers/submit.js +41 -31
  188. package/workers/webhooks.js +60 -37
  189. package/lib/feature-flags.js +0 -48
@@ -6,7 +6,7 @@ const { Mailbox } = require('./imap/mailbox');
6
6
  const logger = require('../logger');
7
7
  const packageData = require('../../package.json');
8
8
  const { backOff } = require('exponential-backoff');
9
- const msgpack = require('msgpack5')();
9
+ const msgpack = require('../msgpack');
10
10
 
11
11
  const { oauth2ProviderData } = require('../oauth2-apps');
12
12
  const { BaseClient } = require('./base-client');
@@ -20,6 +20,7 @@ const { ReconnectBackoff } = require('./reconnect-backoff');
20
20
  const {
21
21
  normalizePath,
22
22
  resolveCredentials,
23
+ useAuthServerForConnection,
23
24
  emitChangeEvent,
24
25
  getByteSize,
25
26
  getBoolean,
@@ -40,6 +41,7 @@ const {
40
41
  AUTH_ERROR_NOTIFY,
41
42
  AUTH_SUCCESS_NOTIFY,
42
43
  CONNECT_ERROR_NOTIFY,
44
+ CONNECTION_CLOSING_CODES,
43
45
  DEFAULT_DOWNLOAD_CHUNK_SIZE,
44
46
  MAX_BACKOFF_DELAY,
45
47
  STABLE_CONNECTION_TIME,
@@ -241,7 +243,13 @@ class IMAPClient extends BaseClient {
241
243
  // check if we need to re-select main mailbox
242
244
  this.completedTimer = setTimeout(() => {
243
245
  clearTimeout(this.completedTimer);
244
- this.ensureMainMailbox().catch(err => this.logger.error({ msg: 'Failed to select main mailbox', err }));
246
+ this.ensureMainMailbox().catch(err => {
247
+ if (CONNECTION_CLOSING_CODES.has(err.code)) {
248
+ this.logger.debug({ msg: 'Select skipped, connection closing', err });
249
+ } else {
250
+ this.logger.error({ msg: 'Failed to select main mailbox', err });
251
+ }
252
+ });
245
253
  }, ENSURE_MAIN_TTL);
246
254
  }
247
255
 
@@ -287,7 +295,7 @@ class IMAPClient extends BaseClient {
287
295
  return connectionClient;
288
296
  }
289
297
  } catch (err) {
290
- this.logger.error({ msg: 'Failed to acquire command connection', reason, err });
298
+ this.logger.warn({ msg: 'Failed to acquire command connection', reason, err });
291
299
  }
292
300
 
293
301
  // Fall back to primary connection
@@ -323,7 +331,6 @@ class IMAPClient extends BaseClient {
323
331
  this.logger.debug({ msg: 'Acquiring connection lock', lockKey });
324
332
  connectLock = await lock.waitAcquireLock(lockKey, 5 * 60 * 1000, 1 * 60 * 1000);
325
333
  if (!connectLock.success) {
326
- this.logger.error({ msg: 'Failed to get lock', lockKey });
327
334
  throw new Error('Failed to get connection lock');
328
335
  }
329
336
  this.logger.debug({ msg: 'Acquired connection lock', lockKey, index: connectLock.index });
@@ -1001,7 +1008,7 @@ class IMAPClient extends BaseClient {
1001
1008
  }
1002
1009
  await mailbox.onExists(event);
1003
1010
  } catch (err) {
1004
- imapClient.log.error({ msg: 'Exists error', err });
1011
+ imapClient.log.error({ msg: 'Failed to process EXISTS notification', path: event?.path, err });
1005
1012
  }
1006
1013
  }
1007
1014
 
@@ -1021,10 +1028,10 @@ class IMAPClient extends BaseClient {
1021
1028
  // that arrived from a replacement connection after a reconnect
1022
1029
  await mailbox.onOpen(event, imapClient);
1023
1030
  } catch (err) {
1024
- if (err.code === 'IMAPConnectionClosing') {
1031
+ if (CONNECTION_CLOSING_CODES.has(err.code)) {
1025
1032
  imapClient.log.debug({ msg: 'Open skipped, connection closing', err });
1026
1033
  } else {
1027
- imapClient.log.error({ msg: 'Open error', err });
1034
+ imapClient.log.error({ msg: 'Failed to process mailbox open notification', path: event?.path, err });
1028
1035
  }
1029
1036
  }
1030
1037
  }
@@ -1042,7 +1049,7 @@ class IMAPClient extends BaseClient {
1042
1049
  }
1043
1050
  await mailbox.onClose(event);
1044
1051
  } catch (err) {
1045
- imapClient.log.error({ msg: 'Close error', err });
1052
+ imapClient.log.error({ msg: 'Failed to process mailbox close notification', path: event?.path, err });
1046
1053
  }
1047
1054
  }
1048
1055
 
@@ -1059,7 +1066,7 @@ class IMAPClient extends BaseClient {
1059
1066
  }
1060
1067
  await mailbox.onFlags(event);
1061
1068
  } catch (err) {
1062
- imapClient.log.error({ msg: 'Flags error', err });
1069
+ imapClient.log.error({ msg: 'Failed to process flag change notification', path: event?.path, err });
1063
1070
  }
1064
1071
  }
1065
1072
 
@@ -1322,11 +1329,10 @@ class IMAPClient extends BaseClient {
1322
1329
  retryCount = 0;
1323
1330
  })
1324
1331
  .catch(err => {
1325
- this.logger.error({ msg: 'Mailbox Sync Error', err, retryCount });
1326
1332
  retryCount++;
1327
1333
  // Exponential backoff with max delay of 30 seconds
1328
1334
  const retryDelay = Math.min(30000, 2000 * Math.pow(2, retryCount));
1329
- this.logger.warn({ msg: 'Scheduling sync retry with backoff', retryDelay, retryCount });
1335
+ this.logger.warn({ msg: 'Failed to sync mailboxes, will retry', err, retryCount, retryDelay });
1330
1336
  setTimeout(setSyncTimer, retryDelay);
1331
1337
  });
1332
1338
  }, this.resyncDelay);
@@ -1387,7 +1393,7 @@ class IMAPClient extends BaseClient {
1387
1393
  }
1388
1394
 
1389
1395
  // If authentication server is set then it overrides authentication data
1390
- if (imapConnectionConfig.useAuthServer) {
1396
+ if (await useAuthServerForConnection(imapConnectionConfig, ctx.logger, { account: this.account, target: 'imap' })) {
1391
1397
  try {
1392
1398
  imapConnectionConfig.auth = await resolveCredentials(this.account, 'imap');
1393
1399
  } catch (err) {
@@ -1397,7 +1403,7 @@ class IMAPClient extends BaseClient {
1397
1403
  serverResponseCode: 'HTTPRequestError'
1398
1404
  });
1399
1405
  ctx.logger.error({
1400
- account: this.account,
1406
+ msg: 'Failed to resolve credentials from authentication server',
1401
1407
  err
1402
1408
  });
1403
1409
  ctx.state = AUTH_ERROR_NOTIFY;
@@ -1413,7 +1419,7 @@ class IMAPClient extends BaseClient {
1413
1419
  // Set local address for outgoing connections (for IP rotation)
1414
1420
  const localAddress = await getLocalAddress(redis, 'imap', this.account);
1415
1421
  imapConnectionConfig.tls.localAddress = localAddress.localAddress;
1416
- this.logger.info({
1422
+ this.logger.debug({
1417
1423
  msg: 'Selected local address',
1418
1424
  account: this.account,
1419
1425
  proto: 'IMAP',
@@ -1705,7 +1711,10 @@ class IMAPClient extends BaseClient {
1705
1711
  }
1706
1712
  }
1707
1713
  } catch (err) {
1708
- imapClient.log.error({ msg: 'Reconnection error', err });
1714
+ // This is the only path that re-arms the connection after an unexpected close.
1715
+ // If it throws, nothing else reconnects the account, so it stays offline until
1716
+ // the worker restarts - never demote this below error.
1717
+ imapClient.log.error({ msg: 'Reconnection error', account: this.account, err });
1709
1718
  }
1710
1719
 
1711
1720
  imapClient = null;
@@ -1735,7 +1744,7 @@ class IMAPClient extends BaseClient {
1735
1744
  let prevConnectedCount = await this.redis.hget(this.getAccountKey(), `state:count:connected`);
1736
1745
  let isFirstSuccessfulConnection = prevConnectedCount === '0'; // string zero means the account has been initialized but not yet connected
1737
1746
 
1738
- let isiInitial = !!isFirstSuccessfulConnection;
1747
+ let isInitial = !!isFirstSuccessfulConnection;
1739
1748
 
1740
1749
  if (!isFirstSuccessfulConnection) {
1741
1750
  // check if the connection was previously in an errored state
@@ -1756,18 +1765,20 @@ class IMAPClient extends BaseClient {
1756
1765
 
1757
1766
  // Send appropriate notifications based on connection history
1758
1767
  if (isFirstSuccessfulConnection) {
1759
- this.logger.info({ msg: 'Successful login without a previous active session', account: this.account, isiInitial, prevActive: false });
1768
+ this.logger.info({ msg: 'Successful login without a previous active session', account: this.account, isInitial, prevActive: false });
1760
1769
  await this.notify(false, AUTH_SUCCESS_NOTIFY, {
1761
1770
  user: imapConfig.auth.user
1762
1771
  });
1763
1772
  } else {
1764
- this.logger.info({ msg: 'Successful login with a previous active session', account: this.account, isiInitial, prevActive: true });
1773
+ this.logger.info({ msg: 'Successful login with a previous active session', account: this.account, isInitial, prevActive: true });
1765
1774
  }
1766
1775
 
1767
1776
  // Set up subconnections for monitoring multiple folders
1768
1777
  this.setupSubConnections()
1769
1778
  .then(result => {
1770
- this.logger.info({ msg: 'Set up subconnections', account: this.account, result });
1779
+ if (result !== null) {
1780
+ this.logger.info({ msg: 'Set up subconnections', account: this.account, result });
1781
+ }
1771
1782
  })
1772
1783
  .catch(err => {
1773
1784
  this.logger.error({ msg: 'Failed to set up subconnections', account: this.account, err });
@@ -1808,14 +1819,14 @@ class IMAPClient extends BaseClient {
1808
1819
  // webhook payloads never render as "[object Object]"
1809
1820
  let errorResponse = (typeof err.response === 'string' && err.response) || err.responseText;
1810
1821
  if (err.authenticationFailed) {
1811
- this.logger.error({ msg: 'Failed to authenticate', account: this.account, err });
1822
+ this.logger.warn({ msg: 'Failed to authenticate', account: this.account, err });
1812
1823
  await this.notify(false, AUTH_ERROR_NOTIFY, {
1813
1824
  response: errorResponse,
1814
1825
  serverResponseCode: err.serverResponseCode
1815
1826
  });
1816
1827
  this.state = 'authenticationError';
1817
1828
  } else {
1818
- this.logger.error({ msg: 'Failed to connect', account: this.account, err });
1829
+ this.logger.warn({ msg: 'Failed to connect', account: this.account, err });
1819
1830
  await this.notify(false, CONNECT_ERROR_NOTIFY, {
1820
1831
  response: errorResponse || err.message,
1821
1832
  serverResponseCode: err.serverResponseCode || err.code
@@ -1902,7 +1913,7 @@ class IMAPClient extends BaseClient {
1902
1913
  this.closeSubconnections();
1903
1914
  }
1904
1915
 
1905
- this.logger.info({ msg: 'Closed account', account: this.account });
1916
+ this.logger.info({ msg: 'Deleted account', account: this.account });
1906
1917
  }
1907
1918
 
1908
1919
  /**
@@ -2190,7 +2201,7 @@ class IMAPClient extends BaseClient {
2190
2201
  // force sync target mailbox to show moved messages
2191
2202
  let targetMailbox = this.mailboxes.get(normalizePath(target.path));
2192
2203
  if (targetMailbox) {
2193
- targetMailbox.sync().catch(err => this.logger.error({ msg: 'Mailbox sync error', path: target.path, err }));
2204
+ targetMailbox.sync().catch(err => this.logger.warn({ msg: 'Failed to sync mailbox', path: target.path, err }));
2194
2205
  }
2195
2206
 
2196
2207
  return res;
@@ -2249,7 +2260,7 @@ class IMAPClient extends BaseClient {
2249
2260
  if (res && res.moved && res.moved.destination) {
2250
2261
  let targetMailbox = this.mailboxes.get(normalizePath(res.moved.destination));
2251
2262
  if (targetMailbox) {
2252
- targetMailbox.sync().catch(err => this.logger.error({ msg: 'Mailbox sync error', path: res && res.moved && res.moved.destination, err }));
2263
+ targetMailbox.sync().catch(err => this.logger.warn({ msg: 'Failed to sync mailbox', path: res && res.moved && res.moved.destination, err }));
2253
2264
  }
2254
2265
  }
2255
2266
 
@@ -2488,7 +2499,7 @@ class IMAPClient extends BaseClient {
2488
2499
  */
2489
2500
  runPostListing() {
2490
2501
  this.refreshAndProcessListing().catch(err => {
2491
- this.logger.error({ msg: 'List refresh error', err });
2502
+ this.logger.warn({ msg: 'Failed to refresh folder listing', err });
2492
2503
  });
2493
2504
  }
2494
2505
 
@@ -2712,7 +2723,7 @@ class IMAPClient extends BaseClient {
2712
2723
  if (this.imapClient && connectionClient === this.imapClient && this.imapClient.mailbox && !this.imapClient.idling) {
2713
2724
  // force back to IDLE
2714
2725
  this.imapClient.idle().catch(err => {
2715
- this.logger.error({ msg: 'IDLE error', err });
2726
+ this.logger.warn({ msg: 'IDLE error', err });
2716
2727
  });
2717
2728
  }
2718
2729
 
@@ -2771,7 +2782,7 @@ class IMAPClient extends BaseClient {
2771
2782
  this.logger.error({ msg: 'Failed to process listing', err: listingErr });
2772
2783
  });
2773
2784
  } catch (E) {
2774
- this.logger.error({ msg: 'Missing mailbox', err, E });
2785
+ this.logger.error({ msg: 'Failed to refresh listing after missing mailbox', err: E });
2775
2786
  }
2776
2787
  }
2777
2788
 
@@ -2793,7 +2804,7 @@ class IMAPClient extends BaseClient {
2793
2804
  }
2794
2805
  await mailbox.onExpunge(payload);
2795
2806
  } catch (err) {
2796
- this.logger.error({ msg: 'Expunge error', err });
2807
+ this.logger.error({ msg: 'Failed to process EXPUNGE notification', path: payload?.path, err });
2797
2808
  }
2798
2809
  }
2799
2810
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { Gateway } = require('../gateway');
4
4
  const { oauth2ProviderData } = require('../oauth2-apps');
5
- const { resolveCredentials } = require('../tools');
5
+ const { resolveCredentials, useAuthServerForConnection } = require('../tools');
6
6
  const { getLocalAddress } = require('../utils/network');
7
7
  const settings = require('../settings');
8
8
  const { TLS_DEFAULTS } = require('../consts');
@@ -48,7 +48,7 @@ class SmtpConfigBuilder {
48
48
  const gatewayData = await gatewayObject.loadGatewayData();
49
49
  return { gatewayData, gatewayObject };
50
50
  } catch (err) {
51
- this.logger.info({
51
+ this.logger.warn({
52
52
  msg: 'Failed to load gateway data',
53
53
  messageId,
54
54
  gateway: gatewayId,
@@ -133,20 +133,20 @@ class SmtpConfigBuilder {
133
133
  * @returns {Promise<Object|null>} Resolved auth credentials
134
134
  */
135
135
  async resolveAuthServer(smtpConnectionConfig) {
136
- if (!smtpConnectionConfig.useAuthServer) {
137
- return smtpConnectionConfig.auth;
136
+ if (await useAuthServerForConnection(smtpConnectionConfig, this.logger, { account: this.account, target: 'smtp' })) {
137
+ try {
138
+ return await resolveCredentials(this.account, 'smtp');
139
+ } catch (err) {
140
+ err.authenticationFailed = true;
141
+ this.logger.error({
142
+ msg: 'Failed to resolve SMTP credentials from the authentication server',
143
+ err
144
+ });
145
+ throw err;
146
+ }
138
147
  }
139
148
 
140
- try {
141
- return await resolveCredentials(this.account, 'smtp');
142
- } catch (err) {
143
- err.authenticationFailed = true;
144
- this.logger.error({
145
- account: this.account,
146
- err
147
- });
148
- throw err;
149
- }
149
+ return smtpConnectionConfig.auth;
150
150
  }
151
151
 
152
152
  /**
@@ -164,7 +164,7 @@ class SmtpConfigBuilder {
164
164
  // Get local address for outbound connection
165
165
  const { localAddress: address, name, addressSelector: selector } = await getLocalAddress(this.redis, 'smtp', this.account, data.localAddress);
166
166
 
167
- this.logger.info({
167
+ this.logger.debug({
168
168
  msg: 'Selected local address',
169
169
  account: this.account,
170
170
  proto: 'SMTP',
@@ -149,7 +149,7 @@ class NotificationHandler {
149
149
  const thread = await getThread(client, index, this.account, payload.data, logger);
150
150
  if (thread) {
151
151
  payload.data.threadId = thread;
152
- this.logger.info({
152
+ this.logger.debug({
153
153
  msg: 'Provisioned thread ID for a message',
154
154
  account: this.account,
155
155
  message: payload.data.id,
@@ -63,7 +63,7 @@ async function request(context, url, method, payload, options = {}) {
63
63
  try {
64
64
  accessToken = await context.getToken();
65
65
  } catch (err) {
66
- context.logger.error({ msg: 'Failed to load access token', account: context.account, err });
66
+ context.logger.warn({ msg: 'Failed to load access token', account: context.account, err });
67
67
  throw err;
68
68
  }
69
69
 
@@ -111,6 +111,12 @@ async function request(context, url, method, payload, options = {}) {
111
111
  const graphError = createGraphError(err.oauthRequest?.response?.error, graphErrorCode);
112
112
 
113
113
  if (graphError) {
114
+ // Carry the raw Graph exchange over to the mapped error. Callers in outlook-client.js
115
+ // build their own responses by switching on `err.oauthRequest.response.error.code` and
116
+ // `err.oauthRequest.status`, so dropping it here silently disables every one of those
117
+ // branches and turns a mapped 404 into a generic 400 with an undefined code.
118
+ graphError.oauthRequest = err.oauthRequest;
119
+
114
120
  context.logger.debug({
115
121
  msg: 'Graph API error mapped to internal code',
116
122
  account: context.account,
@@ -128,12 +134,12 @@ async function request(context, url, method, payload, options = {}) {
128
134
  case 401:
129
135
  // NOTE: never include `accessToken` here - this logger persists to the per-account
130
136
  // log store (exposed via the account logs API/UI) and to Sentry (security review M3).
131
- context.logger.error({ msg: 'Failed to authenticate API request', account: context.account, err });
137
+ context.logger.warn({ msg: 'Failed to authenticate API request', account: context.account, err });
132
138
  throw err;
133
139
 
134
140
  case 429:
135
141
  // Rate limiting
136
- context.logger.error({ msg: 'API request was throttled', account: context.account, err });
142
+ context.logger.warn({ msg: 'API request was throttled', account: context.account, err });
137
143
  throw err;
138
144
 
139
145
  default:
@@ -200,7 +206,7 @@ async function requestWithRetry(context, url, method, payload, options = {}) {
200
206
  // Use Retry-After header if available, otherwise use exponential backoff
201
207
  const retryAfter = err.retryAfter || Math.min(OUTLOOK_RETRY_BASE_DELAY * Math.pow(2, attempt), OUTLOOK_RETRY_MAX_DELAY);
202
208
 
203
- context.logger.info({
209
+ context.logger.debug({
204
210
  msg: 'Rate limited, retrying after delay',
205
211
  account: context.account,
206
212
  attempt: attempt + 1,