emailengine-app 2.81.1 → 2.82.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 (208) hide show
  1. package/.ncurc.js +12 -6
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +52 -0
  4. package/Dockerfile +4 -2
  5. package/bin/emailengine.js +28 -18
  6. package/config/default.toml +0 -5
  7. package/config/test.toml +0 -5
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +70 -42
  10. package/getswagger.sh +0 -4
  11. package/lib/account/account-state.js +2 -110
  12. package/lib/account/bounce-store-sweep.js +63 -0
  13. package/lib/account/expected-identity.js +1 -1
  14. package/lib/account-assignment.js +207 -0
  15. package/lib/account.js +374 -878
  16. package/lib/api-reference/index.js +2 -3
  17. package/lib/api-reference/schema-tree.js +53 -3
  18. package/lib/api-routes/account-routes.js +18 -29
  19. package/lib/api-routes/blocklist-routes.js +2 -2
  20. package/lib/api-routes/bull-board-routes.js +1 -6
  21. package/lib/api-routes/export-routes.js +2 -22
  22. package/lib/api-routes/gateway-routes.js +5 -14
  23. package/lib/api-routes/index.js +1 -13
  24. package/lib/api-routes/mailbox-routes.js +2 -7
  25. package/lib/api-routes/mcp-oauth-routes.js +2 -1
  26. package/lib/api-routes/mcp-routes.js +7 -7
  27. package/lib/api-routes/message-routes.js +44 -236
  28. package/lib/api-routes/mint-bounds.js +110 -0
  29. package/lib/api-routes/oauth2-app-routes.js +23 -32
  30. package/lib/api-routes/operation-impact.js +1 -1
  31. package/lib/api-routes/outbox-routes.js +2 -2
  32. package/lib/api-routes/permission-map.js +1 -7
  33. package/lib/api-routes/route-helpers.js +11 -5
  34. package/lib/api-routes/settings-routes.js +19 -19
  35. package/lib/api-routes/stats-routes.js +1 -1
  36. package/lib/api-routes/submit-routes.js +17 -18
  37. package/lib/api-routes/template-routes.js +4 -9
  38. package/lib/api-routes/token-routes.js +27 -5
  39. package/lib/api-token-scheme.js +71 -0
  40. package/lib/arf-detect.js +41 -7
  41. package/lib/auth-token.js +44 -24
  42. package/lib/autodetect-imap-settings.js +163 -123
  43. package/lib/bounce-detect.js +25 -16
  44. package/lib/calendar-event.js +78 -0
  45. package/lib/consts.js +51 -5
  46. package/lib/create-imap-client.js +24 -0
  47. package/lib/db.js +76 -17
  48. package/lib/delivery-error.js +2 -1
  49. package/lib/egress-fetch.js +54 -3
  50. package/lib/egress-filter.js +11 -0
  51. package/lib/email-client/api-retry.js +147 -0
  52. package/lib/email-client/base-client.js +628 -615
  53. package/lib/email-client/gmail/gmail-api.js +38 -125
  54. package/lib/email-client/gmail/send-request.js +1 -1
  55. package/lib/email-client/gmail-client.js +170 -84
  56. package/lib/email-client/imap/mailbox.js +244 -535
  57. package/lib/email-client/imap/stale-view.js +109 -0
  58. package/lib/email-client/imap/subconnection.js +46 -9
  59. package/lib/email-client/imap/sync-operations.js +5 -37
  60. package/lib/email-client/imap-client.js +188 -64
  61. package/lib/email-client/message-builder.js +9 -14
  62. package/lib/email-client/notification-handler.js +5 -219
  63. package/lib/email-client/outlook/graph-api.js +147 -126
  64. package/lib/email-client/outlook/send-request.js +10 -4
  65. package/lib/email-client/outlook-client.js +519 -617
  66. package/lib/email-client/smtp-pool-manager.js +3 -2
  67. package/lib/encrypt.js +184 -19
  68. package/lib/enum-descriptions.js +1 -2
  69. package/lib/export.js +144 -41
  70. package/lib/gateway.js +20 -6
  71. package/lib/get-raw-email.js +26 -44
  72. package/lib/handlebars-helpers.js +31 -10
  73. package/lib/imap-proxy-auth.js +13 -29
  74. package/lib/imapproxy/imap-core/README.md +1 -0
  75. package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
  76. package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
  77. package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
  78. package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
  79. package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
  80. package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
  81. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
  82. package/lib/imapproxy/imap-server.js +17 -177
  83. package/lib/imapproxy/proxy-handoff.js +235 -0
  84. package/lib/imapproxy/response-error.js +33 -0
  85. package/lib/imapproxy/upstream-client.js +2 -2
  86. package/lib/license-beacon.js +3 -9
  87. package/lib/llm-pre-process.js +182 -43
  88. package/lib/logger.js +1 -1
  89. package/lib/lua/ee-export-queue-add.lua +39 -0
  90. package/lib/lua/ee-get-idempotency.lua +15 -3
  91. package/lib/lua/ee-release-attempts.lua +23 -0
  92. package/lib/lua/ee-reserve-attempts.lua +42 -0
  93. package/lib/lua/h-set-bigger.lua +12 -2
  94. package/lib/lua/s-list-accounts.lua +6 -3
  95. package/lib/mcp/index.js +1 -2
  96. package/lib/mcp/listen.js +221 -18
  97. package/lib/mcp/oauth.js +44 -5
  98. package/lib/mcp/resources.js +8 -2
  99. package/lib/mcp/tools.js +13 -0
  100. package/lib/message-port-stream.js +64 -6
  101. package/lib/msgpack.js +1 -6
  102. package/lib/oauth/external-account-signer.js +16 -13
  103. package/lib/oauth/gmail.js +22 -20
  104. package/lib/oauth/outlook.js +19 -16
  105. package/lib/oauth/pubsub/google.js +38 -2
  106. package/lib/oauth/scope-checker.js +4 -7
  107. package/lib/oauth/verify-app.js +2 -2
  108. package/lib/oauth2-apps.js +139 -44
  109. package/lib/openapi/build-document.js +1 -1
  110. package/lib/openapi/joi-schema.js +78 -9
  111. package/lib/parse-message.js +21 -0
  112. package/lib/payload-examples-webhooks.json +4 -7
  113. package/lib/pbkdf2-phc.js +101 -0
  114. package/lib/privileged-settings.js +0 -14
  115. package/lib/rate-limit.js +54 -15
  116. package/lib/redis-scan-delete.js +56 -29
  117. package/lib/redis-url.js +3 -1
  118. package/lib/respawn-backoff.js +5 -4
  119. package/lib/response-stream.js +25 -4
  120. package/lib/rewrite-text-nodes.js +27 -40
  121. package/lib/routes-ui.js +0 -5
  122. package/lib/schemas.js +129 -262
  123. package/lib/sentry.js +21 -5
  124. package/lib/settings.js +58 -59
  125. package/lib/smtp-auth.js +6 -2
  126. package/lib/smtp-message-processor.js +28 -7
  127. package/lib/sso.js +7 -3
  128. package/lib/stream-encrypt.js +14 -13
  129. package/lib/swagger-options.js +3 -1
  130. package/lib/tls/provision.js +69 -3
  131. package/lib/tls/store.js +14 -1
  132. package/lib/tools.js +113 -52
  133. package/lib/totp.js +16 -1
  134. package/lib/ui-routes/account-routes.js +27 -63
  135. package/lib/ui-routes/admin-config-routes.js +111 -134
  136. package/lib/ui-routes/admin-entities-routes.js +101 -191
  137. package/lib/ui-routes/ai-options.js +104 -0
  138. package/lib/ui-routes/auth-routes.js +98 -18
  139. package/lib/ui-routes/export-routes.js +3 -23
  140. package/lib/ui-routes/internals-routes.js +12 -9
  141. package/lib/ui-routes/network-config-routes.js +8 -18
  142. package/lib/ui-routes/oauth-config-routes.js +80 -214
  143. package/lib/ui-routes/route-helpers.js +40 -44
  144. package/lib/ui-routes/unsubscribe-routes.js +2 -2
  145. package/lib/utils/decode-headers.js +32 -5
  146. package/lib/utils/header-map.js +62 -1
  147. package/lib/utils/network.js +2 -0
  148. package/lib/web-safe-html.js +77 -4
  149. package/lib/webhook-request.js +9 -1
  150. package/lib/webhook-routing.js +27 -1
  151. package/lib/webhooks.js +120 -43
  152. package/lib/worker-rpc-error.js +43 -2
  153. package/list-generate.js +13 -2
  154. package/package.json +38 -46
  155. package/sbom.json +1 -1
  156. package/scripts/refresh-test-tokens.js +42 -14
  157. package/server.js +340 -336
  158. package/static/css/flyonui.css +1 -1
  159. package/static/css/src/app.tailwind.css +7 -8
  160. package/static/js/ee-client.js +145 -70
  161. package/static/js/ui.js +350 -154
  162. package/static/licenses.html +460 -1861
  163. package/translations/messages.pot +99 -99
  164. package/views/accounts/browse.hbs +10 -4
  165. package/views/config/ai.hbs +49 -41
  166. package/views/config/oauth/app.hbs +2 -1
  167. package/views/dashboard.hbs +18 -16
  168. package/views/layout/app.hbs +0 -22
  169. package/views/layout/login.hbs +2 -1
  170. package/views/partials/filter_editor_js.hbs +4 -3
  171. package/views/partials/side_menu.hbs +0 -4
  172. package/views/partials/ui/account-picker.hbs +6 -32
  173. package/views/partials/ui/model-picker.hbs +31 -0
  174. package/views/partials/ui/pagination.hbs +6 -1
  175. package/views/partials/ui/picker.hbs +47 -0
  176. package/views/unsubscribe.hbs +1 -1
  177. package/workers/api.js +33 -23
  178. package/workers/export.js +55 -60
  179. package/workers/imap.js +134 -47
  180. package/workers/submit.js +3 -1
  181. package/workers/webhooks.js +46 -27
  182. package/.githooks/pre-commit +0 -80
  183. package/.github/CODE_OF_CONDUCT.md +0 -76
  184. package/.github/contributing.md +0 -17
  185. package/.github/dependabot.yml +0 -22
  186. package/.github/docker-smoke-test.sh +0 -61
  187. package/.github/workflows/deploy.yml +0 -215
  188. package/.github/workflows/e2e.yml +0 -55
  189. package/.github/workflows/release.yaml +0 -217
  190. package/.github/workflows/test.yml +0 -307
  191. package/lib/api-routes/chat-routes.js +0 -535
  192. package/lib/append-list.js +0 -63
  193. package/lib/document-store.js +0 -75
  194. package/lib/es.js +0 -757
  195. package/lib/generate-text-preview.js +0 -61
  196. package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
  197. package/lib/lua/h-push.lua +0 -32
  198. package/lib/pre-process.js +0 -196
  199. package/lib/threads.js +0 -155
  200. package/lib/ui-routes/document-store-routes.js +0 -806
  201. package/playwright.config.js +0 -47
  202. package/views/config/document-store/chat.hbs +0 -286
  203. package/views/config/document-store/index.hbs +0 -146
  204. package/views/config/document-store/mappings/index.hbs +0 -108
  205. package/views/config/document-store/mappings/new.hbs +0 -68
  206. package/views/config/document-store/pre-processing/index.hbs +0 -103
  207. package/views/partials/document_store_header.hbs +0 -30
  208. package/workers/documents.js +0 -1128
@@ -145,9 +145,8 @@ function jsonForScript(value) {
145
145
  // halves the payload since the operation id is already the key.
146
146
  //
147
147
  // The lookup is keyed on the operation id alone, deliberately ignoring the tag in the old
148
- // hash - tags get renamed (the Chat endpoints now sit under "Deprecated endpoints (Document
149
- // Store)"), which would strand every link that named the old one. The tag table is only a
150
- // second chance for a link whose operation no longer exists but whose group still does.
148
+ // hash - tags get renamed, which would strand every link that named the old one. The tag table
149
+ // is only a second chance for a link whose operation no longer exists but whose group still does.
151
150
  let redirectMapJson;
152
151
 
153
152
  async function getRedirectView(request) {
@@ -65,6 +65,34 @@ function lookupRef(spec, ref) {
65
65
  return (spec.components && spec.components.schemas && spec.components.schemas[name]) || null;
66
66
  }
67
67
 
68
+ // A branch that only lists primitive values of one type, as lib/openapi/joi-schema.js
69
+ // withForeignValues() emits for an allowed value of another type than the schema's own
70
+ function isSentinelBranch(branch) {
71
+ return (
72
+ !!branch &&
73
+ typeof branch === 'object' &&
74
+ Object.keys(branch).length === 2 &&
75
+ ['boolean', 'number', 'string'].includes(branch.type) &&
76
+ Array.isArray(branch.enum) &&
77
+ branch.enum.length > 0
78
+ );
79
+ }
80
+
81
+ // Splits `anyOf: [schema, ...sentinel branches]` into the schema and the sentinel values, or
82
+ // returns null for any other shape (a real alternatives list stays a list of variants)
83
+ function sentinelFold(schema) {
84
+ if (!schema || typeof schema !== 'object' || !Array.isArray(schema.anyOf) || schema.anyOf.length < 2) {
85
+ return null;
86
+ }
87
+
88
+ const [main, ...rest] = schema.anyOf;
89
+ if (isSentinelBranch(main) || !rest.every(isSentinelBranch)) {
90
+ return null;
91
+ }
92
+
93
+ return { main, sentinels: rest.flatMap(branch => branch.enum) };
94
+ }
95
+
68
96
  // Follows a $ref chain to the underlying schema. `refStack` carries the refs already
69
97
  // visited on the current branch; revisiting one means the document is recursive, which
70
98
  // is reported rather than followed.
@@ -87,6 +115,28 @@ function resolve(spec, schema, refStack) {
87
115
  current = target;
88
116
  }
89
117
 
118
+ // The generator publishes `.allow(false)` beside an object or a string as
119
+ // `anyOf: [schema, {type: 'boolean', enum: [false]}]`, which is what a strict validator
120
+ // needs. A reader is better served by the schema itself with the sentinel on its own
121
+ // "also accepts" line, so the pair is folded back into the enum form enumInfo() splits.
122
+ const fold = sentinelFold(current);
123
+ if (fold) {
124
+ const inner = resolve(spec, fold.main, stack);
125
+ if (!inner.schema || typeof inner.schema !== 'object') {
126
+ return inner;
127
+ }
128
+
129
+ const merged = Object.assign({}, inner.schema);
130
+ for (const key of Object.keys(current)) {
131
+ if (key !== 'anyOf') {
132
+ merged[key] = current[key];
133
+ }
134
+ }
135
+ merged.enum = (Array.isArray(inner.schema.enum) ? inner.schema.enum : []).concat(fold.sentinels);
136
+
137
+ return { schema: merged, refStack: inner.refStack };
138
+ }
139
+
90
140
  return { schema: current, refStack: stack };
91
141
  }
92
142
 
@@ -147,9 +197,9 @@ function matchesType(type, value) {
147
197
  // Returns null when the schema is not an enum, so callers can assign both fields in one go.
148
198
  //
149
199
  // The enum is split by whether a value can be an instance of the schema's own type.
150
- // lib/openapi/joi-schema.js emits `.valid()` and `.allow()` into one `enum`, so a joi
151
- // `.allow(false)` lands there too - 35 schemas in the document carry `enum: [false]` beside
152
- // a `string`, `integer` or `object` type. Those are sentinels standing next to the type, not
200
+ // A joi `.allow(false)` beside a `string`, `integer` or `object` type reaches here in the enum:
201
+ // the document publishes it as a separate anyOf branch, which resolve() folds back into the
202
+ // enum for rendering. Those are sentinels standing next to the type, not
153
203
  // its value domain: `false` clears the block on an update payload and means "not available"
154
204
  // on a response. Rendered through the normal "Allowed" row they claimed the only value an
155
205
  // IMAP configuration object accepts is `false`. `alsoAccepts` gets its own line instead.
@@ -30,7 +30,8 @@ const {
30
30
  shortMailboxesSchema,
31
31
  ACCOUNT_DISPLAY_STATES,
32
32
  apiResponses,
33
- ENUM_DESCRIPTIONS
33
+ ENUM_DESCRIPTIONS,
34
+ apiBoolean
34
35
  } = require('../schemas');
35
36
 
36
37
  const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES, MCP_MAX_PAGE_SIZE } = require('../consts');
@@ -158,7 +159,6 @@ async function init(args) {
158
159
  const {
159
160
  server,
160
161
  call,
161
- documentsQueue,
162
162
  oauth2Schema: oauth2SchemaArg,
163
163
  imapSchema: imapSchemaArg,
164
164
  smtpSchema: smtpSchemaArg,
@@ -338,7 +338,7 @@ async function init(args) {
338
338
  logs: Joi.boolean().example(false).description('Store recent logs').default(false),
339
339
 
340
340
  notifyFrom: accountSchemas.notifyFrom.default('now'),
341
- syncFrom: accountSchemas.syncFrom.default(null),
341
+ syncFrom: accountSchemas.syncFrom,
342
342
 
343
343
  proxy: settingsSchema.proxyUrl,
344
344
  smtpEhloName: settingsSchema.smtpEhloName,
@@ -621,13 +621,13 @@ async function init(args) {
621
621
  }),
622
622
 
623
623
  payload: Joi.object({
624
- reconnect: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Only reconnect if true')
624
+ reconnect: apiBoolean().default(false).description('Only reconnect if true')
625
625
  }).label('RequestReconnect')
626
626
  },
627
627
 
628
628
  response: {
629
629
  schema: Joi.object({
630
- reconnect: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Reconnection status')
630
+ reconnect: apiBoolean().default(false).description('Reconnection status')
631
631
  }).label('RequestReconnectResponse'),
632
632
  failAction: 'log'
633
633
  }
@@ -700,13 +700,13 @@ async function init(args) {
700
700
  }),
701
701
 
702
702
  payload: Joi.object({
703
- sync: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Only sync if true')
703
+ sync: apiBoolean().default(false).description('Only sync if true')
704
704
  }).label('RequestSync')
705
705
  },
706
706
 
707
707
  response: {
708
708
  schema: Joi.object({
709
- sync: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Sync status')
709
+ sync: apiBoolean().default(false).description('Sync status')
710
710
  }).label('RequestSyncResponse'),
711
711
  failAction: 'log'
712
712
  }
@@ -722,7 +722,6 @@ async function init(args) {
722
722
  let accountObject = new Account({
723
723
  redis,
724
724
  account: request.params.account,
725
- documentsQueue,
726
725
  call,
727
726
  secret: await getSecret(),
728
727
  timeout: request.headers['x-ee-timeout']
@@ -784,9 +783,7 @@ async function init(args) {
784
783
  }),
785
784
 
786
785
  query: Joi.object({
787
- revoke: Joi.boolean()
788
- .truthy('Y', 'true', '1')
789
- .falsy('N', 'false', 0)
786
+ revoke: apiBoolean()
790
787
  .default(false)
791
788
  .description('Revoke the upstream OAuth2 grant at the provider before deleting the account')
792
789
  .meta({ usage: FIELD_USAGE.revokeGrant })
@@ -796,7 +793,7 @@ async function init(args) {
796
793
  response: {
797
794
  schema: Joi.object({
798
795
  account: accountIdSchema.required(),
799
- deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the account deleted')
796
+ deleted: apiBoolean().default(true).description('Was the account deleted')
800
797
  }).label('DeleteAccountResponse'),
801
798
  failAction: 'log'
802
799
  }
@@ -808,13 +805,12 @@ async function init(args) {
808
805
  method: 'PUT',
809
806
  path: '/v1/account/{account}/flush',
810
807
 
811
- async handler(request, h) {
808
+ async handler(request) {
812
809
  let accountObject = new Account({
813
810
  redis,
814
811
  account: request.params.account,
815
812
  call,
816
813
  secret: await getSecret(),
817
- esClient: await h.getESClient(request.logger),
818
814
  timeout: request.headers['x-ee-timeout']
819
815
  });
820
816
 
@@ -827,7 +823,7 @@ async function init(args) {
827
823
  options: {
828
824
  description: 'Request account flush',
829
825
  notes: [
830
- 'Deletes all email indexes from Redis and ElasticSearch and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
826
+ 'Deletes all email indexes from Redis and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
831
827
  BEHAVIOR.SCHEDULED_ON_WORKER
832
828
  ],
833
829
  tags: ['api', 'Account'],
@@ -875,7 +871,7 @@ async function init(args) {
875
871
  }),
876
872
 
877
873
  payload: Joi.object({
878
- flush: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Only flush the account if true'),
874
+ flush: apiBoolean().default(false).description('Only flush the account if true'),
879
875
  notifyFrom: accountSchemas.notifyFrom.default('now'),
880
876
  imapIndexer: accountSchemas.imapIndexer,
881
877
  syncFrom: accountSchemas.syncFrom
@@ -884,7 +880,7 @@ async function init(args) {
884
880
 
885
881
  response: {
886
882
  schema: Joi.object({
887
- flush: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Flush status')
883
+ flush: apiBoolean().default(false).description('Flush status')
888
884
  }).label('RequestFlushResponse'),
889
885
  failAction: 'log'
890
886
  }
@@ -1080,7 +1076,6 @@ async function init(args) {
1080
1076
  'copy',
1081
1077
  'logs',
1082
1078
  'notifyFrom',
1083
- 'syncFrom',
1084
1079
  'path',
1085
1080
  'subconnections',
1086
1081
  'webhooks',
@@ -1120,7 +1115,7 @@ async function init(args) {
1120
1115
  }
1121
1116
 
1122
1117
  // default null
1123
- for (let key of ['notifyFrom', 'syncFrom', 'lastError', 'smtpStatus']) {
1118
+ for (let key of ['notifyFrom', 'lastError', 'smtpStatus']) {
1124
1119
  result[key] = result[key] || null;
1125
1120
  }
1126
1121
 
@@ -1219,12 +1214,7 @@ async function init(args) {
1219
1214
  }),
1220
1215
 
1221
1216
  query: Joi.object({
1222
- quota: Joi.boolean()
1223
- .truthy('Y', 'true', '1')
1224
- .falsy('N', 'false', 0)
1225
- .default(false)
1226
- .description('If true, then include quota information in the response')
1227
- .label('AccountQuota')
1217
+ quota: apiBoolean().default(false).description('If true, then include quota information in the response').label('AccountQuota')
1228
1218
  })
1229
1219
  },
1230
1220
 
@@ -1583,7 +1573,6 @@ async function init(args) {
1583
1573
  name: request.payload.name,
1584
1574
  email: request.payload.email,
1585
1575
  expectedEmail: request.payload.expectedEmail,
1586
- syncFrom: request.payload.syncFrom,
1587
1576
  notifyFrom: request.payload.notifyFrom,
1588
1577
  subconnections: request.payload.subconnections,
1589
1578
  redirectUrl: request.payload.redirectUrl,
@@ -1697,21 +1686,21 @@ async function init(args) {
1697
1686
  delegated: Joi.boolean()
1698
1687
  .empty('')
1699
1688
  .truthy('Y', 'true', '1')
1700
- .falsy('N', 'false', 0)
1689
+ .falsy('N', 'false', '0', 0)
1701
1690
  .default(false)
1702
1691
  .description('If true, configures this account as a shared mailbox. Currently supported by MS365 OAuth2 accounts'),
1703
1692
 
1704
1693
  skipServerSettings: Joi.boolean()
1705
1694
  .empty('')
1706
1695
  .truthy('Y', 'true', '1')
1707
- .falsy('N', 'false', 0)
1696
+ .falsy('N', 'false', '0', 0)
1708
1697
  .default(true)
1709
1698
  .description(
1710
1699
  'If true, the mail server settings step is skipped whenever the IMAP and SMTP settings for the address can both be discovered and verified with the password the user enters. The step is still shown if discovery or verification does not fully succeed. Set to false to always ask the user for the server settings. Applies to the IMAP setup path only.'
1711
1700
  ),
1712
1701
 
1713
- syncFrom: accountSchemas.syncFrom,
1714
1702
  notifyFrom: accountSchemas.notifyFrom,
1703
+ syncFrom: accountSchemas.syncFrom,
1715
1704
 
1716
1705
  subconnections: accountSchemas.subconnections,
1717
1706
 
@@ -8,7 +8,7 @@ const getSecret = require('../get-secret');
8
8
  const { lists } = require('../lists');
9
9
  const { failAction } = require('../tools');
10
10
  const { handleError } = require('./route-helpers');
11
- const { accountIdSchema, blocklistListIdSchema, apiResponses } = require('../schemas');
11
+ const { accountIdSchema, blocklistListIdSchema, apiResponses, apiBoolean } = require('../schemas');
12
12
  const { IMPACT } = require('./operation-impact');
13
13
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
14
14
 
@@ -331,7 +331,7 @@ async function init(args) {
331
331
 
332
332
  response: {
333
333
  schema: Joi.object({
334
- deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the address removed from the list')
334
+ deleted: apiBoolean().default(true).description('Was the address removed from the list')
335
335
  }).label('DeleteBlocklistResponse'),
336
336
  failAction: 'log'
337
337
  }
@@ -3,7 +3,7 @@
3
3
  const { createBullBoard } = require('@bull-board/api');
4
4
  const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');
5
5
  const { HapiAdapter } = require('@bull-board/hapi');
6
- const { notifyQueue, submitQueue, documentsQueue } = require('../db');
6
+ const { notifyQueue, submitQueue } = require('../db');
7
7
  const { BULL_BOARD_BASE_PATH } = require('../consts');
8
8
 
9
9
  async function init(args) {
@@ -21,11 +21,6 @@ async function init(args) {
21
21
  queue: submitQueue,
22
22
  prefix: 'Submission Queue - ',
23
23
  description: 'This queue contains emails that are scheduled to be sent.'
24
- },
25
- {
26
- queue: documentsQueue,
27
- prefix: 'Document Queue - ',
28
- description: '(Deprecated) This queue was used for indexing email information in the Document Store'
29
24
  }
30
25
  ];
31
26
  let queueAdapters = queues.map(queue => {
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
- const { Export } = require('../export');
3
+ const { Export, openExportReadStream } = require('../export');
5
4
  const Boom = require('@hapi/boom');
6
5
  const Joi = require('joi');
7
6
  const { failAction } = require('../tools');
8
7
  const { accountIdSchema, exportRequestSchema, exportStatusSchema, exportListSchema, exportIdSchema, apiResponses } = require('../schemas');
9
- const getSecret = require('../get-secret');
10
- const { createDecryptStream } = require('../stream-encrypt');
11
8
  const { handleError } = require('./route-helpers');
12
9
  const BEHAVIOR = require('./behavior-notes');
13
10
  const { IMPACT } = require('./operation-impact');
@@ -144,27 +141,10 @@ async function init(args) {
144
141
  throw Boom.notFound('Export not found');
145
142
  }
146
143
 
147
- const fileReadStream = fs.createReadStream(fileInfo.filePath);
148
- let stream = fileReadStream;
149
-
150
- stream.on('error', err => {
144
+ const stream = await openExportReadStream(fileInfo, err => {
151
145
  request.logger.error({ msg: 'Export download stream error', exportId, err });
152
146
  });
153
147
 
154
- if (fileInfo.isEncrypted) {
155
- const secret = await getSecret();
156
- if (!secret) {
157
- fileReadStream.destroy();
158
- throw Boom.serverUnavailable('Encryption secret not available for decryption');
159
- }
160
- const decryptStream = await createDecryptStream(secret);
161
- decryptStream.on('error', err => {
162
- request.logger.error({ msg: 'Export decryption error', exportId, err });
163
- fileReadStream.destroy();
164
- });
165
- stream = fileReadStream.pipe(decryptStream);
166
- }
167
-
168
148
  return h
169
149
  .response(stream)
170
150
  .type('application/gzip')
@@ -6,7 +6,7 @@ const { Gateway } = require('../gateway');
6
6
  const getSecret = require('../get-secret');
7
7
  const { failAction } = require('../tools');
8
8
  const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
9
- const { apiResponses } = require('../schemas');
9
+ const { apiResponses, apiBoolean, formBoolean } = require('../schemas');
10
10
  const { ENUM_DESCRIPTIONS } = require('../enum-descriptions');
11
11
  const { IMPACT } = require('./operation-impact');
12
12
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
@@ -229,9 +229,7 @@ async function init(args) {
229
229
  .description('Service port number')
230
230
  .label('Port'),
231
231
 
232
- secure: Joi.boolean()
233
- .truthy('Y', 'true', '1', 'on')
234
- .falsy('N', 'false', 0, '')
232
+ secure: formBoolean()
235
233
  .allow(null)
236
234
  .default(false)
237
235
  .example(true)
@@ -316,9 +314,7 @@ async function init(args) {
316
314
  .label('Port')
317
315
  .required(),
318
316
 
319
- secure: Joi.boolean()
320
- .truthy('Y', 'true', '1', 'on')
321
- .falsy('N', 'false', 0, '')
317
+ secure: formBoolean()
322
318
  .default(false)
323
319
  .example(true)
324
320
  .description('Should connection use TLS. Usually true for port 465')
@@ -413,12 +409,7 @@ async function init(args) {
413
409
  .description('Service port number')
414
410
  .label('Port'),
415
411
 
416
- secure: Joi.boolean()
417
- .truthy('Y', 'true', '1', 'on')
418
- .falsy('N', 'false', 0, '')
419
- .example(true)
420
- .description('Should connection use TLS. Usually true for port 465')
421
- .label('GatewayUpdateTlsOptions')
412
+ secure: formBoolean().example(true).description('Should connection use TLS. Usually true for port 465').label('GatewayUpdateTlsOptions')
422
413
  }).label('UpdateGateway')
423
414
  },
424
415
 
@@ -487,7 +478,7 @@ async function init(args) {
487
478
  response: {
488
479
  schema: Joi.object({
489
480
  gateway: Joi.string().max(256).required().example('example').description('Gateway ID'),
490
- deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the gateway deleted')
481
+ deleted: apiBoolean().default(true).description('Was the gateway deleted')
491
482
  }).label('DeleteGatewayResponse'),
492
483
  failAction: 'log'
493
484
  }
@@ -13,7 +13,6 @@
13
13
  // them the same bag hides which module depends on what, and hides it from the route-table test too.
14
14
 
15
15
  const templateRoutes = require('./template-routes');
16
- const chatRoutes = require('./chat-routes');
17
16
  const accountRoutes = require('./account-routes');
18
17
  const messageRoutes = require('./message-routes');
19
18
  const exportRoutes = require('./export-routes');
@@ -41,7 +40,6 @@ const mcpOauthRoutes = require('./mcp-oauth-routes');
41
40
  * @param {Object} args.server - Hapi server (or a route-recording mock)
42
41
  * @param {Function} args.call - RPC helper for talking to the main thread
43
42
  * @param {Object} args.notify - notify (webhooks) BullMQ queue
44
- * @param {Object} args.documentsQueue - documents BullMQ queue
45
43
  * @param {Object} args.metrics - Prometheus metrics registry
46
44
  * @param {Object|Boolean} args.CORS_CONFIG
47
45
  * @param {Array} args.FLAG_SORT_ORDER
@@ -49,7 +47,6 @@ const mcpOauthRoutes = require('./mcp-oauth-routes');
49
47
  * @param {Number} args.MAX_ATTACHMENT_SIZE
50
48
  * @param {Number} args.MAX_BODY_SIZE
51
49
  * @param {Number} args.MAX_PAYLOAD_TIMEOUT
52
- * @param {Boolean} args.documentStoreFeatureEnabled - gate for the deprecated Document Store
53
50
  * @param {Boolean} args.mcpFeatureEnabled - gate for the MCP endpoint
54
51
  * @param {Object} args.oauth2Schema
55
52
  * @param {Object} args.imapSchema
@@ -62,7 +59,6 @@ async function registerApiRoutes(args) {
62
59
  server,
63
60
  call,
64
61
  notify,
65
- documentsQueue,
66
62
  metrics,
67
63
  CORS_CONFIG,
68
64
  FLAG_SORT_ORDER,
@@ -70,7 +66,6 @@ async function registerApiRoutes(args) {
70
66
  MAX_ATTACHMENT_SIZE,
71
67
  MAX_BODY_SIZE,
72
68
  MAX_PAYLOAD_TIMEOUT,
73
- documentStoreFeatureEnabled,
74
69
  mcpFeatureEnabled,
75
70
  oauth2Schema,
76
71
  imapSchema,
@@ -82,16 +77,10 @@ async function registerApiRoutes(args) {
82
77
  // setup template routes
83
78
  await templateRoutes({ server, call, CORS_CONFIG });
84
79
 
85
- // setup "chat with email" routes (deprecated Document Store feature; only when enabled)
86
- if (documentStoreFeatureEnabled) {
87
- await chatRoutes({ server, call, CORS_CONFIG });
88
- }
89
-
90
80
  // setup account CRUD routes
91
81
  await accountRoutes({
92
82
  server,
93
83
  call,
94
- documentsQueue,
95
84
  oauth2Schema,
96
85
  imapSchema,
97
86
  smtpSchema,
@@ -108,8 +97,7 @@ async function registerApiRoutes(args) {
108
97
  CORS_CONFIG,
109
98
  MAX_ATTACHMENT_SIZE,
110
99
  MAX_BODY_SIZE,
111
- MAX_PAYLOAD_TIMEOUT,
112
- documentStoreFeatureEnabled
100
+ MAX_PAYLOAD_TIMEOUT
113
101
  });
114
102
 
115
103
  // setup export routes
@@ -7,7 +7,7 @@ const { Account } = require('../account');
7
7
  const getSecret = require('../get-secret');
8
8
  const { failAction } = require('../tools');
9
9
  const { handleError, logApiError } = require('./route-helpers');
10
- const { accountIdSchema, mailboxesSchema, apiResponses } = require('../schemas');
10
+ const { accountIdSchema, mailboxesSchema, apiResponses, apiBoolean } = require('../schemas');
11
11
  const { IMPACT } = require('./operation-impact');
12
12
  const { FIELD_USAGE } = require('../field-usage');
13
13
 
@@ -118,12 +118,7 @@ async function init(args) {
118
118
  }),
119
119
 
120
120
  query: Joi.object({
121
- counters: Joi.boolean()
122
- .truthy('Y', 'true', '1')
123
- .falsy('N', 'false', 0)
124
- .default(false)
125
- .description('If true, then includes message counters in the response')
126
- .label('MailboxCounters')
121
+ counters: apiBoolean().default(false).description('If true, then includes message counters in the response').label('MailboxCounters')
127
122
  }).label('MailboxListQuery')
128
123
  },
129
124
 
@@ -160,7 +160,8 @@ async function init(args) {
160
160
  return h.response(client).code(201);
161
161
  } catch (err) {
162
162
  if (err.oauthError) {
163
- return oauthErrorResponse(h, 400, err.oauthError, err.message);
163
+ // 503 for the instance-wide cap on registrations waiting for consent
164
+ return oauthErrorResponse(h, err.statusCode || 400, err.oauthError, err.message);
164
165
  }
165
166
  throw err;
166
167
  }
@@ -23,7 +23,7 @@ const { isMcpEnabled, MCP_DISABLED_MESSAGE } = require('../mcp');
23
23
  const { processMcpRequest, isAllowedOrigin, acceptsEventStream, rpcError, ERROR_CODES, serverInstructions } = require('../mcp/protocol');
24
24
  const { getToolRegistry, callTool, listToolsFor, catalogSurfaces } = require('../mcp/tools');
25
25
  const { listResources, readResource } = require('../mcp/resources');
26
- const { acceptFilter, openListenStream, canOpenListenStream, MAX_STREAMS_PER_CREDENTIAL } = require('../mcp/listen');
26
+ const { handleListen, MAX_STREAMS_PER_CREDENTIAL } = require('../mcp/listen');
27
27
 
28
28
  async function init(args) {
29
29
  const { server, CORS_CONFIG, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
@@ -111,9 +111,11 @@ async function init(args) {
111
111
  const outcome = await processMcpRequest({ body: request.payload, headers: request.headers, ctx });
112
112
 
113
113
  if (outcome.listen) {
114
- // Checked before the authorization fan-out below, so a client that is already at
115
- // its stream budget cannot spend the instance's Redis round trips discovering it
116
- if (!canOpenListenStream(request)) {
114
+ // The stream cap is checked, and a slot reserved, before the authorization fan-out,
115
+ // so a client that is already at its stream budget cannot spend the instance's
116
+ // Redis round trips discovering it, concurrent requests included
117
+ const response = await handleListen({ h, server, request, subscriptionId: outcome.listen.id, filter: outcome.listen.filter });
118
+ if (!response) {
117
119
  return h.response(
118
120
  rpcError(
119
121
  outcome.listen.id,
@@ -122,9 +124,7 @@ async function init(args) {
122
124
  )
123
125
  );
124
126
  }
125
-
126
- const accepted = await acceptFilter({ server, request, filter: outcome.listen.filter });
127
- return openListenStream({ h, request, subscriptionId: outcome.listen.id, accepted });
127
+ return response;
128
128
  }
129
129
 
130
130
  if (!outcome.body) {