emailengine-app 2.76.0 → 2.78.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 (165) hide show
  1. package/.github/workflows/release.yaml +24 -19
  2. package/.github/workflows/test.yml +80 -0
  3. package/.ncurc.js +14 -2
  4. package/.release-please-manifest.json +3 -0
  5. package/CHANGELOG.md +54 -0
  6. package/README.md +1 -1
  7. package/bin/emailengine.js +1 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +72 -5
  10. package/lib/account/expected-identity.js +88 -0
  11. package/lib/account.js +75 -26
  12. package/lib/address-strategies.js +18 -0
  13. package/lib/api-reference/code-samples.js +194 -0
  14. package/lib/api-reference/format.js +193 -0
  15. package/lib/api-reference/index.js +222 -0
  16. package/lib/api-reference/model.js +338 -0
  17. package/lib/api-reference/schema-tree.js +366 -0
  18. package/lib/api-routes/account-routes.js +136 -39
  19. package/lib/api-routes/behavior-notes.js +57 -0
  20. package/lib/api-routes/blocklist-routes.js +9 -9
  21. package/lib/api-routes/changes-routes.js +6 -4
  22. package/lib/api-routes/chat-routes.js +3 -3
  23. package/lib/api-routes/delivery-test-routes.js +24 -6
  24. package/lib/api-routes/export-routes.js +14 -12
  25. package/lib/api-routes/gateway-routes.js +11 -11
  26. package/lib/api-routes/license-routes.js +7 -7
  27. package/lib/api-routes/mailbox-routes.js +18 -9
  28. package/lib/api-routes/message-routes.js +55 -35
  29. package/lib/api-routes/oauth2-app-routes.js +22 -16
  30. package/lib/api-routes/outbox-routes.js +7 -7
  31. package/lib/api-routes/pubsub-routes.js +3 -3
  32. package/lib/api-routes/settings-routes.js +10 -9
  33. package/lib/api-routes/stats-routes.js +3 -3
  34. package/lib/api-routes/submit-routes.js +58 -8
  35. package/lib/api-routes/template-routes.js +13 -13
  36. package/lib/api-routes/token-routes.js +15 -10
  37. package/lib/api-routes/webhook-route-routes.js +5 -5
  38. package/lib/append-list.js +3 -14
  39. package/lib/arf-detect.js +23 -1
  40. package/lib/autodetect-imap-settings.js +40 -16
  41. package/lib/base32.js +30 -0
  42. package/lib/bounce-detect.js +182 -62
  43. package/lib/consts.js +7 -0
  44. package/lib/egress-filter.js +89 -8
  45. package/lib/email-client/base-client.js +72 -82
  46. package/lib/email-client/gmail-client.js +3 -3
  47. package/lib/email-client/imap/listing-diff.js +3 -3
  48. package/lib/email-client/imap/mailbox.js +5 -69
  49. package/lib/email-client/imap-client.js +3 -2
  50. package/lib/email-client/message-builder.js +13 -13
  51. package/lib/email-client/outlook-client.js +1 -1
  52. package/lib/enum-descriptions.js +130 -0
  53. package/lib/export.js +1 -1
  54. package/lib/gateway.js +1 -1
  55. package/lib/get-raw-email.js +1 -1
  56. package/lib/imapproxy/imap-core/lib/imap-connection.js +2 -2
  57. package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
  58. package/lib/imapproxy/imap-server.js +42 -28
  59. package/lib/imapproxy/upstream-client.js +38 -0
  60. package/lib/license-beacon.js +1 -1
  61. package/lib/llm-pre-process.js +1 -1
  62. package/lib/msgpack.js +62 -0
  63. package/lib/oauth/decode-jwt-payload.js +39 -0
  64. package/lib/oauth/outlook-identity.js +61 -0
  65. package/lib/oauth/retry-setup.js +38 -0
  66. package/lib/oauth2-apps.js +10 -4
  67. package/lib/openapi/build-document.js +318 -0
  68. package/lib/openapi/index.js +95 -0
  69. package/lib/openapi/joi-schema.js +523 -0
  70. package/lib/outbox.js +66 -3
  71. package/lib/pre-process.js +1 -1
  72. package/lib/read-env-value.js +37 -0
  73. package/lib/routes-ui.js +5 -1
  74. package/lib/schemas.js +88 -17
  75. package/lib/swagger-options.js +173 -0
  76. package/lib/templates.js +1 -1
  77. package/lib/tokens.js +70 -6
  78. package/lib/tools.js +117 -48
  79. package/lib/totp.js +67 -0
  80. package/lib/ui-routes/account-routes.js +91 -15
  81. package/lib/ui-routes/admin-config-routes.js +2 -7
  82. package/lib/ui-routes/admin-entities-routes.js +3 -0
  83. package/lib/ui-routes/auth-routes.js +6 -24
  84. package/lib/ui-routes/dashboard-routes.js +2 -26
  85. package/lib/ui-routes/reference-routes.js +198 -0
  86. package/lib/ui-routes/route-helpers.js +39 -0
  87. package/lib/utils/is-email.js +34 -0
  88. package/lib/utils/to-camel-case.js +17 -0
  89. package/lib/webhook-egress.js +37 -0
  90. package/lib/webhooks.js +1 -1
  91. package/package.json +27 -31
  92. package/prepare-bundle-deps.sh +28 -0
  93. package/release-please-config.json +11 -0
  94. package/sbom.json +1 -1
  95. package/server.js +11 -3
  96. package/static/css/flyonui.css +1 -1
  97. package/static/css/public.css +3 -0
  98. package/static/css/src/app.tailwind.css +113 -0
  99. package/static/js/app.js +69 -0
  100. package/static/js/ee-client.js +238 -8
  101. package/static/js/reference.js +1021 -0
  102. package/static/js/ui.js +61 -33
  103. package/static/licenses.html +658 -1560
  104. package/translations/README.md +64 -0
  105. package/translations/de.mo +0 -0
  106. package/translations/de.po +164 -120
  107. package/translations/en.po +200 -161
  108. package/translations/et.mo +0 -0
  109. package/translations/et.po +163 -120
  110. package/translations/fr.mo +0 -0
  111. package/translations/fr.po +163 -120
  112. package/translations/ja.mo +0 -0
  113. package/translations/ja.po +163 -120
  114. package/translations/messages.pot +84 -54
  115. package/translations/nl.mo +0 -0
  116. package/translations/nl.po +164 -120
  117. package/translations/pl.mo +0 -0
  118. package/translations/pl.po +163 -120
  119. package/views/account-identity-error.hbs +34 -0
  120. package/views/accounts/edit.hbs +1 -0
  121. package/views/accounts/register/imap.hbs +12 -2
  122. package/views/config/ai.hbs +1 -1
  123. package/views/config/document-store/chat.hbs +5 -5
  124. package/views/config/document-store/index.hbs +2 -2
  125. package/views/config/document-store/pre-processing/index.hbs +1 -1
  126. package/views/config/email-processing.hbs +1 -1
  127. package/views/config/imap-proxy.hbs +1 -1
  128. package/views/config/license.hbs +1 -1
  129. package/views/config/oauth/index.hbs +3 -3
  130. package/views/config/security.hbs +1 -1
  131. package/views/config/smtp.hbs +2 -2
  132. package/views/dashboard.hbs +1 -1
  133. package/views/layout/app.hbs +43 -8
  134. package/views/oauth-scope-error.hbs +1 -1
  135. package/views/partials/oauth_form.hbs +4 -4
  136. package/views/partials/reference/anchor-link.hbs +20 -0
  137. package/views/partials/reference/disclosure.hbs +37 -0
  138. package/views/partials/reference/nav.hbs +120 -0
  139. package/views/partials/reference/operation.hbs +127 -0
  140. package/views/partials/reference/params.hbs +20 -0
  141. package/views/partials/reference/schema-node.hbs +99 -0
  142. package/views/partials/reference/schema.hbs +19 -0
  143. package/views/partials/reference/section-heading.hbs +16 -0
  144. package/views/partials/reference/token-alert.hbs +49 -0
  145. package/views/partials/reference/try-field.hbs +31 -0
  146. package/views/partials/reference/try-it.hbs +78 -0
  147. package/views/partials/side_menu.hbs +1 -1
  148. package/views/partials/ui/badge.hbs +4 -2
  149. package/views/partials/ui/page-header.hbs +1 -1
  150. package/views/partials/ui/search-input.hbs +31 -0
  151. package/views/partials/ui/setting-ref.hbs +1 -1
  152. package/views/partials/ui/stat-card.hbs +4 -2
  153. package/views/partials/ui/tab.hbs +6 -1
  154. package/views/partials/ui/tabs.hbs +2 -2
  155. package/views/reference/index.hbs +76 -0
  156. package/views/reference/redirect.hbs +49 -0
  157. package/views/reference/tag.hbs +28 -0
  158. package/views/reference/token.hbs +49 -0
  159. package/views/tokens/index.hbs +9 -1
  160. package/views/webhooks/index.hbs +3 -3
  161. package/workers/api.js +194 -302
  162. package/workers/imap.js +1 -1
  163. package/workers/submit.js +1 -1
  164. package/workers/webhooks.js +2 -13
  165. package/views/swagger/index.hbs +0 -82
@@ -7,7 +7,7 @@ const consts = require('../consts');
7
7
  const { REDIS_PREFIX } = consts;
8
8
  const { failAction } = require('../tools');
9
9
  const { handleError } = require('./route-helpers');
10
- const { settingsSchema, settingsQuerySchema, errorResponses } = require('../schemas');
10
+ const { settingsSchema, settingsQuerySchema, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
11
11
 
12
12
  // Response variant of the settings schema. Secret values are masked and returned as booleans,
13
13
  // any setting that has never been set is returned as null, and the virtual eventTypes key is
@@ -67,8 +67,8 @@ async function init(args) {
67
67
  tags: ['api', 'Settings'],
68
68
 
69
69
  plugins: {
70
- 'hapi-swagger': {
71
- responses: errorResponses(400, 401, 403, 429, 500)
70
+ openapi: {
71
+ responses: apiResponses('Returns the values of the settings requested via query arguments. Secrets are masked.', 400, 401, 403, 429, 500)
72
72
  }
73
73
  },
74
74
 
@@ -123,8 +123,8 @@ async function init(args) {
123
123
  tags: ['api', 'Settings'],
124
124
 
125
125
  plugins: {
126
- 'hapi-swagger': {
127
- responses: errorResponses(400, 401, 403, 429, 500)
126
+ openapi: {
127
+ responses: apiResponses('Returns the list of setting keys that were updated.', 400, 401, 403, 429, 500)
128
128
  }
129
129
  },
130
130
 
@@ -201,8 +201,8 @@ async function init(args) {
201
201
  tags: ['api', 'Settings'],
202
202
 
203
203
  plugins: {
204
- 'hapi-swagger': {
205
- responses: errorResponses(400, 401, 403, 429, 500)
204
+ openapi: {
205
+ responses: apiResponses('Returns the job counts and paused state for the queue.', 400, 401, 403, 429, 500)
206
206
  }
207
207
  },
208
208
 
@@ -241,6 +241,7 @@ async function init(args) {
241
241
  .required()
242
242
  .example('notify')
243
243
  .description('Queue ID')
244
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.queueId })
244
245
  .label('QueueIdResponse'),
245
246
  jobs: Joi.object({
246
247
  active: Joi.number().integer().example(123).description('Jobs that are currently being processed'),
@@ -301,8 +302,8 @@ async function init(args) {
301
302
  tags: ['api', 'Settings'],
302
303
 
303
304
  plugins: {
304
- 'hapi-swagger': {
305
- responses: errorResponses(400, 401, 403, 429, 500)
305
+ openapi: {
306
+ responses: apiResponses('Returns the queue state after the change.', 400, 401, 403, 429, 500)
306
307
  }
307
308
  },
308
309
 
@@ -4,7 +4,7 @@ const Joi = require('joi');
4
4
  const { redis } = require('../db');
5
5
  const { failAction, getStats } = require('../tools');
6
6
  const { MAX_DAYS_STATS } = require('../consts');
7
- const { errorResponses } = require('../schemas');
7
+ const { apiResponses } = require('../schemas');
8
8
  const packageData = require('../../package.json');
9
9
 
10
10
  async function init(args) {
@@ -23,8 +23,8 @@ async function init(args) {
23
23
  tags: ['api', 'Stats'],
24
24
 
25
25
  plugins: {
26
- 'hapi-swagger': {
27
- responses: errorResponses(400, 401, 403, 429, 500)
26
+ openapi: {
27
+ responses: apiResponses('Returns counters, connection states and process information for this instance.', 400, 401, 403, 429, 500)
28
28
  }
29
29
  },
30
30
 
@@ -6,6 +6,7 @@ const { Account } = require('../account');
6
6
  const getSecret = require('../get-secret');
7
7
  const { failAction } = require('../tools');
8
8
  const { handleError } = require('./route-helpers');
9
+ const BEHAVIOR = require('./behavior-notes');
9
10
  const {
10
11
  messageReferenceSchema,
11
12
  fromAddressSchema,
@@ -17,7 +18,8 @@ const {
17
18
  settingsSchema,
18
19
  ipSchema,
19
20
  threadIdSchema,
20
- errorResponses
21
+ apiResponses,
22
+ ENUM_DESCRIPTIONS
21
23
  } = require('../schemas');
22
24
 
23
25
  // Schema fragments shared between the message submit and the draft submit routes. Joi schemas
@@ -44,7 +46,7 @@ const dsnSchema = Joi.object({
44
46
  .label('DsnReturn'),
45
47
  notify: Joi.array()
46
48
  .single()
47
- .items(Joi.string().valid('never', 'success', 'failure', 'delay').label('NotifyEntry'))
49
+ .items(Joi.string().valid('never', 'success', 'failure', 'delay').meta({ enumDescriptions: ENUM_DESCRIPTIONS.dsnNotify }).label('NotifyEntry'))
48
50
  .description('Defines the conditions under which a DSN response should be sent')
49
51
  .label('DsnNotify'),
50
52
  recipient: Joi.string().trim().empty('').email().description('The email address the DSN should be sent (ORCPT)')
@@ -97,12 +99,26 @@ async function init(args) {
97
99
  },
98
100
 
99
101
  description: 'Submit message for delivery',
100
- notes: 'Submit message for delivery. If reference message ID is provided then EmailEngine adds all headers and flags required for a reply/forward automatically.',
102
+ notes: [
103
+ 'Submit message for delivery. If reference message ID is provided then EmailEngine adds all headers and flags required for a reply/forward automatically.',
104
+ BEHAVIOR.QUEUED_DELIVERY,
105
+ BEHAVIOR.SENT_FOLDER_UPLOAD
106
+ ],
101
107
  tags: ['api', 'Submit'],
102
108
 
103
109
  plugins: {
104
- 'hapi-swagger': {
105
- responses: errorResponses(400, 401, 403, 404, 429, 500, 503)
110
+ openapi: {
111
+ 'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
112
+ responses: apiResponses(
113
+ 'Returns the queue ID the message was accepted under. Delivery happens asynchronously - a 200 means queued, not sent.',
114
+ 400,
115
+ 401,
116
+ 403,
117
+ 404,
118
+ 429,
119
+ 500,
120
+ 503
121
+ )
106
122
  }
107
123
  },
108
124
 
@@ -484,12 +500,46 @@ async function init(args) {
484
500
  },
485
501
  options: {
486
502
  description: 'Submit a stored draft for delivery',
487
- notes: 'Sends an existing draft message. The message must be a draft: stored in the Drafts folder or flagged as a draft (IMAP), carrying the DRAFT label (Gmail), or a draft message (MS Graph). Gmail and MS Graph accounts use the native draft-send call of the provider, which also files the message into the Sent Mail folder and removes the draft. For IMAP accounts the draft is downloaded, sent over SMTP, copied to the Sent Mail folder (unless disabled), and then removed from the Drafts folder.',
503
+ notes: [
504
+ 'Sends an existing draft message. The message must be a draft: stored in the Drafts folder or flagged as a draft (IMAP), carrying the DRAFT label (Gmail), or a draft message (MS Graph). Gmail and MS Graph accounts use the native draft-send call of the provider, which also files the message into the Sent Mail folder and removes the draft. For IMAP accounts the draft is downloaded, sent over SMTP, copied to the Sent Mail folder (unless disabled), and then removed from the Drafts folder.',
505
+ BEHAVIOR.QUEUED_DELIVERY,
506
+ BEHAVIOR.SENT_FOLDER_UPLOAD
507
+ ],
488
508
  tags: ['api', 'Submit'],
489
509
 
490
510
  plugins: {
491
- 'hapi-swagger': {
492
- responses: errorResponses(400, 401, 403, 404, 429, 500, 503)
511
+ openapi: {
512
+ 'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
513
+
514
+ // Every property of this payload is an optional override, so a snippet
515
+ // synthesized from the schema shows an envelope, a DSN block and a proxy
516
+ // as if they were the request. The draft already carries its recipients
517
+ // and content; the call that matters is the empty one. Hand-written
518
+ // samples lead the tab strip on the reference page and reach every other
519
+ // consumer of /swagger.json through the standard extension.
520
+ 'x-codeSamples': [
521
+ {
522
+ lang: 'bash',
523
+ label: 'Minimal',
524
+ source: [
525
+ `curl -X POST "$EMAILENGINE_URL/v1/account/example/message/AAAAAQAACnA/submit" \\`,
526
+ ` -H "Authorization: Bearer $EMAILENGINE_TOKEN" \\`,
527
+ ` -H "Content-Type: application/json" \\`,
528
+ ` -d '{}'`
529
+ ].join('\n')
530
+ }
531
+ ],
532
+
533
+ responses: apiResponses(
534
+ 'Returns the queue ID the stored draft was accepted under. Delivery happens asynchronously - a 200 means queued, not sent.',
535
+ 400,
536
+ 401,
537
+ 403,
538
+ 404,
539
+ 429,
540
+ 500,
541
+ 503
542
+ )
493
543
  }
494
544
  },
495
545
 
@@ -8,7 +8,7 @@ const Joi = require('joi');
8
8
  const { failAction } = require('../tools');
9
9
  const { handleError, throwNotFound } = require('./route-helpers');
10
10
 
11
- const { templateSchemas, accountIdSchema, errorResponses } = require('../schemas');
11
+ const { templateSchemas, accountIdSchema, apiResponses } = require('../schemas');
12
12
 
13
13
  // Template owner field shared by all template response schemas
14
14
  const templateAccountIdSchema = accountIdSchema.required().allow(null).description('Account ID. Null for public templates');
@@ -56,8 +56,8 @@ async function init(args) {
56
56
  tags: ['api', 'Templates'],
57
57
 
58
58
  plugins: {
59
- 'hapi-swagger': {
60
- responses: errorResponses(400, 401, 403, 404, 429, 500)
59
+ openapi: {
60
+ responses: apiResponses('Returns the created template.', 400, 401, 403, 404, 429, 500)
61
61
  }
62
62
  },
63
63
 
@@ -144,8 +144,8 @@ async function init(args) {
144
144
  tags: ['api', 'Templates'],
145
145
 
146
146
  plugins: {
147
- 'hapi-swagger': {
148
- responses: errorResponses(400, 401, 403, 404, 429, 500)
147
+ openapi: {
148
+ responses: apiResponses('Returns the updated template.', 400, 401, 403, 404, 429, 500)
149
149
  }
150
150
  },
151
151
 
@@ -225,8 +225,8 @@ async function init(args) {
225
225
  tags: ['api', 'Templates'],
226
226
 
227
227
  plugins: {
228
- 'hapi-swagger': {
229
- responses: errorResponses(400, 401, 403, 404, 429, 500)
228
+ openapi: {
229
+ responses: apiResponses('Returns a page of stored templates for the account.', 400, 401, 403, 404, 429, 500)
230
230
  }
231
231
  },
232
232
 
@@ -315,8 +315,8 @@ async function init(args) {
315
315
  tags: ['api', 'Templates'],
316
316
 
317
317
  plugins: {
318
- 'hapi-swagger': {
319
- responses: errorResponses(400, 401, 403, 404, 429, 500)
318
+ openapi: {
319
+ responses: apiResponses('Returns the template, including its content.', 400, 401, 403, 404, 429, 500)
320
320
  }
321
321
  },
322
322
 
@@ -385,8 +385,8 @@ async function init(args) {
385
385
  tags: ['api', 'Templates'],
386
386
 
387
387
  plugins: {
388
- 'hapi-swagger': {
389
- responses: errorResponses(400, 401, 403, 429, 500)
388
+ openapi: {
389
+ responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 429, 500)
390
390
  }
391
391
  },
392
392
 
@@ -449,8 +449,8 @@ async function init(args) {
449
449
  tags: ['api', 'Templates'],
450
450
 
451
451
  plugins: {
452
- 'hapi-swagger': {
453
- responses: errorResponses(400, 401, 403, 404, 429, 500)
452
+ openapi: {
453
+ responses: apiResponses('Returns the number of templates removed.', 400, 401, 403, 404, 429, 500)
454
454
  }
455
455
  },
456
456
 
@@ -8,7 +8,7 @@ const getSecret = require('../get-secret');
8
8
  const tokens = require('../tokens');
9
9
  const { failAction } = require('../tools');
10
10
  const { handleError } = require('./route-helpers');
11
- const { accountIdSchema, tokenRestrictionsSchema, ipSchema, tokenIdSchema, errorResponses } = require('../schemas');
11
+ const { accountIdSchema, tokenRestrictionsSchema, ipSchema, tokenIdSchema, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
12
12
 
13
13
  const tokenAccessSchema = Joi.object({
14
14
  time: Joi.date().iso().allow(null).example('2021-02-17T13:43:18.860Z').description('Last time this token was used. Null if the token has never been used'),
@@ -49,6 +49,11 @@ const tokenListItemFields = {
49
49
  scopes: tokenScopesSchema,
50
50
  restrictions: tokenRestrictionsSchema,
51
51
  created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this token was created'),
52
+ expires: Joi.date()
53
+ .iso()
54
+ .example('2021-02-17T14:43:18.860Z')
55
+ .description('The time this token stops working. Absent for tokens that never expire')
56
+ .label('TokenExpires'),
52
57
  access: tokenAccessSchema,
53
58
  id: tokenIdSchema
54
59
  };
@@ -99,8 +104,8 @@ async function init(args) {
99
104
  tags: ['api', 'Access Tokens'],
100
105
 
101
106
  plugins: {
102
- 'hapi-swagger': {
103
- responses: errorResponses(400, 401, 403, 404, 429, 500)
107
+ openapi: {
108
+ responses: apiResponses('Returns the new token value. This is the only time it is shown - store it now.', 400, 401, 403, 404, 429, 500)
104
109
  }
105
110
  },
106
111
 
@@ -124,7 +129,7 @@ async function init(args) {
124
129
  description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
125
130
 
126
131
  scopes: Joi.array()
127
- .items(Joi.string().valid('api', 'smtp', 'imap-proxy').label('TokenScope'))
132
+ .items(Joi.string().valid('api', 'smtp', 'imap-proxy').meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope }).label('TokenScope'))
128
133
  .single()
129
134
  .default(['api'])
130
135
  .required()
@@ -167,8 +172,8 @@ async function init(args) {
167
172
  tags: ['api', 'Access Tokens'],
168
173
 
169
174
  plugins: {
170
- 'hapi-swagger': {
171
- responses: errorResponses(400, 401, 403, 429, 500)
175
+ openapi: {
176
+ responses: apiResponses('Returns a deletion marker. The token stops working immediately.', 400, 401, 403, 429, 500)
172
177
  }
173
178
  },
174
179
 
@@ -219,8 +224,8 @@ async function init(args) {
219
224
  tags: ['api', 'Access Tokens'],
220
225
 
221
226
  plugins: {
222
- 'hapi-swagger': {
223
- responses: errorResponses(401, 403, 429, 500)
227
+ openapi: {
228
+ responses: apiResponses('Returns the root access tokens. Token values are never returned after creation.', 401, 403, 429, 500)
224
229
  }
225
230
  },
226
231
 
@@ -267,8 +272,8 @@ async function init(args) {
267
272
  tags: ['api', 'Access Tokens'],
268
273
 
269
274
  plugins: {
270
- 'hapi-swagger': {
271
- responses: errorResponses(400, 401, 403, 429, 500)
275
+ openapi: {
276
+ responses: apiResponses('Returns the access tokens scoped to the account.', 400, 401, 403, 429, 500)
272
277
  }
273
278
  },
274
279
 
@@ -4,7 +4,7 @@ const Joi = require('joi');
4
4
  const { webhooks: Webhooks } = require('../webhooks');
5
5
  const { failAction } = require('../tools');
6
6
  const { handleError, throwNotFound } = require('./route-helpers');
7
- const { settingsSchema, errorResponses } = require('../schemas');
7
+ const { settingsSchema, apiResponses } = require('../schemas');
8
8
 
9
9
  const webhookErrorFlagSchema = Joi.object({
10
10
  message: Joi.string().example('Request failed with status 500').description('Error message from the last failed delivery')
@@ -39,8 +39,8 @@ async function init(args) {
39
39
  tags: ['api', 'Webhooks'],
40
40
 
41
41
  plugins: {
42
- 'hapi-swagger': {
43
- responses: errorResponses(400, 401, 403, 429, 500)
42
+ openapi: {
43
+ responses: apiResponses('Returns a page of custom webhook routes.', 400, 401, 403, 429, 500)
44
44
  }
45
45
  },
46
46
 
@@ -126,8 +126,8 @@ async function init(args) {
126
126
  tags: ['api', 'Webhooks'],
127
127
 
128
128
  plugins: {
129
- 'hapi-swagger': {
130
- responses: errorResponses(400, 401, 403, 404, 429, 500)
129
+ openapi: {
130
+ responses: apiResponses('Returns the webhook route, including its filter and transform functions.', 400, 401, 403, 404, 429, 500)
131
131
  }
132
132
  },
133
133
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const msgpack = require('msgpack5')();
3
+ const msgpack = require('./msgpack');
4
4
 
5
5
  /**
6
6
  * Pushes an object to the end of a list where that list is stored in a hash field
@@ -43,19 +43,8 @@ async function list(redis, list, key) {
43
43
  return [];
44
44
  }
45
45
 
46
- return new Promise((resolve, reject) => {
47
- let decoder = msgpack.decoder({});
48
- let list = [];
49
- decoder.on('readable', () => {
50
- let data;
51
- while ((data = decoder.read()) !== null) {
52
- list.push(data);
53
- }
54
- });
55
- decoder.on('end', () => resolve(list));
56
- decoder.on('error', err => reject(err));
57
- decoder.end(contents);
58
- });
46
+ // the hash field holds a byte stream of concatenated msgpack values
47
+ return msgpack.decodeMulti(contents);
59
48
  }
60
49
 
61
50
  /**
package/lib/arf-detect.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const libmime = require('libmime');
4
4
  const addressparser = require('nodemailer/lib/addressparser');
5
+ const { toCamelCase } = require('./utils/to-camel-case');
5
6
 
6
7
  const ARF_SINGLE = [
7
8
  'feedback-type',
@@ -199,4 +200,25 @@ const arfDetect = async messageInfo => {
199
200
  return report;
200
201
  };
201
202
 
202
- module.exports = { arfDetect };
203
+ /**
204
+ * Turns an ARF report into the camelCased shape published in a complaint notification
205
+ *
206
+ * @param {Object} report - Report from arfDetect()
207
+ * @returns {Object} The arf and headers sections with camelCased keys
208
+ */
209
+ function camelCaseComplaint(report) {
210
+ let complaint = {};
211
+
212
+ for (let subKey of ['arf', 'headers']) {
213
+ for (let key of Object.keys(report[subKey])) {
214
+ if (!complaint[subKey]) {
215
+ complaint[subKey] = {};
216
+ }
217
+ complaint[subKey][toCamelCase(key)] = report[subKey][key];
218
+ }
219
+ }
220
+
221
+ return complaint;
222
+ }
223
+
224
+ module.exports = { arfDetect, camelCaseComplaint };
@@ -2,23 +2,42 @@
2
2
 
3
3
  const punycode = require('punycode.js');
4
4
  const dns = require('dns').promises;
5
- const { parseString: parseXmlCb } = require('xml2js');
6
- const util = require('util');
5
+ const { XMLParser, XMLValidator } = require('fast-xml-parser');
7
6
  const packageData = require('../package.json');
8
- const parseXml = util.promisify((xml, cb) => {
9
- parseXmlCb(
10
- xml,
11
- {
12
- explicitArray: true,
13
- normalize: true,
14
- normalizeTags: true,
15
- xmlMode: true,
16
- strict: true
17
- },
18
- cb
19
- );
7
+
8
+ // Configured to produce the same tree shape as the xml2js options this module was written
9
+ // against: lowercased tag names, child elements always as arrays (but not the root), attributes
10
+ // grouped under `$`, text of an attributed element under `_`, and entity references decoded.
11
+ // The `isArray` jpath check is what keeps the root an object: only the root's jpath has no dot.
12
+ const xmlParser = new XMLParser({
13
+ ignoreDeclaration: true,
14
+ ignoreAttributes: false,
15
+ attributesGroupName: '$',
16
+ attributeNamePrefix: '',
17
+ textNodeName: '_',
18
+ isArray: (name, jpath, isLeafNode, isAttribute) => !isAttribute && jpath.includes('.'),
19
+ transformTagName: tag => tag.toLowerCase(),
20
+ parseTagValue: false,
21
+ trimValues: true,
22
+ htmlEntities: true
20
23
  });
21
24
 
25
+ function parseXml(text) {
26
+ if (!text || !text.trim()) {
27
+ // xml2js resolved an empty document to null instead of erroring, callers check for it
28
+ return null;
29
+ }
30
+
31
+ const validation = XMLValidator.validate(text);
32
+ if (validation !== true) {
33
+ let err = new Error(`Failed to parse XML: ${validation.err.msg}`);
34
+ err.code = 'EXmlParseError';
35
+ throw err;
36
+ }
37
+
38
+ return xmlParser.parse(text);
39
+ }
40
+
22
41
  const { fetch: fetchCmd } = require('undici');
23
42
  const { httpAgent } = require('./tools');
24
43
 
@@ -178,7 +197,7 @@ async function processAutoconfigFile(email, domain, text, source) {
178
197
  } catch (err) {
179
198
  //ignore
180
199
  }
181
- let json = await parseXml(text);
200
+ let json = parseXml(text);
182
201
 
183
202
  let emailProviders = json && json.clientconfig && Array.isArray(json.clientconfig.emailprovider) ? json.clientconfig.emailprovider : [];
184
203
  let incomingServer = emailProviders
@@ -697,7 +716,11 @@ async function resolveUsingAutodiscovery(email, domain, source) {
697
716
 
698
717
  let text = await res.text();
699
718
 
700
- let json = await parseXml(text);
719
+ return await processAutodiscoverResponse(text, source);
720
+ }
721
+
722
+ async function processAutodiscoverResponse(text, source) {
723
+ let json = parseXml(text);
701
724
 
702
725
  let imap = false;
703
726
  let smtp = false;
@@ -829,6 +852,7 @@ module.exports.autodetectImapSettings = autodetectImapSettings;
829
852
  // Exposed for unit testing of the pure parsing/matching helpers. These have no
830
853
  // network side effects, so they can be exercised directly without mocking DNS or HTTP.
831
854
  module.exports.processAutoconfigFile = processAutoconfigFile;
855
+ module.exports.processAutodiscoverResponse = processAutodiscoverResponse;
832
856
  module.exports.getAppPassword = getAppPassword;
833
857
  module.exports.resolveAppPassword = resolveAppPassword;
834
858
  module.exports.escapeXml = escapeXml;
package/lib/base32.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ // RFC 4648 base32 without padding. Replaces the unmaintained base32.js package; output is
4
+ // byte-identical to its encoder for the two uses in this codebase (otpauth: URL secrets and
5
+ // IMAP proxy connection ids), which never need padding or decoding.
6
+
7
+ const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
8
+
9
+ function base32Encode(buf) {
10
+ let bits = 0;
11
+ let value = 0;
12
+ let output = '';
13
+
14
+ for (let octet of buf) {
15
+ value = (value << 8) | octet;
16
+ bits += 8;
17
+ while (bits >= 5) {
18
+ output += BASE32_ALPHABET[(value >>> (bits - 5)) & 31];
19
+ bits -= 5;
20
+ }
21
+ }
22
+
23
+ if (bits > 0) {
24
+ output += BASE32_ALPHABET[(value << (5 - bits)) & 31];
25
+ }
26
+
27
+ return output;
28
+ }
29
+
30
+ module.exports = { base32Encode };