emailengine-app 2.81.2 → 2.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/.ncurc.js +12 -11
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +27 -0
  4. package/Dockerfile +2 -0
  5. package/bin/emailengine.js +28 -18
  6. package/config/default.toml +0 -5
  7. package/config/test.toml +0 -5
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +70 -42
  10. package/getswagger.sh +0 -4
  11. package/lib/account/account-state.js +2 -110
  12. package/lib/account/expected-identity.js +1 -1
  13. package/lib/account-assignment.js +138 -1
  14. package/lib/account.js +254 -859
  15. package/lib/api-reference/index.js +2 -3
  16. package/lib/api-reference/schema-tree.js +53 -3
  17. package/lib/api-routes/account-routes.js +18 -29
  18. package/lib/api-routes/blocklist-routes.js +2 -2
  19. package/lib/api-routes/bull-board-routes.js +1 -6
  20. package/lib/api-routes/export-routes.js +2 -22
  21. package/lib/api-routes/gateway-routes.js +5 -14
  22. package/lib/api-routes/index.js +1 -13
  23. package/lib/api-routes/mailbox-routes.js +2 -7
  24. package/lib/api-routes/mcp-oauth-routes.js +2 -1
  25. package/lib/api-routes/mcp-routes.js +7 -7
  26. package/lib/api-routes/message-routes.js +40 -235
  27. package/lib/api-routes/mint-bounds.js +110 -0
  28. package/lib/api-routes/oauth2-app-routes.js +23 -32
  29. package/lib/api-routes/operation-impact.js +1 -1
  30. package/lib/api-routes/outbox-routes.js +2 -2
  31. package/lib/api-routes/permission-map.js +1 -7
  32. package/lib/api-routes/route-helpers.js +11 -5
  33. package/lib/api-routes/settings-routes.js +19 -19
  34. package/lib/api-routes/stats-routes.js +1 -1
  35. package/lib/api-routes/submit-routes.js +17 -18
  36. package/lib/api-routes/template-routes.js +4 -9
  37. package/lib/api-routes/token-routes.js +27 -5
  38. package/lib/api-token-scheme.js +71 -0
  39. package/lib/arf-detect.js +33 -6
  40. package/lib/auth-token.js +44 -24
  41. package/lib/autodetect-imap-settings.js +163 -123
  42. package/lib/bounce-detect.js +25 -16
  43. package/lib/calendar-event.js +78 -0
  44. package/lib/consts.js +42 -5
  45. package/lib/create-imap-client.js +24 -0
  46. package/lib/db.js +76 -11
  47. package/lib/delivery-error.js +2 -1
  48. package/lib/egress-fetch.js +54 -3
  49. package/lib/egress-filter.js +11 -0
  50. package/lib/email-client/api-retry.js +147 -0
  51. package/lib/email-client/base-client.js +377 -523
  52. package/lib/email-client/gmail/gmail-api.js +38 -125
  53. package/lib/email-client/gmail/send-request.js +1 -1
  54. package/lib/email-client/gmail-client.js +76 -50
  55. package/lib/email-client/imap/mailbox.js +158 -324
  56. package/lib/email-client/imap/stale-view.js +109 -0
  57. package/lib/email-client/imap/subconnection.js +46 -9
  58. package/lib/email-client/imap/sync-operations.js +5 -37
  59. package/lib/email-client/imap-client.js +188 -64
  60. package/lib/email-client/message-builder.js +9 -14
  61. package/lib/email-client/notification-handler.js +5 -219
  62. package/lib/email-client/outlook/graph-api.js +147 -126
  63. package/lib/email-client/outlook/send-request.js +10 -4
  64. package/lib/email-client/outlook-client.js +194 -397
  65. package/lib/email-client/smtp-pool-manager.js +3 -2
  66. package/lib/encrypt.js +184 -19
  67. package/lib/enum-descriptions.js +1 -2
  68. package/lib/export.js +133 -39
  69. package/lib/gateway.js +20 -6
  70. package/lib/get-raw-email.js +26 -44
  71. package/lib/handlebars-helpers.js +31 -10
  72. package/lib/imap-proxy-auth.js +13 -29
  73. package/lib/imapproxy/imap-core/README.md +1 -0
  74. package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
  75. package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
  76. package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
  77. package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
  78. package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
  79. package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
  80. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
  81. package/lib/imapproxy/imap-server.js +17 -177
  82. package/lib/imapproxy/proxy-handoff.js +235 -0
  83. package/lib/imapproxy/response-error.js +33 -0
  84. package/lib/imapproxy/upstream-client.js +2 -2
  85. package/lib/license-beacon.js +3 -9
  86. package/lib/llm-pre-process.js +182 -43
  87. package/lib/logger.js +1 -1
  88. package/lib/lua/ee-export-queue-add.lua +39 -0
  89. package/lib/lua/ee-get-idempotency.lua +15 -3
  90. package/lib/lua/ee-release-attempts.lua +23 -0
  91. package/lib/lua/ee-reserve-attempts.lua +42 -0
  92. package/lib/lua/h-set-bigger.lua +12 -2
  93. package/lib/lua/s-list-accounts.lua +6 -3
  94. package/lib/mcp/index.js +1 -2
  95. package/lib/mcp/listen.js +221 -18
  96. package/lib/mcp/oauth.js +44 -5
  97. package/lib/mcp/resources.js +8 -2
  98. package/lib/mcp/tools.js +13 -0
  99. package/lib/message-port-stream.js +64 -6
  100. package/lib/oauth/external-account-signer.js +16 -13
  101. package/lib/oauth/gmail.js +22 -20
  102. package/lib/oauth/outlook.js +19 -16
  103. package/lib/oauth/pubsub/google.js +38 -2
  104. package/lib/oauth/scope-checker.js +4 -7
  105. package/lib/oauth/verify-app.js +2 -2
  106. package/lib/oauth2-apps.js +139 -44
  107. package/lib/openapi/build-document.js +1 -1
  108. package/lib/openapi/joi-schema.js +78 -9
  109. package/lib/parse-message.js +21 -0
  110. package/lib/payload-examples-webhooks.json +4 -7
  111. package/lib/pbkdf2-phc.js +101 -0
  112. package/lib/privileged-settings.js +0 -14
  113. package/lib/rate-limit.js +54 -15
  114. package/lib/redis-scan-delete.js +56 -29
  115. package/lib/redis-url.js +3 -1
  116. package/lib/respawn-backoff.js +5 -4
  117. package/lib/response-stream.js +25 -4
  118. package/lib/rewrite-text-nodes.js +27 -40
  119. package/lib/routes-ui.js +0 -5
  120. package/lib/schemas.js +122 -242
  121. package/lib/sentry.js +21 -5
  122. package/lib/settings.js +58 -59
  123. package/lib/smtp-auth.js +6 -2
  124. package/lib/smtp-message-processor.js +28 -7
  125. package/lib/sso.js +7 -3
  126. package/lib/stream-encrypt.js +14 -13
  127. package/lib/swagger-options.js +3 -1
  128. package/lib/tls/provision.js +69 -3
  129. package/lib/tls/store.js +14 -1
  130. package/lib/tools.js +113 -52
  131. package/lib/totp.js +16 -1
  132. package/lib/ui-routes/account-routes.js +27 -63
  133. package/lib/ui-routes/admin-config-routes.js +111 -134
  134. package/lib/ui-routes/admin-entities-routes.js +101 -191
  135. package/lib/ui-routes/ai-options.js +104 -0
  136. package/lib/ui-routes/auth-routes.js +98 -18
  137. package/lib/ui-routes/export-routes.js +3 -23
  138. package/lib/ui-routes/internals-routes.js +12 -9
  139. package/lib/ui-routes/network-config-routes.js +8 -18
  140. package/lib/ui-routes/oauth-config-routes.js +80 -214
  141. package/lib/ui-routes/route-helpers.js +40 -44
  142. package/lib/ui-routes/unsubscribe-routes.js +2 -2
  143. package/lib/utils/decode-headers.js +32 -5
  144. package/lib/utils/header-map.js +62 -1
  145. package/lib/utils/network.js +2 -0
  146. package/lib/web-safe-html.js +77 -4
  147. package/lib/webhook-request.js +9 -1
  148. package/lib/webhook-routing.js +27 -1
  149. package/lib/webhooks.js +120 -43
  150. package/lib/worker-rpc-error.js +43 -2
  151. package/list-generate.js +13 -2
  152. package/package.json +33 -41
  153. package/sbom.json +1 -1
  154. package/scripts/refresh-test-tokens.js +42 -14
  155. package/server.js +317 -289
  156. package/static/css/flyonui.css +1 -1
  157. package/static/css/src/app.tailwind.css +7 -8
  158. package/static/js/ee-client.js +145 -70
  159. package/static/js/ui.js +350 -154
  160. package/static/licenses.html +434 -1835
  161. package/translations/messages.pot +97 -97
  162. package/views/accounts/browse.hbs +10 -4
  163. package/views/config/ai.hbs +49 -41
  164. package/views/config/oauth/app.hbs +2 -1
  165. package/views/dashboard.hbs +18 -16
  166. package/views/layout/app.hbs +0 -22
  167. package/views/layout/login.hbs +2 -1
  168. package/views/partials/filter_editor_js.hbs +4 -3
  169. package/views/partials/side_menu.hbs +0 -4
  170. package/views/partials/ui/account-picker.hbs +6 -32
  171. package/views/partials/ui/model-picker.hbs +31 -0
  172. package/views/partials/ui/pagination.hbs +6 -1
  173. package/views/partials/ui/picker.hbs +47 -0
  174. package/views/unsubscribe.hbs +1 -1
  175. package/workers/api.js +20 -20
  176. package/workers/export.js +55 -60
  177. package/workers/imap.js +126 -46
  178. package/workers/submit.js +3 -1
  179. package/workers/webhooks.js +46 -27
  180. package/.githooks/pre-commit +0 -80
  181. package/.github/CODE_OF_CONDUCT.md +0 -76
  182. package/.github/contributing.md +0 -17
  183. package/.github/dependabot.yml +0 -22
  184. package/.github/docker-smoke-test.sh +0 -61
  185. package/.github/workflows/deploy.yml +0 -215
  186. package/.github/workflows/e2e.yml +0 -55
  187. package/.github/workflows/release.yaml +0 -217
  188. package/.github/workflows/test.yml +0 -307
  189. package/lib/api-routes/chat-routes.js +0 -535
  190. package/lib/document-store.js +0 -75
  191. package/lib/es.js +0 -757
  192. package/lib/generate-text-preview.js +0 -61
  193. package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
  194. package/lib/pre-process.js +0 -196
  195. package/lib/threads.js +0 -155
  196. package/lib/ui-routes/document-store-routes.js +0 -806
  197. package/playwright.config.js +0 -47
  198. package/views/config/document-store/chat.hbs +0 -286
  199. package/views/config/document-store/index.hbs +0 -146
  200. package/views/config/document-store/mappings/index.hbs +0 -108
  201. package/views/config/document-store/mappings/new.hbs +0 -68
  202. package/views/config/document-store/pre-processing/index.hbs +0 -103
  203. package/views/partials/document_store_header.hbs +0 -30
  204. package/workers/documents.js +0 -1128
@@ -291,28 +291,6 @@
291
291
  {{/unless}}
292
292
  {{/unless}}
293
293
 
294
- {{!-- Deprecated Document Store removal notice. Shown (and not dismissible) on every admin
295
- page whenever the Document Store is genuinely active (feature gate on + setting on).
296
- Rendered as a SOLID error alert (not a stat-card) so it stands out from the page's
297
- white cards. Removal date is 2026-10-01. --}}
298
- {{#if showDocumentStore}}
299
- <div class="alert alert-error border-2 shadow-lg mb-6 flex items-start gap-4" role="alert">
300
- <span class="icon-[tabler--alert-triangle] size-8 shrink-0 mt-0.5"></span>
301
- <div class="grow">
302
- <h4 class="text-lg font-bold mb-2">Document Store is being removed</h4>
303
- <p class="mb-2">This instance still has the deprecated <strong>Document Store</strong>
304
- enabled. Starting <strong>October 1, 2026</strong>, the Document Store will be removed
305
- from EmailEngine releases. After that, syncing emails to ElasticSearch and the related
306
- endpoints (chat with email, unified search) will no longer be available.</p>
307
- <p class="mb-3">If you want to keep using the Document Store, <strong>do not upgrade</strong>
308
- this EmailEngine instance beyond the last release that still includes it. Be aware that
309
- such a frozen version will <strong>not receive security updates</strong>, so continuing
310
- to run it is entirely at your own risk.</p>
311
- {{> ui/btn href="/admin/config/document-store" variant="neutral" size="sm" icon="icon-[tabler--arrow-right]" label="Review Document Store settings"}}
312
- </div>
313
- </div>
314
- {{/if}}
315
-
316
294
  {{{content}}}
317
295
 
318
296
  </div>
@@ -23,7 +23,8 @@
23
23
  login form never emits this and no user input reaches the string. Why that page navigates
24
24
  itself instead of the server answering a redirect is the whole story in the view. --}}
25
25
  {{#if ssoRedirectUrl}}
26
- <script data-cfasync="false" nonce="{{cspNonce}}">window.location.replace('{{ssoRedirectUrl}}');</script>
26
+ <meta name="ee-sso-redirect" content="{{ssoRedirectUrl}}">
27
+ <script data-cfasync="false" nonce="{{cspNonce}}">window.location.replace(document.querySelector('meta[name="ee-sso-redirect"]').content);</script>
27
28
  {{/if}}
28
29
 
29
30
  {{> head_assets}}
@@ -1,8 +1,8 @@
1
1
  {{!--
2
2
  Shared filter/map editor test machinery: the ACE editors, the evaluation web
3
3
  worker, live filter-result painting and the "set test payload" modal. Used by
4
- the webhook routing pages (via webhooks_editor_functions), the AI pre-filter
5
- page and the Document Store pre-processing page.
4
+ the webhook routing pages (via webhooks_editor_functions) and the AI pre-filter
5
+ page.
6
6
  Hash params (all optional):
7
7
  hasMap - truthy to include the output-mapping editor/preview pair
8
8
  and the map evaluation chain
@@ -30,6 +30,7 @@
30
30
  <input type="hidden" id="examplePayloadsJson" value="{{examplePayloadsJson}}">
31
31
  <input type="hidden" id="scriptEnvJson" value="{{scriptEnvJson}}">
32
32
  <input type="hidden" id="defaultTestPayloadJson" value="{{defaultTestPayload}}">
33
+ <input type="hidden" id="filterEditorFormId" value="{{#if formId}}{{formId}}{{else}}edit-form{{/if}}">
33
34
 
34
35
  {{#> ui/modal id="setPayloadModal" title=(when modalTitle modalTitle "Set test payload") dialogClass="max-w-3xl"}}
35
36
  <div class="modal-body">
@@ -229,7 +230,7 @@ the *Set test payload* button to change the filter payload.`);
229
230
  editorMapPreview.clearSelection(1);
230
231
  {{/if}}
231
232
 
232
- document.getElementById('{{#if formId}}{{formId}}{{else}}edit-form{{/if}}').addEventListener('submit', () => {
233
+ document.getElementById(document.getElementById('filterEditorFormId').value).addEventListener('submit', () => {
233
234
  document.getElementById('fn-content-element').value = JSON.stringify(editorFn.getValue());
234
235
  {{#if hasMap}}
235
236
  document.getElementById('map-content-element').value = JSON.stringify(editorMap.getValue());
@@ -34,10 +34,6 @@
34
34
  {{> ui/menu-item href="/admin/config/imap-proxy" label="IMAP Proxy" active=menuConfigImapProxy}}
35
35
  {{> ui/menu-item href="/admin/config/branding" label="Branding" active=menuConfigBranding}}
36
36
  {{> ui/menu-item href="/admin/config/logging" label="Logging" active=menuConfigLogging}}
37
-
38
- {{#if showDocumentStore}}
39
- {{> ui/menu-item href="/admin/config/document-store" label="Document Store" active=menuConfigDocumentStore}}
40
- {{/if}}
41
37
  {{/ui/menu-section}}
42
38
 
43
39
  {{> ui/menu-item href="/admin/config/license" label="License" icon="icon-[tabler--license] size-4.5"
@@ -6,17 +6,13 @@
6
6
  part of an id, a name or an address, pick from the suggestions, and the box is replaced by a
7
7
  card naming the account that was picked, with a button to clear it again.
8
8
 
9
- The posted value stays a plain account id in a hidden input carrying the given id, so a page
10
- that already reads or watches that field keeps working - static/js/ui.js fires `input` and
11
- `change` on it whenever the choice changes, exactly as typing into a text field would.
12
-
13
9
  Suggestions come from GET /admin/accounts/suggestions; the card is painted by ui.js from the
14
10
  same JSON shape, so a server-rendered selection and a just-picked one cannot look different.
15
11
 
16
12
  Hand-rolled rather than FlyonUI's HSComboBox, which the vendored bundle does carry: that
17
13
  component renders items from template strings, and every field on a row here (a display name,
18
14
  an address) arrives from a mail provider, so the rows are built as text nodes instead. The
19
- hidden-id-plus-card shape is not one of its modes either.
15
+ hidden-id-plus-card shape is not one of its modes either. The markup is ui/picker.
20
16
  {{> ui/account-picker id="account" label="Account" value=values.account selected=selectedAccount}}
21
17
  Params:
22
18
  id - hidden input id, also the default posted name and what page scripts read (required)
@@ -30,30 +26,8 @@
30
26
  account looks like)
31
27
  placeholder - search box placeholder (optional)
32
28
  --}}
33
- <div class="w-full">
34
- {{#if label}}
35
- <label class="label-text" for="{{id}}-search">{{label}}</label>
36
- {{/if}}
37
- <div data-account-picker data-input="{{id}}" {{#if selected}}data-selected="{{json selected}}" {{/if}}>
38
- <input type="hidden" id="{{id}}" name="{{#if name}}{{name}}{{else}}{{id}}{{/if}}" {{#if value}}value="{{value}}" {{/if}}>
39
-
40
- {{!-- The picked account. Empty until ui.js paints it, and hidden whenever nothing is picked. --}}
41
- <div class="ee-account-picker-card hidden" data-picker-card></div>
42
-
43
- <div class="ee-account-picker-search" data-picker-search>
44
- <div class="input{{#if error}} is-invalid{{/if}}">
45
- <span class="icon-[tabler--search] text-base-content/60 my-auto me-2 size-4 shrink-0"></span>
46
- <input type="text" class="grow" id="{{id}}-search" role="combobox" aria-expanded="false" aria-autocomplete="list"
47
- aria-controls="{{id}}-results" autocomplete="off" data-lpignore="true"
48
- placeholder="{{#if placeholder}}{{placeholder}}{{else}}Search by name, address or account id{{/if}}">
49
- </div>
50
- <div class="ee-account-picker-results hidden" id="{{id}}-results" role="listbox" data-picker-results></div>
51
- </div>
52
- </div>
53
- {{#if error}}
54
- <span class="helper-text text-error">{{error}}</span>
55
- {{/if}}
56
- {{#if hint}}
57
- <span class="helper-text">{{hint}}</span>
58
- {{/if}}
59
- </div>
29
+ {{#if placeholder}}
30
+ {{> ui/picker kind="account" id=id name=name label=label hint=hint error=error value=value selected=selected placeholder=placeholder}}
31
+ {{else}}
32
+ {{> ui/picker kind="account" id=id name=name label=label hint=hint error=error value=value selected=selected placeholder="Search by name, address or account id"}}
33
+ {{/if}}
@@ -0,0 +1,31 @@
1
+ {{!--
2
+ ui/model-picker - the "which model" field of the AI page.
3
+
4
+ A provider lists dozens of models, most of them unsuited to reading mail, and a <select> of
5
+ bare names was a wall nobody could choose from. This is the account picker's shape over a list
6
+ the page already holds: type any part of a name, an id or a note ("gpt 6", "6 luna" and
7
+ "cheap" all work, matched term by term and ranked with the id counting most), pick from the
8
+ suggestions, and the box is replaced by a card naming the model, what it is for, and its id.
9
+ Every entry carries a one-line note and the recommended ones are listed first, so the sane
10
+ choice is also the easy one. The first entry is "Default", which follows the library's
11
+ built-in model across upgrades.
12
+
13
+ The list travels in the data-models attribute and can be replaced after a refresh with
14
+ window.uiModelPickerSetModels(); the card is painted from the entry the value names. The
15
+ markup is ui/picker.
16
+ {{> ui/model-picker id="openAiModel" models=openAiModels value=values.openAiModel}}
17
+ Params:
18
+ id - hidden input id, also the default posted name and what page scripts read (required)
19
+ name - posted field name (defaults to id)
20
+ label - field label (optional)
21
+ hint - muted helper text under the control (optional)
22
+ error - validation error message (optional)
23
+ value - current model name, empty for the default (optional)
24
+ models - the list: {id, name, description, recommended} entries, "Default" first (required)
25
+ placeholder - search box placeholder (optional)
26
+ --}}
27
+ {{#if placeholder}}
28
+ {{> ui/picker kind="model" id=id name=name label=label hint=hint error=error value=value models=models placeholder=placeholder}}
29
+ {{else}}
30
+ {{> ui/picker kind="model" id=id name=name label=label hint=hint error=error value=value models=models placeholder="Search models by name or id"}}
31
+ {{/if}}
@@ -8,7 +8,8 @@
8
8
  showPaging - falsy when there is only one page; suppresses all output
9
9
  prevPage - URL of the previous page, falsy when on the first page
10
10
  nextPage - URL of the next page, falsy when on the last page
11
- pageLinks - array of { url, title, active }
11
+ pageLinks - array of { url, title, active }, or { gap: true } where pages are
12
+ left out (windowedPageLinks in lib/ui-routes/route-helpers.js)
12
13
  --}}
13
14
  {{#if showPaging}}
14
15
  <div class="card-footer border-base-content/10 border-t px-6 py-4">
@@ -20,7 +21,11 @@
20
21
  {{/if}}
21
22
 
22
23
  {{#each pageLinks}}
24
+ {{#if gap}}
25
+ <span class="join-item btn btn-soft btn-sm btn-disabled" aria-hidden="true">&hellip;</span>
26
+ {{else}}
23
27
  <a class="join-item btn btn-sm {{#if active}}btn-primary{{else}}btn-soft{{/if}}" href="{{url}}">{{title}}</a>
28
+ {{/if}}
24
29
  {{/each}}
25
30
 
26
31
  {{#if nextPage}}
@@ -0,0 +1,47 @@
1
+ {{!--
2
+ ui/picker - a search box that becomes a card: the shared markup behind ui/account-picker and
3
+ ui/model-picker, which are the two faces a page asks for by name. static/js/ui.js wires every
4
+ [data-picker] element with the adapter its kind names (see uiPickerAdapters there).
5
+
6
+ The posted value stays a plain id in a hidden input carrying the given id, so a page that
7
+ already reads or watches that field keeps working - ui.js fires `input` and `change` on it
8
+ whenever the choice changes, exactly as typing into a text field would.
9
+
10
+ Params:
11
+ kind - "account" or "model" (required)
12
+ id - hidden input id, also the default posted name and what page scripts read (required)
13
+ name - posted field name (defaults to id)
14
+ label - field label (optional)
15
+ hint - muted helper text under the control (optional)
16
+ error - validation error message (optional)
17
+ value - current id (optional)
18
+ selected - the entry for `value`, when the server resolved it (optional)
19
+ models - the list for the model kind: {id, name, description, recommended} entries
20
+ placeholder - search box placeholder (required; the wrappers supply the default of their kind)
21
+ --}}
22
+ <div class="w-full">
23
+ {{#if label}}
24
+ <label class="label-text" for="{{id}}-search">{{label}}</label>
25
+ {{/if}}
26
+ <div data-picker="{{kind}}" data-input="{{id}}" {{#if models}}data-models="{{json models}}" {{/if}}{{#if selected}}data-selected="{{json selected}}" {{/if}}>
27
+ <input type="hidden" id="{{id}}" name="{{#if name}}{{name}}{{else}}{{id}}{{/if}}" {{#if value}}value="{{value}}" {{/if}}>
28
+
29
+ {{!-- The picked entry. Empty until ui.js paints it, and hidden whenever nothing is picked. --}}
30
+ <div class="ee-account-picker-card hidden" data-picker-card></div>
31
+
32
+ <div class="ee-account-picker-search" data-picker-search>
33
+ <div class="input{{#if error}} is-invalid{{/if}}">
34
+ <span class="icon-[tabler--search] text-base-content/60 my-auto me-2 size-4 shrink-0"></span>
35
+ <input type="text" class="grow" id="{{id}}-search" role="combobox" aria-expanded="false" aria-autocomplete="list"
36
+ aria-controls="{{id}}-results" autocomplete="off" data-lpignore="true" placeholder="{{placeholder}}">
37
+ </div>
38
+ <div class="ee-account-picker-results hidden" id="{{id}}-results" role="listbox" data-picker-results></div>
39
+ </div>
40
+ </div>
41
+ {{#if error}}
42
+ <span class="helper-text text-error">{{error}}</span>
43
+ {{/if}}
44
+ {{#if hint}}
45
+ <span class="helper-text">{{hint}}</span>
46
+ {{/if}}
47
+ </div>
@@ -9,7 +9,7 @@ the "subscription resumed" state. --}}
9
9
  <p>{{_ "Your email address was unsubscribed." templateLocale }}</p>
10
10
 
11
11
  <p>{{_ "Was this a mistake? Click <a%s>here</a> to re-subscribe." templateLocale
12
- " id='resubscribe-link' href='#' class='ee-link'"}}</p>
12
+ (markup " id='resubscribe-link' href='#' class='ee-link'")}}</p>
13
13
 
14
14
  {{!-- autofocus on the dialog keeps showModal() from focusing (and drawing a
15
15
  focus ring on) the corner close button --}}
package/workers/api.js CHANGED
@@ -69,7 +69,7 @@ const { buildRetrySetup } = require('../lib/oauth/retry-setup');
69
69
  const { matchesExpectedIdentity, pendingSetupExpectation, resolveExpectedIdentity } = require('../lib/account/expected-identity');
70
70
 
71
71
  const handlebars = require('handlebars');
72
- const AuthBearer = require('hapi-auth-bearer-token');
72
+ const { apiTokenScheme, SCHEME_NAME: API_TOKEN_SCHEME } = require('../lib/api-token-scheme');
73
73
  const tokens = require('../lib/tokens');
74
74
  const tokenPermissions = require('../lib/token-permissions');
75
75
  const { mcpFeatureEnabled } = require('../lib/mcp');
@@ -78,12 +78,11 @@ const tokenAuditLog = require('../lib/token-audit-log');
78
78
  const { routeGrant, perRequestSurfaceAdmits, sessionTokenAdmits } = require('../lib/api-routes/permission-map');
79
79
  const { mcpOptions } = require('../lib/api-routes/route-metadata');
80
80
 
81
- const { redis, documentsQueue } = require('../lib/db');
81
+ const { redis } = require('../lib/db');
82
82
  const { Account } = require('../lib/account');
83
83
  const settings = require('../lib/settings');
84
84
 
85
85
  const getSecret = require('../lib/get-secret');
86
- const { getESClient, documentStoreFeatureEnabled } = require('../lib/document-store');
87
86
 
88
87
  const sso = require('../lib/sso');
89
88
 
@@ -110,7 +109,8 @@ const {
110
109
  DEFAULT_EENGINE_TIMEOUT,
111
110
  DEFAULT_MAX_ATTACHMENT_SIZE,
112
111
  MAX_FORM_TTL,
113
- NONCE_BYTES
112
+ NONCE_BYTES,
113
+ LAST_DOCUMENT_STORE_VERSION
114
114
  } = consts;
115
115
 
116
116
  const registerApiRoutes = require('../lib/api-routes');
@@ -590,7 +590,6 @@ const init = async () => {
590
590
  }
591
591
 
592
592
  let assertPreconditionResult;
593
- server.decorate('toolkit', 'getESClient', async (...args) => await getESClient(...args));
594
593
 
595
594
  // A read-only view of the certificate store for routes. Ordering a certificate is the
596
595
  // reconciler's job - it owns the state a page follows, the retry pacing and the listener
@@ -787,10 +786,10 @@ const init = async () => {
787
786
  cors: !!CORS_CONFIG
788
787
  };
789
788
 
790
- await server.register(AuthBearer);
789
+ server.auth.scheme(API_TOKEN_SCHEME, apiTokenScheme);
791
790
 
792
791
  // Authentication for API calls
793
- server.auth.strategy('api-token', 'bearer-access-token', {
792
+ server.auth.strategy('api-token', API_TOKEN_SCHEME, {
794
793
  allowQueryToken: true, // optional, false by default
795
794
  validate: async (request, token /*, h*/) => {
796
795
  let disableTokens = await settings.get('disableTokens');
@@ -885,7 +884,7 @@ const init = async () => {
885
884
  tokenData = await tokens.get(token, false, { log: !request.app.mcpInternal, remoteAddress: request.app.ip });
886
885
  } catch (err) {
887
886
  // A thrown Boom reaches the client the way the scope and permission refusals
888
- // below do (hapi-auth-bearer-token does not catch it), so the reason travels as a
887
+ // below do (the api-token scheme does not catch it), so the reason travels as a
889
888
  // machine-readable code - UnknownToken, ExpiredToken, InvalidToken - while the
890
889
  // message stays the generic one the scheme itself would have sent. The scheme
891
890
  // name keeps the WWW-Authenticate header the plugin's own refusal carries.
@@ -2818,7 +2817,6 @@ const init = async () => {
2818
2817
  server,
2819
2818
  call,
2820
2819
  notify,
2821
- documentsQueue,
2822
2820
  metrics,
2823
2821
  CORS_CONFIG,
2824
2822
  FLAG_SORT_ORDER,
@@ -2826,7 +2824,6 @@ const init = async () => {
2826
2824
  MAX_ATTACHMENT_SIZE,
2827
2825
  MAX_BODY_SIZE,
2828
2826
  MAX_PAYLOAD_TIMEOUT,
2829
- documentStoreFeatureEnabled,
2830
2827
  mcpFeatureEnabled,
2831
2828
  oauth2Schema,
2832
2829
  imapSchema,
@@ -2871,7 +2868,10 @@ const init = async () => {
2871
2868
  layoutPath: './views/layout',
2872
2869
  partialsPath: './views/partials',
2873
2870
 
2874
- isCached: false,
2871
+ // Uncached, vision re-reads and re-registers every partial with synchronous fs calls on
2872
+ // each render, blocking the worker that also serves /v1. Only development wants live
2873
+ // template edits.
2874
+ isCached: process.env.NODE_ENV !== 'development',
2875
2875
 
2876
2876
  async context(request) {
2877
2877
  // The three reads are independent, and this runs on every admin page render. The
@@ -2911,7 +2911,11 @@ const init = async () => {
2911
2911
  tract,
2912
2912
  templateHeader: embeddedTemplateHeader,
2913
2913
  templateHtmlHead: embeddedTemplateHtmlHead,
2914
- documentStoreEnabled: showDocumentStore,
2914
+ // The Document Store was removed in 2.82.0. The setting that switched it on is
2915
+ // read raw off the settings hash (it is no longer in the settings schema), so an
2916
+ // instance upgraded with the feature still on is told where it went instead of
2917
+ // losing it quietly
2918
+ documentStoreEnabled: documentStoreRemoved,
2915
2919
  serviceUrl,
2916
2920
  language,
2917
2921
  locale,
@@ -2923,10 +2927,6 @@ const init = async () => {
2923
2927
  let systemAlerts = [];
2924
2928
  let authData;
2925
2929
 
2926
- // Deprecated Document Store: enabled in settings but unavailable because EmailEngine
2927
- // was not started with the document store gate (--documentStore.enabled / EENGINE_DOCUMENT_STORE_ENABLED).
2928
- let documentStoreUnavailable = !documentStoreFeatureEnabled && !!showDocumentStore;
2929
-
2930
2930
  switch (request.auth.artifacts && request.auth.artifacts.provider) {
2931
2931
  case 'okta': {
2932
2932
  let profile = request.auth.artifacts.profile || {};
@@ -3049,12 +3049,12 @@ const init = async () => {
3049
3049
  });
3050
3050
  }
3051
3051
 
3052
- if (documentStoreUnavailable) {
3052
+ if (documentStoreRemoved) {
3053
3053
  systemAlerts.push({
3054
3054
  url: '/admin',
3055
3055
  level: 'danger',
3056
3056
  icon: 'icon-[tabler--database]',
3057
- message: `The Document Store is enabled in settings but unavailable. Start EmailEngine with the document store gate to use it, or disable the setting.`
3057
+ message: `The Document Store has been removed from EmailEngine. Downgrade to v${LAST_DOCUMENT_STORE_VERSION} if you still need it.`
3058
3058
  });
3059
3059
  }
3060
3060
 
@@ -3091,8 +3091,8 @@ const init = async () => {
3091
3091
  embeddedTemplateHeader,
3092
3092
  embeddedTemplateHtmlHead,
3093
3093
  currentYear: new Date().getFullYear(),
3094
- showDocumentStore: documentStoreFeatureEnabled && showDocumentStore,
3095
- documentStoreUnavailable,
3094
+ documentStoreRemoved,
3095
+ lastDocumentStoreVersion: LAST_DOCUMENT_STORE_VERSION,
3096
3096
  updateBrowserInfo: !serviceUrl || !language || !timezone,
3097
3097
 
3098
3098
  // Suppress large banner warnings when EENGINE_DISABLE_SETUP_WARNINGS is set
package/workers/export.js CHANGED
@@ -5,9 +5,6 @@ const { parentPort } = require('worker_threads');
5
5
  const packageData = require('../package.json');
6
6
  const config = require('@zone-eu/wild-config');
7
7
  const logger = require('../lib/logger');
8
- const fs = require('fs');
9
- const zlib = require('zlib');
10
- const { pipeline } = require('stream');
11
8
 
12
9
  const {
13
10
  REDIS_PREFIX,
@@ -30,13 +27,15 @@ const {
30
27
  isExportLimitReached,
31
28
  parseActiveEntry,
32
29
  getExportKey,
30
+ exportFilePath,
31
+ openExportOutput,
33
32
  ACTIVE_EXPORTS_KEY
34
33
  } = require('../lib/export');
35
34
 
36
35
  const { initSentry } = require('../lib/sentry');
37
36
  initSentry('export');
38
37
 
39
- const { redis, queueConf } = require('../lib/db');
38
+ const { redis, queueConf, logBullErrors } = require('../lib/db');
40
39
  const { Worker } = require('bullmq');
41
40
  const { Account } = require('../lib/account');
42
41
  const getSecret = require('../lib/get-secret');
@@ -359,7 +358,8 @@ async function indexFolder(accountObject, account, exportId, folderPath, startDa
359
358
 
360
359
  async function exportMessages(job, exportData) {
361
360
  const { account, exportId } = job.data;
362
- const { filePath } = exportData;
361
+ // Derived from the id like every other reader of the record, never the stored path as such
362
+ const filePath = exportFilePath(exportId, exportData);
363
363
  const includeAttachments = exportData.includeAttachments === '1';
364
364
  const textType = exportData.textType || '*';
365
365
  const rawMaxBytes = Number(exportData.maxBytes);
@@ -377,31 +377,19 @@ async function exportMessages(job, exportData) {
377
377
  timeout: EXPORT_TIMEOUT
378
378
  });
379
379
 
380
- const gzipStream = zlib.createGzip();
381
- const fileStream = fs.createWriteStream(filePath, { mode: 0o600 });
382
-
383
- let encryptStream = null;
384
- let streamError = null;
385
-
386
- const secret = isEncrypted ? await getSecret() : null;
387
-
388
- const streams = [gzipStream];
389
- if (secret) {
390
- const { createEncryptStream } = require('../lib/stream-encrypt');
391
- encryptStream = await createEncryptStream(secret);
392
- streams.push(encryptStream);
393
- }
394
- streams.push(fileStream);
380
+ // Everything that can fail before the export starts writing runs before the output file is
381
+ // opened: a failure here used to leave the file descriptor (and the unlinked file's disk space)
382
+ // held for the life of the worker.
383
+ const accountData = await accountObject.loadAccountData(account);
384
+ const isApiAccount = await accountObject.isApiClient(accountData);
395
385
 
396
- pipeline(...streams, err => {
397
- if (err && !streamError) {
398
- streamError = err;
399
- }
400
- });
386
+ const output = await openExportOutput(filePath, isEncrypted ? await getSecret() : null);
387
+ const gzipStream = output.input;
388
+ const fileStream = output.output;
401
389
 
402
390
  function writeWithBackpressure(data) {
403
- if (streamError) {
404
- return Promise.reject(streamError);
391
+ if (output.error()) {
392
+ return Promise.reject(output.error());
405
393
  }
406
394
 
407
395
  if (gzipStream.write(data)) {
@@ -436,8 +424,6 @@ async function exportMessages(job, exportData) {
436
424
  // from inside the retry backoff so a batch stuck retrying does not let the lock lapse.
437
425
  const maybeExtendLease = createLeaseExtender(job, account, exportId);
438
426
 
439
- const accountData = await accountObject.loadAccountData(account);
440
- const isApiAccount = await accountObject.isApiClient(accountData);
441
427
  const MESSAGE_FETCH_BATCH_SIZE = 10; // Batch size for parallel message fetching
442
428
  const MAX_BATCH_RETRIES = 5; // Max retries for rate-limited or transient per-message errors within a batch
443
429
  const BATCH_RETRY_BASE_DELAY = 5000; // Base delay for batch retry backoff (5 seconds)
@@ -490,8 +476,8 @@ async function exportMessages(job, exportData) {
490
476
 
491
477
  try {
492
478
  while (true) {
493
- if (streamError) {
494
- throw streamError;
479
+ if (output.error()) {
480
+ throw output.error();
495
481
  }
496
482
 
497
483
  if (sizeLimitReached) {
@@ -536,8 +522,8 @@ async function exportMessages(job, exportData) {
536
522
 
537
523
  if (isApiAccount && entriesToFetch.length > 1) {
538
524
  for (let i = 0; i < entriesToFetch.length; i += MESSAGE_FETCH_BATCH_SIZE) {
539
- if (streamError) {
540
- throw streamError;
525
+ if (output.error()) {
526
+ throw output.error();
541
527
  }
542
528
  if (sizeLimitReached) {
543
529
  break;
@@ -630,8 +616,8 @@ async function exportMessages(job, exportData) {
630
616
  }
631
617
  } else {
632
618
  for (const entry of entriesToFetch) {
633
- if (streamError) {
634
- throw streamError;
619
+ if (output.error()) {
620
+ throw output.error();
635
621
  }
636
622
 
637
623
  let message = null;
@@ -697,25 +683,17 @@ async function exportMessages(job, exportData) {
697
683
  processingError = err;
698
684
  }
699
685
 
700
- if (sizeLimitReached) {
701
- logger.warn({
702
- msg: 'Export truncated: size limit reached',
703
- account,
704
- exportId,
705
- totalBytesWritten,
706
- limit: maxExportSize,
707
- messagesExported: processed
708
- });
709
- await Export.update(account, exportId, { truncated: '1' });
710
- }
711
-
712
686
  const FINALIZATION_TIMEOUT = 30000;
713
687
  await new Promise((resolve, reject) => {
688
+ if (output.error()) {
689
+ // The chain already failed and pipeline() tore it down, so no 'finish' or 'error'
690
+ // is coming; waiting would only run out the timeout
691
+ output.destroy();
692
+ return reject(output.error());
693
+ }
714
694
  const timeout = setTimeout(() => {
715
- gzipStream.destroy();
716
- if (encryptStream) encryptStream.destroy();
717
- fileStream.destroy();
718
- reject(streamError || new Error('Stream finalization timed out'));
695
+ output.destroy();
696
+ reject(output.error() || new Error('Stream finalization timed out'));
719
697
  }, FINALIZATION_TIMEOUT);
720
698
  gzipStream.end();
721
699
  fileStream.once('finish', () => {
@@ -724,15 +702,28 @@ async function exportMessages(job, exportData) {
724
702
  });
725
703
  fileStream.once('error', err => {
726
704
  clearTimeout(timeout);
727
- reject(streamError || err);
705
+ reject(output.error() || err);
728
706
  });
729
707
  });
730
708
 
731
709
  if (processingError) {
732
710
  throw processingError;
733
711
  }
734
- if (streamError) {
735
- throw streamError;
712
+ if (output.error()) {
713
+ throw output.error();
714
+ }
715
+
716
+ // Written after the file is closed, so a failure here cannot leave the streams open
717
+ if (sizeLimitReached) {
718
+ logger.warn({
719
+ msg: 'Export truncated: size limit reached',
720
+ account,
721
+ exportId,
722
+ totalBytesWritten,
723
+ limit: maxExportSize,
724
+ messagesExported: processed
725
+ });
726
+ await Export.update(account, exportId, { truncated: '1' });
736
727
  }
737
728
 
738
729
  logger.info({ msg: 'Export messages completed', account, exportId, messagesExported: processed, bytesWritten: totalBytesWritten });
@@ -794,9 +785,7 @@ const exportWorker = new Worker(
794
785
 
795
786
  const exportData = await redis.hgetall(`${REDIS_PREFIX}exp:${account}:${exportId}`).catch(() => ({}));
796
787
 
797
- if (exportData.filePath) {
798
- await fs.promises.unlink(exportData.filePath).catch(() => {});
799
- }
788
+ await Export.removeFile(exportId, exportData);
800
789
 
801
790
  if (err.code === 'ExportCancelled') {
802
791
  await Export.deleteFully(account, exportId);
@@ -837,6 +826,8 @@ const exportWorker = new Worker(
837
826
  }
838
827
  );
839
828
 
829
+ logBullErrors(exportWorker, 'worker:export');
830
+
840
831
  exportWorker.on('completed', async job => {
841
832
  metrics(logger, 'queuesProcessed', 'inc', { queue: 'export', status: 'completed' });
842
833
  logger.debug({ msg: 'Export queue entry completed', queue: job.queue.name, job: job.id, account: job.data.account, exportId: job.data.exportId });
@@ -898,9 +889,13 @@ async function onCommand(command) {
898
889
  }
899
890
 
900
891
  // Now that interrupted exports have been reconciled and orphaned files cleaned, start consuming
901
- // jobs. Mirrors BullMQ's own autorun: a fatal run() failure is surfaced as an 'error' event,
902
- // which (no listener) crashes the worker thread so the main process can restart it.
903
- exportWorker.run().catch(error => exportWorker.emit('error', error));
892
+ // jobs. A fatal run() failure leaves a thread that keeps sending heartbeats while consuming
893
+ // nothing, so it exits instead and the main process respawns it. (Re-emitting it as an 'error'
894
+ // event did not crash anything: BullMQ catches an unlistened 'error' and prints it.)
895
+ exportWorker.run().catch(err => {
896
+ logger.fatal({ msg: 'Export queue processing stopped, exiting worker', err });
897
+ logger.flush(() => process.exit(1));
898
+ });
904
899
 
905
900
  setInterval(() => {
906
901
  try {