emailengine-app 2.81.2 → 2.82.1

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 (226) hide show
  1. package/.ncurc.js +33 -10
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +71 -0
  4. package/DOCKER_DEPLOYMENT.md +13 -12
  5. package/Dockerfile +2 -0
  6. package/bin/emailengine.js +105 -25
  7. package/config/default.toml +0 -5
  8. package/config/test.toml +0 -5
  9. package/data/google-crawlers.json +1 -1
  10. package/encrypt.js +70 -42
  11. package/getswagger.sh +0 -4
  12. package/lib/account/account-state.js +2 -110
  13. package/lib/account/expected-identity.js +1 -1
  14. package/lib/account-assignment.js +138 -1
  15. package/lib/account.js +289 -869
  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-binding.js +58 -0
  19. package/lib/api-routes/account-routes.js +65 -37
  20. package/lib/api-routes/behavior-notes.js +4 -0
  21. package/lib/api-routes/blocklist-routes.js +2 -2
  22. package/lib/api-routes/bull-board-routes.js +1 -6
  23. package/lib/api-routes/export-routes.js +2 -22
  24. package/lib/api-routes/gateway-routes.js +15 -16
  25. package/lib/api-routes/index.js +1 -13
  26. package/lib/api-routes/mailbox-routes.js +2 -7
  27. package/lib/api-routes/mcp-oauth-routes.js +2 -1
  28. package/lib/api-routes/mcp-routes.js +7 -7
  29. package/lib/api-routes/message-routes.js +50 -238
  30. package/lib/api-routes/mint-bounds.js +110 -0
  31. package/lib/api-routes/oauth2-app-routes.js +23 -32
  32. package/lib/api-routes/operation-impact.js +1 -1
  33. package/lib/api-routes/outbox-routes.js +3 -3
  34. package/lib/api-routes/permission-map.js +1 -7
  35. package/lib/api-routes/route-helpers.js +11 -5
  36. package/lib/api-routes/settings-routes.js +20 -21
  37. package/lib/api-routes/stats-routes.js +1 -1
  38. package/lib/api-routes/submit-routes.js +17 -18
  39. package/lib/api-routes/template-routes.js +4 -9
  40. package/lib/api-routes/token-routes.js +28 -6
  41. package/lib/api-token-scheme.js +71 -0
  42. package/lib/arf-detect.js +33 -6
  43. package/lib/auth-token.js +44 -24
  44. package/lib/autodetect-imap-settings.js +305 -123
  45. package/lib/bounce-detect.js +25 -16
  46. package/lib/calendar-event.js +78 -0
  47. package/lib/consts.js +54 -5
  48. package/lib/create-imap-client.js +24 -0
  49. package/lib/db.js +77 -30
  50. package/lib/delivery-error.js +70 -2
  51. package/lib/egress-fetch.js +54 -3
  52. package/lib/egress-filter.js +11 -0
  53. package/lib/email-client/api-retry.js +147 -0
  54. package/lib/email-client/base-client.js +383 -536
  55. package/lib/email-client/credential-errors.js +21 -5
  56. package/lib/email-client/gmail/gmail-api.js +38 -125
  57. package/lib/email-client/gmail/send-request.js +1 -1
  58. package/lib/email-client/gmail-client.js +77 -51
  59. package/lib/email-client/imap/mailbox.js +158 -324
  60. package/lib/email-client/imap/stale-view.js +109 -0
  61. package/lib/email-client/imap/subconnection.js +46 -9
  62. package/lib/email-client/imap/sync-operations.js +5 -37
  63. package/lib/email-client/imap-client.js +190 -65
  64. package/lib/email-client/message-builder.js +50 -25
  65. package/lib/email-client/notification-handler.js +5 -219
  66. package/lib/email-client/outlook/graph-api.js +147 -126
  67. package/lib/email-client/outlook/send-request.js +10 -4
  68. package/lib/email-client/outlook-client.js +389 -463
  69. package/lib/email-client/smtp-pool-manager.js +3 -2
  70. package/lib/encrypt.js +184 -19
  71. package/lib/enum-descriptions.js +6 -3
  72. package/lib/export.js +141 -41
  73. package/lib/gateway.js +25 -6
  74. package/lib/get-raw-email.js +26 -44
  75. package/lib/get-secret.js +1 -21
  76. package/lib/handlebars-helpers.js +31 -10
  77. package/lib/imap-proxy-auth.js +13 -29
  78. package/lib/imapproxy/imap-core/README.md +1 -0
  79. package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
  80. package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
  81. package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
  82. package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
  83. package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
  84. package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
  85. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
  86. package/lib/imapproxy/imap-server.js +17 -177
  87. package/lib/imapproxy/proxy-handoff.js +235 -0
  88. package/lib/imapproxy/response-error.js +33 -0
  89. package/lib/imapproxy/upstream-client.js +2 -2
  90. package/lib/license-beacon.js +3 -9
  91. package/lib/llm-pre-process.js +182 -43
  92. package/lib/logger.js +1 -1
  93. package/lib/lua/ee-export-queue-add.lua +39 -0
  94. package/lib/lua/ee-get-idempotency.lua +15 -3
  95. package/lib/lua/ee-release-attempts.lua +23 -0
  96. package/lib/lua/ee-reserve-attempts.lua +42 -0
  97. package/lib/lua/h-set-bigger.lua +12 -2
  98. package/lib/lua/s-list-accounts.lua +6 -3
  99. package/lib/mcp/index.js +1 -2
  100. package/lib/mcp/listen.js +221 -18
  101. package/lib/mcp/oauth.js +44 -5
  102. package/lib/mcp/resources.js +8 -2
  103. package/lib/mcp/tools.js +108 -36
  104. package/lib/message-port-stream.js +64 -6
  105. package/lib/oauth/external-account-signer.js +16 -13
  106. package/lib/oauth/gmail.js +64 -32
  107. package/lib/oauth/mail-ru.js +24 -17
  108. package/lib/oauth/outlook.js +53 -40
  109. package/lib/oauth/pubsub/google.js +38 -2
  110. package/lib/oauth/scope-checker.js +39 -8
  111. package/lib/oauth/scope-list.js +55 -0
  112. package/lib/oauth/token-fetch.js +47 -0
  113. package/lib/oauth/verify-app.js +2 -2
  114. package/lib/oauth2-apps.js +154 -90
  115. package/lib/openapi/build-document.js +1 -1
  116. package/lib/openapi/joi-schema.js +78 -9
  117. package/lib/outbox.js +2 -7
  118. package/lib/parse-message.js +21 -0
  119. package/lib/payload-examples-webhooks.json +4 -7
  120. package/lib/pbkdf2-phc.js +101 -0
  121. package/lib/privileged-settings.js +0 -14
  122. package/lib/queue-retention.js +4 -2
  123. package/lib/rate-limit.js +54 -15
  124. package/lib/read-env-value.js +33 -2
  125. package/lib/redis-scan-delete.js +56 -29
  126. package/lib/redis-url.js +3 -1
  127. package/lib/respawn-backoff.js +5 -4
  128. package/lib/response-stream.js +25 -4
  129. package/lib/rewrite-text-nodes.js +27 -40
  130. package/lib/routes-ui.js +0 -5
  131. package/lib/schemas.js +180 -253
  132. package/lib/sentry.js +21 -5
  133. package/lib/settings.js +58 -59
  134. package/lib/smtp-auth.js +6 -2
  135. package/lib/smtp-message-processor.js +28 -7
  136. package/lib/sso.js +7 -3
  137. package/lib/stream-encrypt.js +14 -13
  138. package/lib/swagger-options.js +3 -1
  139. package/lib/tls/provision.js +69 -3
  140. package/lib/tls/store.js +14 -1
  141. package/lib/token-audit-log.js +3 -2
  142. package/lib/tools.js +114 -53
  143. package/lib/totp.js +16 -1
  144. package/lib/ui-routes/account-routes.js +67 -70
  145. package/lib/ui-routes/admin-config-routes.js +111 -134
  146. package/lib/ui-routes/admin-entities-routes.js +101 -191
  147. package/lib/ui-routes/ai-options.js +104 -0
  148. package/lib/ui-routes/auth-routes.js +98 -18
  149. package/lib/ui-routes/export-routes.js +3 -23
  150. package/lib/ui-routes/internals-routes.js +12 -9
  151. package/lib/ui-routes/network-config-routes.js +8 -18
  152. package/lib/ui-routes/oauth-config-routes.js +83 -228
  153. package/lib/ui-routes/route-helpers.js +63 -67
  154. package/lib/ui-routes/special-use-paths.js +33 -0
  155. package/lib/ui-routes/unsubscribe-routes.js +2 -2
  156. package/lib/utils/decode-headers.js +32 -5
  157. package/lib/utils/header-map.js +62 -1
  158. package/lib/utils/network.js +11 -17
  159. package/lib/web-safe-html.js +77 -4
  160. package/lib/webhook-request.js +9 -1
  161. package/lib/webhook-routing.js +27 -1
  162. package/lib/webhooks.js +120 -43
  163. package/lib/worker-rpc-error.js +43 -2
  164. package/list-generate.js +13 -2
  165. package/package.json +38 -46
  166. package/sbom.json +1 -1
  167. package/scripts/refresh-test-tokens.js +42 -14
  168. package/server.js +338 -292
  169. package/setup-production.sh +16 -7
  170. package/static/css/flyonui.css +1 -1
  171. package/static/css/src/app.tailwind.css +7 -8
  172. package/static/js/ee-client.js +145 -70
  173. package/static/js/ui.js +350 -154
  174. package/static/licenses.html +349 -1740
  175. package/translations/messages.pot +129 -111
  176. package/views/account-workspace-error.hbs +30 -0
  177. package/views/accounts/account.hbs +9 -4
  178. package/views/accounts/browse.hbs +10 -4
  179. package/views/accounts/edit.hbs +11 -2
  180. package/views/config/ai.hbs +49 -41
  181. package/views/config/oauth/app.hbs +2 -1
  182. package/views/dashboard.hbs +18 -16
  183. package/views/internals/index.hbs +1 -1
  184. package/views/layout/app.hbs +0 -22
  185. package/views/layout/login.hbs +2 -1
  186. package/views/partials/filter_editor_js.hbs +4 -3
  187. package/views/partials/gmail_api_scopes.hbs +16 -0
  188. package/views/partials/oauth_form.hbs +67 -94
  189. package/views/partials/oauth_pubsub_app_select.hbs +43 -0
  190. package/views/partials/scope_info.hbs +14 -23
  191. package/views/partials/side_menu.hbs +0 -4
  192. package/views/partials/ui/account-picker.hbs +6 -32
  193. package/views/partials/ui/model-picker.hbs +31 -0
  194. package/views/partials/ui/pagination.hbs +6 -1
  195. package/views/partials/ui/picker.hbs +47 -0
  196. package/views/unsubscribe.hbs +1 -1
  197. package/workers/api.js +82 -47
  198. package/workers/export.js +55 -60
  199. package/workers/imap.js +132 -49
  200. package/workers/submit.js +5 -6
  201. package/workers/webhooks.js +46 -27
  202. package/.githooks/pre-commit +0 -80
  203. package/.github/CODE_OF_CONDUCT.md +0 -76
  204. package/.github/contributing.md +0 -17
  205. package/.github/dependabot.yml +0 -22
  206. package/.github/docker-smoke-test.sh +0 -61
  207. package/.github/workflows/deploy.yml +0 -215
  208. package/.github/workflows/e2e.yml +0 -55
  209. package/.github/workflows/release.yaml +0 -217
  210. package/.github/workflows/test.yml +0 -307
  211. package/lib/api-routes/chat-routes.js +0 -535
  212. package/lib/document-store.js +0 -75
  213. package/lib/es.js +0 -757
  214. package/lib/generate-text-preview.js +0 -61
  215. package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
  216. package/lib/pre-process.js +0 -196
  217. package/lib/threads.js +0 -155
  218. package/lib/ui-routes/document-store-routes.js +0 -806
  219. package/playwright.config.js +0 -47
  220. package/views/config/document-store/chat.hbs +0 -286
  221. package/views/config/document-store/index.hbs +0 -146
  222. package/views/config/document-store/mappings/index.hbs +0 -108
  223. package/views/config/document-store/mappings/new.hbs +0 -68
  224. package/views/config/document-store/pre-processing/index.hbs +0 -103
  225. package/views/partials/document_store_header.hbs +0 -30
  226. package/workers/documents.js +0 -1128
@@ -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) {
@@ -3,7 +3,6 @@
3
3
  const { redis } = require('../db');
4
4
  const { Account } = require('../account');
5
5
  const getSecret = require('../get-secret');
6
- const settings = require('../settings');
7
6
  const Joi = require('joi');
8
7
  const { failAction } = require('../tools');
9
8
  const { handleError } = require('./route-helpers');
@@ -42,9 +41,7 @@ const {
42
41
  messageIdSchema,
43
42
  messageDetailsSchema,
44
43
  messageListSchema,
45
- messageEntrySchema,
46
44
  documentStoreSchema,
47
- documentStoreQuerySchema,
48
45
  searchSchema,
49
46
  messageUpdateSchema,
50
47
  addressSchema,
@@ -53,7 +50,9 @@ const {
53
50
  emailIdSchema,
54
51
  threadIdSchema,
55
52
  apiResponses,
56
- ENUM_DESCRIPTIONS
53
+ ENUM_DESCRIPTIONS,
54
+ MAX_MESSAGE_ATTACHMENTS,
55
+ apiBoolean
57
56
  } = require('../schemas');
58
57
 
59
58
  const listMessageFolderPathDescription =
@@ -69,6 +68,18 @@ const UPDATE_OP_ENTRY_EXAMPLE = {
69
68
 
70
69
  // Response field for a flag or label update operation. IMAP accounts return a boolean (whether
71
70
  // the operation succeeded), API-based accounts echo the requested values as an array.
71
+ // The `failed` member of a bulk response: the messages the server refused after retries. The
72
+ // labels are public type names in the OpenAPI document, so the prefix is the operation's.
73
+ const bulkFailedSchema = prefix =>
74
+ Joi.object({
75
+ emailIds: Joi.array()
76
+ .items(emailIdSchema)
77
+ .description('List of emailId values the server refused after retries (MS Graph API accounts only)')
78
+ .label(`${prefix}FailedEmailIds`)
79
+ })
80
+ .label(`${prefix}Failed`)
81
+ .description('Present when some messages could not be processed (MS Graph API accounts only)');
82
+
72
83
  const updateOpResultSchema = (op, noun, entryLabel, example, label) =>
73
84
  Joi.alternatives()
74
85
  .try(Joi.boolean(), Joi.array().items(Joi.string().label(entryLabel).example(UPDATE_OP_ENTRY_EXAMPLE[noun])))
@@ -85,7 +96,7 @@ const idMapSchema = Joi.array()
85
96
  .label('IdMapArray');
86
97
 
87
98
  async function init(args) {
88
- const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT, documentStoreFeatureEnabled } = args;
99
+ const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
89
100
 
90
101
  // GET /v1/account/{account}/message/{message}/source - Download raw message
91
102
  server.route({
@@ -147,13 +158,12 @@ async function init(args) {
147
158
  method: 'GET',
148
159
  path: '/v1/account/{account}/message/{message}',
149
160
 
150
- async handler(request, h) {
161
+ async handler(request) {
151
162
  let accountObject = new Account({
152
163
  redis,
153
164
  account: request.params.account,
154
165
  call,
155
166
  secret: await getSecret(),
156
- esClient: await h.getESClient(request.logger),
157
167
  timeout: request.headers['x-ee-timeout']
158
168
  });
159
169
 
@@ -231,9 +241,7 @@ async function init(args) {
231
241
  .description('Which text content to return, use * for all. By default text content is not returned.')
232
242
  .label('MessageTextType'),
233
243
 
234
- webSafeHtml: Joi.boolean()
235
- .truthy('Y', 'true', '1')
236
- .falsy('N', 'false', 0)
244
+ webSafeHtml: apiBoolean()
237
245
  .default(false)
238
246
  .description('Shorthand option to fetch and preprocess HTML and inline images')
239
247
  .meta({ usage: FIELD_USAGE.webSafeHtml })
@@ -243,28 +251,19 @@ async function init(args) {
243
251
  // for" from an explicit false, because an explicit false is what overrides
244
252
  // the webSafeHtml shorthand. It resolves the tri-state to a boolean, so no
245
253
  // consumer downstream sees the undefined.
246
- embedAttachedImages: Joi.boolean()
247
- .truthy('Y', 'true', '1')
248
- .falsy('N', 'false', 0)
254
+ embedAttachedImages: apiBoolean()
249
255
  .description('If true, then fetches attached images and embeds these in the HTML as data URIs. Not set means false')
250
256
  .meta({ usage: FIELD_USAGE.embedAttachedImages })
251
257
  .label('EmbedImages'),
252
258
 
253
- preProcessHtml: Joi.boolean()
254
- .truthy('Y', 'true', '1')
255
- .falsy('N', 'false', 0)
256
- .default(false)
257
- .description('If true, then pre-processes HTML for compatibility')
258
- .label('PreProcess'),
259
+ preProcessHtml: apiBoolean().default(false).description('If true, then pre-processes HTML for compatibility').label('PreProcess'),
259
260
 
260
- markAsSeen: Joi.boolean()
261
- .truthy('Y', 'true', '1')
262
- .falsy('N', 'false', 0)
261
+ markAsSeen: apiBoolean()
263
262
  .default(false)
264
263
  .description('If true, then marks unseen email as seen while returning the message')
265
264
  .label('MarkAsSeen'),
266
265
 
267
- documentStore: documentStoreSchema.default(false)
266
+ documentStore: documentStoreSchema
268
267
  }),
269
268
 
270
269
  params: Joi.object({
@@ -307,7 +306,11 @@ async function init(args) {
307
306
  },
308
307
 
309
308
  description: 'Upload message',
310
- notes: ['Upload a message structure, compile it into an EML file and store it into selected mailbox.', BEHAVIOR.UPLOAD_DRAFTS_ONLY_GRAPH],
309
+ notes: [
310
+ 'Upload a message structure, compile it into an EML file and store it into selected mailbox.',
311
+ BEHAVIOR.UPLOAD_DRAFTS_ONLY_GRAPH,
312
+ BEHAVIOR.UPLOAD_IGNORES_FLAGS_GMAIL
313
+ ],
311
314
  tags: ['api', 'Message'],
312
315
 
313
316
  plugins: {
@@ -327,7 +330,7 @@ async function init(args) {
327
330
  keep: ['account', 'path', 'flags', 'reference', 'from', 'to', 'cc', 'bcc', 'subject', 'text', 'html', 'attachments']
328
331
  },
329
332
  openapi: {
330
- 'x-ee-behavior': [BEHAVIOR.UPLOAD_DRAFTS_ONLY_GRAPH],
333
+ 'x-ee-behavior': [BEHAVIOR.UPLOAD_DRAFTS_ONLY_GRAPH, BEHAVIOR.UPLOAD_IGNORES_FLAGS_GMAIL],
331
334
  responses: apiResponses('Returns the uploaded message with the identifiers the provider assigned to it.', 400, 401, 403, 404, 429, 500, 503)
332
335
  }
333
336
  },
@@ -424,6 +427,7 @@ async function init(args) {
424
427
  .label('MsgUploadReference')
425
428
  }).label('UploadAttachment')
426
429
  )
430
+ .max(MAX_MESSAGE_ATTACHMENTS)
427
431
  .description('List of attachments')
428
432
  .label('UploadAttachmentList'),
429
433
 
@@ -462,7 +466,6 @@ async function init(args) {
462
466
  .description('Referenced message ID. Not present when only a thread ID was referenced'),
463
467
  threadId: threadIdSchema.description('Referenced thread ID (Gmail API accounts only)').label('ResponseReferenceThreadId'),
464
468
  success: Joi.boolean().example(true).description('Was the referenced message processed').label('ResponseReferenceSuccess'),
465
- documentStore: documentStoreSchema.default(false),
466
469
  error: Joi.string().example('Referenced message was not found').description('An error message if referenced message processing failed')
467
470
  })
468
471
  .description('Reference info if referencing was requested')
@@ -630,6 +633,7 @@ async function init(args) {
630
633
  delete: updateOpResultSchema('delete', 'labels', 'BulkLabelEntry', ['Label3'], 'BulkLabelDeleteResult'),
631
634
  set: updateOpResultSchema('set', 'labels', 'BulkLabelEntry', ['Label1'], 'BulkLabelSetResult')
632
635
  }).label('BulkLabelUpdateResponse'),
636
+ failed: bulkFailedSchema('BulkUpdate'),
633
637
  emailIds: Joi.array()
634
638
  .items(emailIdSchema)
635
639
  .description('List of updated email IDs (Gmail API and MS Graph API accounts only)')
@@ -794,7 +798,8 @@ async function init(args) {
794
798
  .description(
795
799
  'An optional list of emailId values, if the server supports unique email IDs (Gmail API and MS Graph API accounts only). Null when no messages matched the search (Gmail API)'
796
800
  )
797
- .label('MovedEmailIdsArray')
801
+ .label('MovedEmailIdsArray'),
802
+ failed: bulkFailedSchema('BulkMove')
798
803
  }).label('MessagesMoveResponse'),
799
804
  failAction: 'log'
800
805
  }
@@ -854,9 +859,7 @@ async function init(args) {
854
859
  failAction,
855
860
 
856
861
  query: Joi.object({
857
- force: Joi.boolean()
858
- .truthy('Y', 'true', '1')
859
- .falsy('N', 'false', 0)
862
+ force: apiBoolean()
860
863
  .default(false)
861
864
  .description('Delete message even if not in Trash. Not supported for Gmail API accounts.')
862
865
  .label('ForceDelete')
@@ -945,9 +948,7 @@ async function init(args) {
945
948
 
946
949
  query: Joi.object({
947
950
  path: Joi.string().empty('').required().example('INBOX').description(listMessageFolderPathDescription),
948
- force: Joi.boolean()
949
- .truthy('Y', 'true', '1')
950
- .falsy('N', 'false', 0)
951
+ force: apiBoolean()
951
952
  .default(false)
952
953
  .description('Delete messages even if not in Trash. Not supported for Gmail API accounts (messages are always moved to Trash)')
953
954
  .label('ForceDelete')
@@ -986,7 +987,8 @@ async function init(args) {
986
987
  .label('DeletedEmailIdsArray')
987
988
  })
988
989
  .label('MessagesDeleted')
989
- .description('Value is present if messages were deleted permanently (MS Graph API accounts only)')
990
+ .description('Value is present if messages were deleted permanently (MS Graph API accounts only)'),
991
+ failed: bulkFailedSchema('BulkDelete')
990
992
  }).label('MessagesDeleteResponse'),
991
993
  failAction: 'log'
992
994
  }
@@ -998,13 +1000,12 @@ async function init(args) {
998
1000
  method: 'GET',
999
1001
  path: '/v1/account/{account}/messages',
1000
1002
 
1001
- async handler(request, h) {
1003
+ async handler(request) {
1002
1004
  let accountObject = new Account({
1003
1005
  redis,
1004
1006
  account: request.params.account,
1005
1007
  call,
1006
1008
  secret: await getSecret(),
1007
- esClient: await h.getESClient(request.logger),
1008
1009
  timeout: request.headers['x-ee-timeout']
1009
1010
  });
1010
1011
 
@@ -1070,7 +1071,7 @@ async function init(args) {
1070
1071
  .label('PageNumber'),
1071
1072
 
1072
1073
  pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize'),
1073
- documentStore: documentStoreSchema.default(false)
1074
+ documentStore: documentStoreSchema
1074
1075
  }).label('MessageQuery')
1075
1076
  },
1076
1077
 
@@ -1086,38 +1087,15 @@ async function init(args) {
1086
1087
  method: 'POST',
1087
1088
  path: '/v1/account/{account}/search',
1088
1089
 
1089
- async handler(request, h) {
1090
+ async handler(request) {
1090
1091
  let accountObject = new Account({
1091
1092
  redis,
1092
1093
  account: request.params.account,
1093
1094
  call,
1094
1095
  secret: await getSecret(),
1095
- esClient: await h.getESClient(request.logger),
1096
1096
  timeout: request.headers['x-ee-timeout']
1097
1097
  });
1098
1098
 
1099
- let extraValidationErrors = [];
1100
-
1101
- if (request.query.documentStore) {
1102
- for (let key of ['seq', 'modseq']) {
1103
- if (request.payload.search && key in request.payload.search) {
1104
- extraValidationErrors.push({ message: 'Not available when using Document Store', context: { key } });
1105
- }
1106
- }
1107
- } else {
1108
- for (let key of ['documentQuery']) {
1109
- if (key in request.payload) {
1110
- extraValidationErrors.push({ message: 'Requires Document Store to be enabled', context: { key } });
1111
- }
1112
- }
1113
- }
1114
-
1115
- if (extraValidationErrors.length) {
1116
- let error = new Error('Input validation failed');
1117
- error.details = extraValidationErrors;
1118
- return failAction(request, h, error);
1119
- }
1120
-
1121
1099
  try {
1122
1100
  return await accountObject.searchMessages(Object.assign(request.query, request.payload));
1123
1101
  } catch (err) {
@@ -1162,15 +1140,7 @@ async function init(args) {
1162
1140
  }),
1163
1141
 
1164
1142
  query: Joi.object({
1165
- path: Joi.string()
1166
- .when('documentStore', {
1167
- is: true,
1168
- then: Joi.optional(),
1169
- otherwise: Joi.required()
1170
- })
1171
- .example('INBOX')
1172
- .description(listMessageFolderPathDescription)
1173
- .label('Path'),
1143
+ path: Joi.string().required().example('INBOX').description(listMessageFolderPathDescription).label('Path'),
1174
1144
 
1175
1145
  cursor: Joi.string()
1176
1146
  .trim()
@@ -1191,36 +1161,17 @@ async function init(args) {
1191
1161
 
1192
1162
  pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page'),
1193
1163
 
1194
- useOutlookSearch: Joi.boolean()
1195
- .truthy('Y', 'true', '1')
1196
- .falsy('N', 'false', 0)
1164
+ useOutlookSearch: apiBoolean()
1197
1165
  .description('MS Graph only. Use the $search parameter for search queries instead of $filter')
1198
1166
  .meta({ usage: FIELD_USAGE.useOutlookSearch })
1199
1167
  .label('useOutlookSearch')
1200
1168
  .optional(),
1201
1169
 
1202
- documentStore: documentStoreSchema.default(false).meta({ swaggerHidden: true }),
1203
- exposeQuery: Joi.boolean()
1204
- .truthy('Y', 'true', '1')
1205
- .falsy('N', 'false', 0)
1206
- .description('If enabled then includes the combined query (as the documentStoreQuery field) in the response for debugging')
1207
- .label('exposeQuery')
1208
- .when('documentStore', {
1209
- is: true,
1210
- then: Joi.optional(),
1211
- otherwise: Joi.forbidden()
1212
- })
1213
- .meta({ swaggerHidden: true })
1170
+ documentStore: documentStoreSchema
1214
1171
  }),
1215
1172
 
1216
1173
  payload: Joi.object({
1217
- search: searchSchema,
1218
- documentQuery: Joi.object()
1219
- .min(1)
1220
- .description('Document Store query. Only allowed with `documentStore`.')
1221
- .label('DocumentQuery')
1222
- .unknown()
1223
- .meta({ swaggerHidden: true })
1174
+ search: searchSchema
1224
1175
  })
1225
1176
  .label('MessageSearchPayload')
1226
1177
  .example({
@@ -1253,157 +1204,17 @@ async function init(args) {
1253
1204
  }
1254
1205
  });
1255
1206
 
1256
- // POST /v1/unified/search - Unified search for messages
1257
- // Deprecated Document Store feature: only register this endpoint when the feature is enabled,
1258
- // otherwise it behaves like a regular 404.
1259
- if (documentStoreFeatureEnabled) {
1260
- server.route({
1261
- method: 'POST',
1262
- path: '/v1/unified/search',
1263
-
1264
- async handler(request, h) {
1265
- let accountObject = new Account({
1266
- redis,
1267
- call,
1268
- secret: await getSecret(),
1269
- esClient: await h.getESClient(request.logger),
1270
- timeout: request.headers['x-ee-timeout']
1271
- });
1272
-
1273
- let extraValidationErrors = [];
1274
-
1275
- for (let key of ['seq', 'modseq']) {
1276
- if (request.payload.search && key in request.payload.search) {
1277
- extraValidationErrors.push({ message: 'Not available when using Document Store', context: { key } });
1278
- }
1279
- }
1280
-
1281
- if (extraValidationErrors.length) {
1282
- let error = new Error('Input validation failed');
1283
- error.details = extraValidationErrors;
1284
- return failAction(request, h, error);
1285
- }
1286
-
1287
- let documentStoreEnabled = await settings.get('documentStoreEnabled');
1288
- if (!documentStoreEnabled) {
1289
- let error = new Error('Document store not enabled');
1290
- error.details = extraValidationErrors;
1291
- return failAction(request, h, error);
1292
- }
1293
-
1294
- try {
1295
- return await accountObject.searchMessages(Object.assign({ documentStore: true }, request.query, request.payload), { unified: true });
1296
- } catch (err) {
1297
- handleError(request, err);
1298
- }
1299
- },
1300
- options: {
1301
- description: 'Unified search for messages',
1302
- notes: 'Filter messages from the Document Store for multiple accounts or paths. Document Store must be enabled for the unified search to work.',
1303
- tags: ['api', 'Deprecated endpoints (Document Store)'],
1304
-
1305
- plugins: {
1306
- openapi: {
1307
- 'x-ee-impact': IMPACT.READONLY,
1308
- responses: apiResponses('Returns matching messages across all indexed accounts.', 400, 401, 403, 429, 500)
1309
- }
1310
- },
1311
-
1312
- auth: {
1313
- strategy: 'api-token',
1314
- mode: 'required'
1315
- },
1316
- cors: CORS_CONFIG,
1317
-
1318
- validate: {
1319
- options: {
1320
- stripUnknown: false,
1321
- abortEarly: false,
1322
- convert: true
1323
- },
1324
- failAction,
1325
-
1326
- query: Joi.object({
1327
- page: Joi.number()
1328
- .integer()
1329
- .min(0)
1330
- .max(1024 * 1024)
1331
- .default(0)
1332
- .example(0)
1333
- .description('Page number (zero indexed, so use 0 for first page)'),
1334
- pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page'),
1335
- exposeQuery: Joi.boolean()
1336
- .truthy('Y', 'true', '1')
1337
- .falsy('N', 'false', 0)
1338
- .description('If enabled then includes the combined query (as the documentStoreQuery field) in the response for debugging')
1339
- .label('exposeQuery')
1340
- .optional()
1341
- .meta({ swaggerHidden: true })
1342
- }),
1343
-
1344
- payload: Joi.object({
1345
- accounts: Joi.array()
1346
- .items(Joi.string().empty('').trim().max(256).example('example'))
1347
- .single()
1348
- .description('Optional list of account ID values')
1349
- .label('UnifiedSearchAccounts'),
1350
- paths: Joi.array()
1351
- .items(Joi.string().optional().example('INBOX'))
1352
- .single()
1353
- .description('Optional list of mailbox folder paths or specialUse flags')
1354
- .label('UnifiedSearchPaths'),
1355
- search: searchSchema,
1356
- documentQuery: Joi.object().min(1).description('Document Store query').label('DocumentQuery').unknown().meta({ swaggerHidden: true })
1357
- }).label('UnifiedSearchQuery')
1358
- },
1359
-
1360
- response: {
1361
- schema: Joi.object({
1362
- total: Joi.number()
1363
- .integer()
1364
- .example(120)
1365
- .description('Total number of matching messages (capped at 10000 by the Document Store)')
1366
- .label('UnifiedTotalNumber'),
1367
- page: Joi.number().integer().example(0).description('Current page number (zero-based)').label('UnifiedPageNumber'),
1368
- pages: Joi.number().integer().example(24).description('Total number of pages available').label('UnifiedPagesNumber'),
1369
- accounts: Joi.array()
1370
- .items(Joi.string().example('example'))
1371
- .description('Account filter used for the search, if provided')
1372
- .label('UnifiedSearchAccountsEcho'),
1373
- paths: Joi.array()
1374
- .items(Joi.string().example('INBOX'))
1375
- .description('Path filter used for the search, if provided')
1376
- .label('UnifiedSearchPathsEcho'),
1377
- messages: Joi.array()
1378
- .items(
1379
- messageEntrySchema
1380
- .keys({
1381
- account: accountIdSchema.description('Account ID this message belongs to')
1382
- })
1383
- .unknown()
1384
- .label('UnifiedMessageListEntry')
1385
- )
1386
- .label('UnifiedPageMessages'),
1387
- documentStoreQuery: documentStoreQuerySchema
1388
- }).label('UnifiedSearchResponse'),
1389
- failAction: 'log'
1390
- }
1391
- }
1392
- });
1393
- }
1394
-
1395
1207
  // GET /v1/account/{account}/text/{text} - Retrieve message text
1396
1208
  server.route({
1397
1209
  method: 'GET',
1398
1210
  path: '/v1/account/{account}/text/{text}',
1399
1211
 
1400
- async handler(request, h) {
1212
+ async handler(request) {
1401
1213
  let accountObject = new Account({
1402
1214
  redis,
1403
1215
  account: request.params.account,
1404
1216
  call,
1405
1217
  secret: await getSecret(),
1406
- esClient: await h.getESClient(request.logger),
1407
1218
  timeout: request.headers['x-ee-timeout']
1408
1219
  });
1409
1220
 
@@ -1464,15 +1275,13 @@ async function init(args) {
1464
1275
  .description('Which text content to return, use * for all. By default all contents are returned.')
1465
1276
  .label('TextSearchTextType'),
1466
1277
 
1467
- webSafeHtml: Joi.boolean()
1468
- .truthy('Y', 'true', '1')
1469
- .falsy('N', 'false', 0)
1278
+ webSafeHtml: apiBoolean()
1470
1279
  .default(false)
1471
1280
  .description('If true, then returns a single sanitized HTML rendering of the body instead of the raw text parts')
1472
1281
  .meta({ usage: FIELD_USAGE.webSafeText })
1473
1282
  .label('WebSafeText'),
1474
1283
 
1475
- documentStore: documentStoreSchema.default(false)
1284
+ documentStore: documentStoreSchema
1476
1285
  }),
1477
1286
 
1478
1287
  params: Joi.object({
@@ -1495,7 +1304,10 @@ async function init(args) {
1495
1304
  .description('Whether the HTML content has been processed into a web-safe version (set when webSafeHtml was requested)'),
1496
1305
  hasMore: Joi.boolean()
1497
1306
  .example(false)
1498
- .description('Is the current text output capped or not. Always false for Gmail API and MS Graph API accounts')
1307
+ .description(
1308
+ 'Whether the returned text was capped by maxBytes. On an IMAP account the cap also decides how much is downloaded; ' +
1309
+ 'on a Gmail API or MS Graph account the provider returns the whole text in one response and the cap decides how much of it is passed on'
1310
+ )
1499
1311
  }).label('TextResponse'),
1500
1312
  failAction: 'log'
1501
1313
  }