emailengine-app 2.84.1 → 2.85.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 (147) hide show
  1. package/.dockerignore +6 -0
  2. package/.ncurc.js +5 -3
  3. package/.prettierignore +5 -1
  4. package/.prettierrc.js +2 -0
  5. package/.release-please-manifest.json +1 -1
  6. package/CHANGELOG.md +61 -0
  7. package/Dockerfile +8 -2
  8. package/README.md +1 -1
  9. package/bin/emailengine.js +444 -403
  10. package/copy-static-files.sh +39 -14
  11. package/data/google-crawlers.json +1 -1
  12. package/data/public_suffix_list.dat +16562 -0
  13. package/docker-compose.yml +1 -1
  14. package/eslint.config.js +81 -99
  15. package/lib/account/own-account-key.js +42 -0
  16. package/lib/account-assignment.js +1 -33
  17. package/lib/account.js +68 -24
  18. package/lib/add-trackers.js +11 -4
  19. package/lib/api-reference/format.js +4 -3
  20. package/lib/api-routes/account-routes.js +244 -26
  21. package/lib/api-routes/blocklist-routes.js +23 -2
  22. package/lib/api-routes/delivery-test-routes.js +26 -3
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +37 -5
  25. package/lib/api-routes/mailbox-routes.js +41 -2
  26. package/lib/api-routes/message-routes.js +104 -4
  27. package/lib/api-routes/mint-bounds.js +11 -0
  28. package/lib/api-routes/oauth2-app-routes.js +48 -15
  29. package/lib/api-routes/outbox-routes.js +45 -11
  30. package/lib/api-routes/permission-map.js +12 -1
  31. package/lib/api-routes/route-helpers.js +125 -3
  32. package/lib/api-routes/settings-routes.js +23 -2
  33. package/lib/api-routes/submit-routes.js +338 -309
  34. package/lib/api-routes/template-routes.js +38 -2
  35. package/lib/api-routes/token-routes.js +142 -96
  36. package/lib/api-routes/webhook-route-routes.js +13 -2
  37. package/lib/auth-token.js +23 -10
  38. package/lib/bounce-detect.js +414 -210
  39. package/lib/consts.js +39 -4
  40. package/lib/create-imap-client.js +41 -2
  41. package/lib/email-client/base-client.js +30 -41
  42. package/lib/email-client/gmail-client.js +30 -18
  43. package/lib/email-client/imap/mailbox.js +13 -23
  44. package/lib/email-client/imap/response-metrics.js +75 -0
  45. package/lib/email-client/imap/subconnection.js +1 -1
  46. package/lib/email-client/imap-client.js +6 -3
  47. package/lib/email-client/message-builder.js +7 -2
  48. package/lib/email-client/notification-handler.js +1 -2
  49. package/lib/email-client/outlook/graph-api.js +17 -2
  50. package/lib/email-client/outlook-client.js +6 -3
  51. package/lib/email-client/smtp-pool-manager.js +6 -0
  52. package/lib/encrypt.js +9 -0
  53. package/lib/export.js +3 -1
  54. package/lib/gateway.js +2 -3
  55. package/lib/get-raw-email.js +4 -2
  56. package/lib/hapi-request-logger.js +107 -0
  57. package/lib/imap-proxy-auth.js +14 -1
  58. package/lib/imapproxy/imap-core/README.md +6 -5
  59. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +1 -0
  60. package/lib/imapproxy/imap-core/lib/commands/login.js +1 -0
  61. package/lib/imapproxy/imap-core/lib/imap-command.js +86 -43
  62. package/lib/imapproxy/imap-core/lib/imap-stream.js +58 -13
  63. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +3 -1
  64. package/lib/mcp/listen.js +10 -1
  65. package/lib/mcp/tools.js +37 -8
  66. package/lib/notify-attachments.js +17 -0
  67. package/lib/oauth/external-account-config.js +3 -1
  68. package/lib/oauth/gmail.js +21 -48
  69. package/lib/oauth/mail-ru.js +5 -38
  70. package/lib/oauth/outlook-mailbox.js +35 -0
  71. package/lib/oauth/outlook.js +26 -44
  72. package/lib/oauth/state.js +24 -0
  73. package/lib/oauth2-apps.js +1 -1
  74. package/lib/pbkdf2-phc.js +19 -2
  75. package/lib/privileged-settings.js +6 -3
  76. package/lib/redis-scan-delete.js +15 -1
  77. package/lib/schemas.js +79 -33
  78. package/lib/settings.js +13 -1
  79. package/lib/smtp-auth.js +23 -0
  80. package/lib/sso.js +1 -1
  81. package/lib/swagger-options.js +1 -1
  82. package/lib/thread-diagnostics.js +46 -0
  83. package/lib/timezones.js +109 -0
  84. package/lib/token-permission-view.js +3 -3
  85. package/lib/tools.js +285 -66
  86. package/lib/totp.js +2 -5
  87. package/lib/translations.js +1 -2
  88. package/lib/ui-routes/account-routes.js +491 -491
  89. package/lib/ui-routes/account-setup.js +99 -0
  90. package/lib/ui-routes/admin-config-routes.js +98 -48
  91. package/lib/ui-routes/admin-entities-routes.js +113 -31
  92. package/lib/ui-routes/auth-routes.js +137 -62
  93. package/lib/ui-routes/connection-security-form.js +74 -0
  94. package/lib/ui-routes/form-lists.js +46 -0
  95. package/lib/ui-routes/internals-routes.js +5 -0
  96. package/lib/ui-routes/mcp-consent-routes.js +5 -1
  97. package/lib/ui-routes/oauth-config-routes.js +133 -100
  98. package/lib/ui-routes/route-helpers.js +19 -3
  99. package/lib/ui-routes/sign-in-helpers.js +59 -0
  100. package/lib/ui-routes/tls-config-routes.js +58 -15
  101. package/lib/ui-routes/unsubscribe-routes.js +6 -3
  102. package/lib/utils/back-off.js +82 -0
  103. package/lib/utils/map-concurrent.js +36 -0
  104. package/lib/utils/murmurhash3.js +66 -0
  105. package/lib/utils/network.js +28 -0
  106. package/lib/utils/provider-id.js +27 -0
  107. package/lib/utils/public-suffix.js +122 -0
  108. package/lib/utils/random-id.js +26 -0
  109. package/lib/utils/require-tls.js +33 -0
  110. package/lib/utils/version.js +74 -0
  111. package/lib/web-safe-html.js +5 -6
  112. package/lib/webhook-penalty.js +75 -0
  113. package/lib/webhook-routing.js +49 -2
  114. package/lib/webhooks.js +41 -6
  115. package/package.json +37 -39
  116. package/sbom.json +7980 -1
  117. package/server.js +659 -455
  118. package/static/js/ace/ace.js +1 -1
  119. package/static/js/ace/mode-handlebars.js +1 -1
  120. package/static/js/ace/mode-html.js +1 -1
  121. package/static/js/ace/mode-javascript.js +1 -1
  122. package/static/js/ace/mode-markdown.js +1 -1
  123. package/static/js/ace/worker-html.js +1 -1
  124. package/static/js/ace/worker-javascript.js +1 -1
  125. package/static/js/ace/worker-json.js +1 -1
  126. package/static/js/ee-client.js +5 -0
  127. package/static/licenses.html +191 -1016
  128. package/translations/messages.pot +70 -71
  129. package/views/account/security.hbs +10 -0
  130. package/views/accounts/account.hbs +11 -11
  131. package/views/accounts/edit.hbs +6 -2
  132. package/views/config/ai.hbs +1 -1
  133. package/views/config/security.hbs +2 -2
  134. package/views/config/service.hbs +3 -0
  135. package/views/internals/index.hbs +8 -0
  136. package/views/partials/gateway_form.hbs +3 -1
  137. package/views/partials/webhook_form.hbs +1 -1
  138. package/views/suppression-lists/index.hbs +1 -1
  139. package/workers/api.js +780 -585
  140. package/workers/export.js +1 -1
  141. package/workers/submit.js +1 -1
  142. package/workers/webhooks.js +54 -34
  143. package/config/test.toml +0 -46
  144. package/install.sh +0 -428
  145. package/setup-production.sh +0 -215
  146. package/systemd/emailengine.service +0 -97
  147. package/systemd/nginx-proxy.conf +0 -77
@@ -6,13 +6,16 @@ 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, apiBoolean, formBoolean } = require('../schemas');
9
+ const { apiResponses, apiBoolean, formBoolean, requireTlsSchema } = 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');
13
13
 
14
14
  // Gateways store SMTP delivery errors, not OAuth2 errors, so the error shape differs from the
15
15
  // account-level lastErrorSchema
16
+ // the account schemas' STARTTLS rule, on the form boolean the gateway payloads use
17
+ const gatewayRequireTlsSchema = requireTlsSchema('GatewayRequireTLS', formBoolean());
18
+
16
19
  const gatewayLastErrorSchema = Joi.object({
17
20
  created: Joi.number().integer().example(1623868624153).description('Timestamp of the error as milliseconds from epoch'),
18
21
  status: Joi.string().valid('error').example('error').description('Status of the last delivery attempt'),
@@ -32,8 +35,8 @@ const gatewayLastErrorSchema = Joi.object({
32
35
  .description('Information about the last failed delivery attempt using this gateway')
33
36
  .label('GatewayErrorEntry');
34
37
 
35
- async function init(args) {
36
- const { server, call, CORS_CONFIG } = args;
38
+ function registerListGateways(server, args) {
39
+ const { call, CORS_CONFIG } = args;
37
40
 
38
41
  server.route({
39
42
  method: 'GET',
@@ -126,6 +129,10 @@ async function init(args) {
126
129
  }
127
130
  }
128
131
  });
132
+ }
133
+
134
+ function registerGetGateway(server, args) {
135
+ const { call, CORS_CONFIG } = args;
129
136
 
130
137
  server.route({
131
138
  method: 'GET',
@@ -235,6 +242,7 @@ async function init(args) {
235
242
  .example(true)
236
243
  .description('Should connection use TLS. Usually true for port 465')
237
244
  .label('GatewayTlsOptions'),
245
+ requireTLS: gatewayRequireTlsSchema.allow(null),
238
246
 
239
247
  lastError: gatewayLastErrorSchema.allow(null)
240
248
  }).label('GatewayResponse'),
@@ -242,6 +250,10 @@ async function init(args) {
242
250
  }
243
251
  }
244
252
  });
253
+ }
254
+
255
+ function registerCreateGateway(server, args) {
256
+ const { call, CORS_CONFIG } = args;
245
257
 
246
258
  server.route({
247
259
  method: 'POST',
@@ -326,7 +338,8 @@ async function init(args) {
326
338
  .default(false)
327
339
  .example(true)
328
340
  .description('Should connection use TLS. Usually true for port 465')
329
- .label('GatewayCreateTlsOptions')
341
+ .label('GatewayCreateTlsOptions'),
342
+ requireTLS: gatewayRequireTlsSchema
330
343
  }).label('CreateGateway')
331
344
  },
332
345
 
@@ -345,6 +358,10 @@ async function init(args) {
345
358
  }
346
359
  }
347
360
  });
361
+ }
362
+
363
+ function registerUpdateGateway(server, args) {
364
+ const { call, CORS_CONFIG } = args;
348
365
 
349
366
  server.route({
350
367
  method: 'PUT',
@@ -417,7 +434,8 @@ async function init(args) {
417
434
  .description('Service port number')
418
435
  .label('Port'),
419
436
 
420
- secure: formBoolean().example(true).description('Should connection use TLS. Usually true for port 465').label('GatewayUpdateTlsOptions')
437
+ secure: formBoolean().example(true).description('Should connection use TLS. Usually true for port 465').label('GatewayUpdateTlsOptions'),
438
+ requireTLS: gatewayRequireTlsSchema
421
439
  }).label('UpdateGateway')
422
440
  },
423
441
 
@@ -429,6 +447,10 @@ async function init(args) {
429
447
  }
430
448
  }
431
449
  });
450
+ }
451
+
452
+ function registerDeleteGateway(server, args) {
453
+ const { CORS_CONFIG } = args;
432
454
 
433
455
  server.route({
434
456
  method: 'DELETE',
@@ -494,4 +516,14 @@ async function init(args) {
494
516
  });
495
517
  }
496
518
 
519
+ async function init(args) {
520
+ const { server } = args;
521
+
522
+ registerListGateways(server, args);
523
+ registerGetGateway(server, args);
524
+ registerCreateGateway(server, args);
525
+ registerUpdateGateway(server, args);
526
+ registerDeleteGateway(server, args);
527
+ }
528
+
497
529
  module.exports = init;
@@ -32,8 +32,8 @@ function throwMailboxError(request, err) {
32
32
  throw error;
33
33
  }
34
34
 
35
- async function init(args) {
36
- const { server, call, CORS_CONFIG, FLAG_SORT_ORDER } = args;
35
+ function registerListMailboxes(server, args) {
36
+ const { call, CORS_CONFIG, FLAG_SORT_ORDER } = args;
37
37
 
38
38
  server.route({
39
39
  method: 'GET',
@@ -130,6 +130,10 @@ async function init(args) {
130
130
  }
131
131
  }
132
132
  });
133
+ }
134
+
135
+ function registerCreateMailbox(server, args) {
136
+ const { call, CORS_CONFIG } = args;
133
137
 
134
138
  server.route({
135
139
  method: 'POST',
@@ -157,6 +161,12 @@ async function init(args) {
157
161
  tags: ['api', 'Mailbox'],
158
162
 
159
163
  plugins: {
164
+ mcp: {
165
+ name: 'create_mailbox',
166
+ title: 'Create mailbox',
167
+ description:
168
+ 'Create a folder. Give the path as a list of names from the top level down (["Projects", "2026"]) so the server joins them with its own separator; a missing parent is created too. The response carries the full path that list_messages and move_message take.'
169
+ },
160
170
  openapi: {
161
171
  responses: apiResponses('Returns the created folder and its path.', 400, 401, 403, 404, 429, 500, 503)
162
172
  }
@@ -201,6 +211,10 @@ async function init(args) {
201
211
  }
202
212
  }
203
213
  });
214
+ }
215
+
216
+ function registerModifyMailbox(server, args) {
217
+ const { call, CORS_CONFIG } = args;
204
218
 
205
219
  server.route({
206
220
  method: 'PUT',
@@ -228,6 +242,12 @@ async function init(args) {
228
242
  tags: ['api', 'Mailbox'],
229
243
 
230
244
  plugins: {
245
+ mcp: {
246
+ name: 'update_mailbox',
247
+ title: 'Rename or update mailbox',
248
+ description:
249
+ 'Rename or move a folder (newPath, as a list of names from the top level down), or change whether it is subscribed. `path` is the current path from list_mailboxes. The messages move with the folder; list them again under the new path for their current ids.'
250
+ },
231
251
  openapi: {
232
252
  responses: apiResponses('Returns the renamed folder with its old and new paths.', 400, 401, 403, 404, 429, 500, 503)
233
253
  }
@@ -284,6 +304,10 @@ async function init(args) {
284
304
  }
285
305
  }
286
306
  });
307
+ }
308
+
309
+ function registerDeleteMailbox(server, args) {
310
+ const { call, CORS_CONFIG } = args;
287
311
 
288
312
  server.route({
289
313
  method: 'DELETE',
@@ -313,6 +337,12 @@ async function init(args) {
313
337
  tags: ['api', 'Mailbox'],
314
338
 
315
339
  plugins: {
340
+ mcp: {
341
+ name: 'delete_mailbox',
342
+ title: 'Delete mailbox',
343
+ description:
344
+ 'Delete a folder by its path from list_mailboxes - confirm with the user before calling this. On an IMAP account the folder goes with every message in it, and nothing is kept in Trash. On a Gmail API account the label is removed and the messages stay in the mailbox under their other labels.'
345
+ },
316
346
  openapi: {
317
347
  'x-ee-impact': IMPACT.DESTRUCTIVE,
318
348
  responses: apiResponses('Returns the deleted folder path.', 400, 401, 403, 404, 429, 500, 503)
@@ -357,4 +387,13 @@ async function init(args) {
357
387
  });
358
388
  }
359
389
 
390
+ async function init(args) {
391
+ const { server } = args;
392
+
393
+ registerListMailboxes(server, args);
394
+ registerCreateMailbox(server, args);
395
+ registerModifyMailbox(server, args);
396
+ registerDeleteMailbox(server, args);
397
+ }
398
+
360
399
  module.exports = init;
@@ -5,7 +5,8 @@ const { Account } = require('../account');
5
5
  const getSecret = require('../get-secret');
6
6
  const Joi = require('joi');
7
7
  const { failAction } = require('../tools');
8
- const { handleError } = require('./route-helpers');
8
+ const { handleError, assertCredentialAllows } = require('./route-helpers');
9
+ const { ACTION, GROUP } = require('./permission-map');
9
10
  const BEHAVIOR = require('./behavior-notes');
10
11
  const { IMPACT } = require('./operation-impact');
11
12
  const { FIELD_USAGE } = require('../field-usage');
@@ -95,8 +96,8 @@ const idMapSchema = Joi.array()
95
96
  .description('An optional map of source and target ID values, if the server provided this info (IMAP accounts only)')
96
97
  .label('IdMapArray');
97
98
 
98
- async function init(args) {
99
- const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
99
+ function registerGetMessageSource(server, args) {
100
+ const { call, CORS_CONFIG } = args;
100
101
 
101
102
  // GET /v1/account/{account}/message/{message}/source - Download raw message
102
103
  server.route({
@@ -152,6 +153,10 @@ async function init(args) {
152
153
  }
153
154
  }
154
155
  });
156
+ }
157
+
158
+ function registerGetMessage(server, args) {
159
+ const { call, CORS_CONFIG } = args;
155
160
 
156
161
  // GET /v1/account/{account}/message/{message} - Get message information
157
162
  server.route({
@@ -168,6 +173,11 @@ async function init(args) {
168
173
  });
169
174
 
170
175
  try {
176
+ // The route resolves to read/message, and marking the message seen is a write
177
+ if (request.query.markAsSeen) {
178
+ assertCredentialAllows(request, { action: ACTION.WRITE, group: GROUP.MESSAGE }, 'mark a message as seen');
179
+ }
180
+
171
181
  // detectBounce is not a query option: it is what this route asks of the client, and
172
182
  // the internal fetches (a reply's reference, the sync path) do not pay for it
173
183
  let options = Object.assign({}, request.query, { detectBounce: true });
@@ -278,6 +288,10 @@ async function init(args) {
278
288
  }
279
289
  }
280
290
  });
291
+ }
292
+
293
+ function registerUploadMessage(server, args) {
294
+ const { call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
281
295
 
282
296
  // POST /v1/account/{account}/message - Upload message
283
297
  server.route({
@@ -320,7 +334,7 @@ async function init(args) {
320
334
  description:
321
335
  'Store a new message in a folder, typically a draft in the Drafts folder. Takes structured fields (from, to, subject, text, html). ' +
322
336
  'It takes the same `reference` block as send_message, so a reply or a forward can be drafted for the user to look over first. ' +
323
- 'Nothing is sent - use send_message for that.',
337
+ 'Nothing is sent: once the user has reviewed the draft, send_draft sends it by the id this returns. send_message sends a new message directly.',
324
338
  // An allowlist for the same reason send_message uses one: the composed message
325
339
  // is a small stable set, the route's payload is not, and a field added later
326
340
  // should not join an agent-facing schema by default. Left out are `raw` (which
@@ -475,6 +489,10 @@ async function init(args) {
475
489
  }
476
490
  }
477
491
  });
492
+ }
493
+
494
+ function registerUpdateMessage(server, args) {
495
+ const { call, CORS_CONFIG } = args;
478
496
 
479
497
  // PUT /v1/account/{account}/message/{message} - Update message
480
498
  server.route({
@@ -561,6 +579,10 @@ async function init(args) {
561
579
  }
562
580
  }
563
581
  });
582
+ }
583
+
584
+ function registerUpdateMessages(server, args) {
585
+ const { call, CORS_CONFIG } = args;
564
586
 
565
587
  // PUT /v1/account/{account}/messages - Update multiple messages
566
588
  server.route({
@@ -588,6 +610,14 @@ async function init(args) {
588
610
  tags: ['api', 'Multi Message Actions'],
589
611
 
590
612
  plugins: {
613
+ mcp: {
614
+ name: 'update_messages',
615
+ title: 'Update matching messages',
616
+ description:
617
+ 'Change the flags or labels of every message in one folder that matches a search, in one call - for example mark all unread mail from one sender as read. ' +
618
+ 'Run search_messages with the same folder and criteria first to see which messages match, then pass those criteria here. ' +
619
+ 'For one message, or a few whose ids are known, use update_message instead.'
620
+ },
591
621
  openapi: {
592
622
  'x-ee-behavior': [BEHAVIOR.NO_LABEL_SET_ON_GMAIL],
593
623
  responses: apiResponses('Returns which flag and label changes were applied to the matching messages.', 400, 401, 403, 404, 429, 500, 503)
@@ -643,6 +673,10 @@ async function init(args) {
643
673
  }
644
674
  }
645
675
  });
676
+ }
677
+
678
+ function registerMoveMessage(server, args) {
679
+ const { call, CORS_CONFIG } = args;
646
680
 
647
681
  // PUT /v1/account/{account}/message/{message}/move - Move a message
648
682
  server.route({
@@ -726,6 +760,10 @@ async function init(args) {
726
760
  }
727
761
  }
728
762
  });
763
+ }
764
+
765
+ function registerMoveMessages(server, args) {
766
+ const { call, CORS_CONFIG } = args;
729
767
 
730
768
  // PUT /v1/account/{account}/messages/move - Move multiple messages
731
769
  server.route({
@@ -753,6 +791,18 @@ async function init(args) {
753
791
  tags: ['api', 'Multi Message Actions'],
754
792
 
755
793
  plugins: {
794
+ mcp: {
795
+ name: 'move_messages',
796
+ title: 'Move matching messages',
797
+ description:
798
+ 'Move every message in one folder that matches a search to another folder, in one call. `source` is the folder searched and `path` the folder the messages go to, both paths from list_mailboxes. ' +
799
+ 'Run search_messages on the source folder with the same criteria first to see which messages match, then pass those criteria here. ' +
800
+ 'For one message, or a few whose ids are known, use move_message instead.',
801
+ // The route reads the folder to search from the query and the target from the
802
+ // payload, both as `path`. The target keeps the name move_message gives it, and
803
+ // the folder searched takes the name move_message gives its own source folder.
804
+ rename: { query: { path: 'source' } }
805
+ },
756
806
  openapi: {
757
807
  responses: apiResponses('Returns the number of messages moved.', 400, 401, 403, 404, 429, 500, 503)
758
808
  }
@@ -805,6 +855,10 @@ async function init(args) {
805
855
  }
806
856
  }
807
857
  });
858
+ }
859
+
860
+ function registerDeleteMessage(server, args) {
861
+ const { call, CORS_CONFIG } = args;
808
862
 
809
863
  // DELETE /v1/account/{account}/message/{message} - Delete message
810
864
  server.route({
@@ -894,6 +948,10 @@ async function init(args) {
894
948
  }
895
949
  }
896
950
  });
951
+ }
952
+
953
+ function registerDeleteMessages(server, args) {
954
+ const { call, CORS_CONFIG } = args;
897
955
 
898
956
  // PUT /v1/account/{account}/messages/delete - Delete multiple messages
899
957
  server.route({
@@ -921,6 +979,14 @@ async function init(args) {
921
979
  tags: ['api', 'Multi Message Actions'],
922
980
 
923
981
  plugins: {
982
+ mcp: {
983
+ name: 'delete_messages',
984
+ title: 'Delete matching messages',
985
+ description:
986
+ 'Delete every message in one folder that matches a search, in one call - confirm with the user before calling this. Messages are moved to Trash, and deleted permanently when the folder already is Trash. ' +
987
+ 'Run search_messages with the same folder and criteria first to see which messages match, and pass exactly those criteria here. ' +
988
+ 'For one message, or a few whose ids are known, use delete_message instead.'
989
+ },
924
990
  openapi: {
925
991
  'x-ee-impact': IMPACT.DESTRUCTIVE,
926
992
  'x-ee-behavior': [BEHAVIOR.GMAIL_DELETE_IS_TRASH],
@@ -994,6 +1060,10 @@ async function init(args) {
994
1060
  }
995
1061
  }
996
1062
  });
1063
+ }
1064
+
1065
+ function registerListMessages(server, args) {
1066
+ const { call, CORS_CONFIG } = args;
997
1067
 
998
1068
  // GET /v1/account/{account}/messages - List messages in a folder
999
1069
  server.route({
@@ -1081,6 +1151,10 @@ async function init(args) {
1081
1151
  }
1082
1152
  }
1083
1153
  });
1154
+ }
1155
+
1156
+ function registerSearchMessages(server, args) {
1157
+ const { call, CORS_CONFIG } = args;
1084
1158
 
1085
1159
  // POST /v1/account/{account}/search - Search for messages
1086
1160
  server.route({
@@ -1203,6 +1277,10 @@ async function init(args) {
1203
1277
  }
1204
1278
  }
1205
1279
  });
1280
+ }
1281
+
1282
+ function registerGetMessageText(server, args) {
1283
+ const { call, CORS_CONFIG, MAX_ATTACHMENT_SIZE } = args;
1206
1284
 
1207
1285
  // GET /v1/account/{account}/text/{text} - Retrieve message text
1208
1286
  server.route({
@@ -1313,6 +1391,10 @@ async function init(args) {
1313
1391
  }
1314
1392
  }
1315
1393
  });
1394
+ }
1395
+
1396
+ function registerGetAttachment(server, args) {
1397
+ const { call, CORS_CONFIG } = args;
1316
1398
 
1317
1399
  // GET /v1/account/{account}/attachment/{attachment} - Download attachment
1318
1400
  server.route({
@@ -1382,4 +1464,22 @@ async function init(args) {
1382
1464
  });
1383
1465
  }
1384
1466
 
1467
+ async function init(args) {
1468
+ const { server } = args;
1469
+
1470
+ registerGetMessageSource(server, args);
1471
+ registerGetMessage(server, args);
1472
+ registerUploadMessage(server, args);
1473
+ registerUpdateMessage(server, args);
1474
+ registerUpdateMessages(server, args);
1475
+ registerMoveMessage(server, args);
1476
+ registerMoveMessages(server, args);
1477
+ registerDeleteMessage(server, args);
1478
+ registerDeleteMessages(server, args);
1479
+ registerListMessages(server, args);
1480
+ registerSearchMessages(server, args);
1481
+ registerGetMessageText(server, args);
1482
+ registerGetAttachment(server, args);
1483
+ }
1484
+
1385
1485
  module.exports = init;
@@ -66,6 +66,17 @@ function mintWidenings(creator, payload) {
66
66
  const own = creator.restrictions || {};
67
67
  const requested = (payload && payload.restrictions) || {};
68
68
 
69
+ // Scopes are a limit too: a token minted with `api` only must not produce one that also serves
70
+ // the SMTP or IMAP proxy listeners, or every scope the creator was issued with is one request
71
+ // away from gone. A creator with no scope list, or `*`, holds every scope and may hand any out;
72
+ // a payload with no scope list asks for every scope and is refused by a scoped creator.
73
+ if (Array.isArray(creator.scopes) && creator.scopes.length && !creator.scopes.includes('*')) {
74
+ const list = Array.isArray(payload && payload.scopes) ? payload.scopes : [];
75
+ if (!list.length || !list.every(entry => creator.scopes.includes(entry))) {
76
+ reasons.push("scopes must be set to a subset of the creating token's own scopes");
77
+ }
78
+ }
79
+
69
80
  if (Array.isArray(own.addresses) && own.addresses.length) {
70
81
  const list = Array.isArray(requested.addresses) ? requested.addresses : [];
71
82
  if (!list.length || !list.every(entry => entryCovered(entry, own.addresses))) {
@@ -53,20 +53,8 @@ const oauth2AppExtraFields = {
53
53
  pubSubIamPolicy: Joi.boolean().example(true).description('Whether the IAM policy for the Cloud Pub/Sub topic has been set up')
54
54
  };
55
55
 
56
- async function init(args) {
57
- const { server, call, CORS_CONFIG, OAuth2ProviderSchema } = args;
58
-
59
- // Notify the worker when an app create/update changed Pub/Sub resources, and strip the
60
- // internal marker from the API response
61
- let applyPubSubUpdates = async result => {
62
- if (result && result.pubsubUpdates) {
63
- if (Object.keys(result.pubsubUpdates).length > 0) {
64
- await call({ cmd: 'googlePubSub', app: result.id });
65
- }
66
- delete result.pubsubUpdates;
67
- }
68
- return result;
69
- };
56
+ function registerListOAuth2Apps(server, ctx) {
57
+ const { CORS_CONFIG, OAuth2ProviderSchema } = ctx;
70
58
 
71
59
  server.route({
72
60
  method: 'GET',
@@ -212,6 +200,10 @@ async function init(args) {
212
200
  }
213
201
  }
214
202
  });
203
+ }
204
+
205
+ function registerGetOAuth2App(server, ctx) {
206
+ const { CORS_CONFIG, OAuth2ProviderSchema } = ctx;
215
207
 
216
208
  server.route({
217
209
  method: 'GET',
@@ -338,6 +330,10 @@ async function init(args) {
338
330
  }
339
331
  }
340
332
  });
333
+ }
334
+
335
+ function registerCreateOAuth2App(server, ctx) {
336
+ const { CORS_CONFIG, applyPubSubUpdates } = ctx;
341
337
 
342
338
  server.route({
343
339
  method: 'POST',
@@ -396,6 +392,10 @@ async function init(args) {
396
392
  }
397
393
  }
398
394
  });
395
+ }
396
+
397
+ function registerUpdateOAuth2App(server, ctx) {
398
+ const { CORS_CONFIG, applyPubSubUpdates } = ctx;
399
399
 
400
400
  server.route({
401
401
  method: 'PUT',
@@ -476,7 +476,7 @@ async function init(args) {
476
476
  .trim()
477
477
  .empty('')
478
478
  .max(256)
479
- .example('boT7Q~dUljnfFdVuqpC11g8nGMjO8kpRAv-ZB')
479
+ .example('example-client-secret')
480
480
  .description('Client secret for 3-legged OAuth2 applications'),
481
481
 
482
482
  pubSubApp: Joi.string()
@@ -559,6 +559,10 @@ async function init(args) {
559
559
  }
560
560
  }
561
561
  });
562
+ }
563
+
564
+ function registerDeleteOAuth2App(server, ctx) {
565
+ const { call, CORS_CONFIG } = ctx;
562
566
 
563
567
  server.route({
564
568
  method: 'DELETE',
@@ -626,6 +630,10 @@ async function init(args) {
626
630
  }
627
631
  }
628
632
  });
633
+ }
634
+
635
+ function registerVerifyOAuth2App(server, ctx) {
636
+ const { CORS_CONFIG } = ctx;
629
637
 
630
638
  server.route({
631
639
  method: 'POST',
@@ -716,4 +724,29 @@ async function init(args) {
716
724
  });
717
725
  }
718
726
 
727
+ async function init(args) {
728
+ const { server, call, CORS_CONFIG, OAuth2ProviderSchema } = args;
729
+
730
+ // Notify the worker when an app create/update changed Pub/Sub resources, and strip the
731
+ // internal marker from the API response
732
+ let applyPubSubUpdates = async result => {
733
+ if (result && result.pubsubUpdates) {
734
+ if (Object.keys(result.pubsubUpdates).length > 0) {
735
+ await call({ cmd: 'googlePubSub', app: result.id });
736
+ }
737
+ delete result.pubsubUpdates;
738
+ }
739
+ return result;
740
+ };
741
+
742
+ const ctx = { call, CORS_CONFIG, OAuth2ProviderSchema, applyPubSubUpdates };
743
+
744
+ registerListOAuth2Apps(server, ctx);
745
+ registerGetOAuth2App(server, ctx);
746
+ registerCreateOAuth2App(server, ctx);
747
+ registerUpdateOAuth2App(server, ctx);
748
+ registerDeleteOAuth2App(server, ctx);
749
+ registerVerifyOAuth2App(server, ctx);
750
+ }
751
+
719
752
  module.exports = init;
@@ -10,17 +10,8 @@ const { outboxEntrySchema, apiResponses, apiBoolean } = require('../schemas');
10
10
  const { IMPACT } = require('./operation-impact');
11
11
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
12
12
 
13
- async function init(args) {
14
- const { server, CORS_CONFIG } = args;
15
-
16
- // The queue ID of a message, as every per-message outbox route takes it
17
- const outboxEntryParams = Joi.object({
18
- queueId: Joi.string().max(100).example('d41f0423195f271f').description('Queue identifier for scheduled email').required()
19
- }).label('OutboxEntryParams');
20
-
21
- // What every per-message route answers for an unknown queue ID. The state refusals the
22
- // outbox module throws (code NotFailed, ContentGone, NotDelayed) carry a 409 of their own
23
- const notFound = () => Boom.boomify(new Error('Requested queue entry was not found'), { statusCode: 404 });
13
+ function registerListOutbox(server, ctx) {
14
+ const { CORS_CONFIG } = ctx;
24
15
 
25
16
  server.route({
26
17
  method: 'GET',
@@ -98,6 +89,10 @@ async function init(args) {
98
89
  }
99
90
  }
100
91
  });
92
+ }
93
+
94
+ function registerGetOutboxEntry(server, ctx) {
95
+ const { CORS_CONFIG, outboxEntryParams, notFound } = ctx;
101
96
 
102
97
  server.route({
103
98
  method: 'GET',
@@ -121,6 +116,12 @@ async function init(args) {
121
116
  tags: ['api', 'Outbox'],
122
117
 
123
118
  plugins: {
119
+ mcp: {
120
+ name: 'get_queued_message',
121
+ title: 'Get queued message',
122
+ description:
123
+ 'Get one message in the sending queue by the queue id that send_message, send_draft or get_outbox returned: its recipients, scheduled time, delivery attempts and the last delivery error.'
124
+ },
124
125
  openapi: {
125
126
  responses: apiResponses('Returns the queued message, including its delivery attempts and last error.', 400, 401, 403, 404, 429, 500)
126
127
  }
@@ -149,6 +150,10 @@ async function init(args) {
149
150
  }
150
151
  }
151
152
  });
153
+ }
154
+
155
+ function registerRetryOutboxEntry(server, ctx) {
156
+ const { CORS_CONFIG, outboxEntryParams, notFound } = ctx;
152
157
 
153
158
  server.route({
154
159
  method: 'POST',
@@ -209,6 +214,10 @@ async function init(args) {
209
214
  }
210
215
  }
211
216
  });
217
+ }
218
+
219
+ function registerPromoteOutboxEntry(server, ctx) {
220
+ const { CORS_CONFIG, outboxEntryParams, notFound } = ctx;
212
221
 
213
222
  server.route({
214
223
  method: 'POST',
@@ -269,6 +278,10 @@ async function init(args) {
269
278
  }
270
279
  }
271
280
  });
281
+ }
282
+
283
+ function registerDeleteOutboxEntry(server, ctx) {
284
+ const { CORS_CONFIG, outboxEntryParams } = ctx;
272
285
 
273
286
  server.route({
274
287
  method: 'DELETE',
@@ -331,4 +344,25 @@ async function init(args) {
331
344
  });
332
345
  }
333
346
 
347
+ async function init(args) {
348
+ const { server, CORS_CONFIG } = args;
349
+
350
+ // The queue ID of a message, as every per-message outbox route takes it
351
+ const outboxEntryParams = Joi.object({
352
+ queueId: Joi.string().max(100).example('d41f0423195f271f').description('Queue identifier for scheduled email').required()
353
+ }).label('OutboxEntryParams');
354
+
355
+ // What every per-message route answers for an unknown queue ID. The state refusals the
356
+ // outbox module throws (code NotFailed, ContentGone, NotDelayed) carry a 409 of their own
357
+ const notFound = () => Boom.boomify(new Error('Requested queue entry was not found'), { statusCode: 404 });
358
+
359
+ const ctx = { CORS_CONFIG, outboxEntryParams, notFound };
360
+
361
+ registerListOutbox(server, ctx);
362
+ registerGetOutboxEntry(server, ctx);
363
+ registerRetryOutboxEntry(server, ctx);
364
+ registerPromoteOutboxEntry(server, ctx);
365
+ registerDeleteOutboxEntry(server, ctx);
366
+ }
367
+
334
368
  module.exports = init;