emailengine-app 2.74.0 → 2.74.2

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 (40) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/data/google-crawlers.json +1 -1
  3. package/lib/account.js +23 -45
  4. package/lib/api-routes/changes-routes.js +51 -0
  5. package/lib/api-routes/index.js +160 -0
  6. package/lib/consts.js +15 -0
  7. package/lib/email-client/gmail/send-request.js +69 -0
  8. package/lib/email-client/gmail-client.js +4 -41
  9. package/lib/email-client/imap/detach-client.js +27 -0
  10. package/lib/email-client/imap/listing-diff.js +165 -0
  11. package/lib/email-client/imap/mailbox.js +32 -13
  12. package/lib/email-client/imap/subconnection.js +2 -4
  13. package/lib/email-client/imap/sync-operations.js +5 -3
  14. package/lib/email-client/imap-client.js +50 -84
  15. package/lib/email-client/outlook/send-request.js +48 -0
  16. package/lib/email-client/outlook-client.js +5 -14
  17. package/lib/export.js +97 -21
  18. package/lib/imapproxy/imap-core/lib/imap-connection.js +1 -1
  19. package/lib/logger.js +14 -6
  20. package/lib/rate-limit.js +33 -11
  21. package/lib/response-stream.js +138 -0
  22. package/lib/schemas.js +4 -2
  23. package/lib/sentry.js +8 -0
  24. package/lib/smtp-message-processor.js +131 -0
  25. package/lib/tools.js +28 -5
  26. package/lib/ui-routes/internals-routes.js +167 -67
  27. package/lib/ui-routes/route-helpers.js +9 -6
  28. package/package.json +9 -9
  29. package/sbom.json +1 -1
  30. package/static/css/flyonui.css +1 -1
  31. package/static/licenses.html +28 -18
  32. package/translations/messages.pot +67 -67
  33. package/views/config/ai.hbs +3 -1
  34. package/views/internals/index.hbs +63 -29
  35. package/views/layout/app.hbs +22 -0
  36. package/views/partials/document_store_header.hbs +7 -4
  37. package/workers/api.js +20 -216
  38. package/workers/export.js +29 -15
  39. package/workers/imap.js +47 -10
  40. package/workers/smtp.js +50 -91
package/lib/tools.js CHANGED
@@ -37,7 +37,9 @@ const {
37
37
  FETCH_RETRY_EXPONENTIAL,
38
38
  FETCH_RETRY_MAX,
39
39
  URL_FETCH_RETRY_MAX,
40
- MAX_DAYS_STATS
40
+ MAX_DAYS_STATS,
41
+ MAILBOX_RESPONSE_FIELDS,
42
+ MAILBOX_HASH
41
43
  } = require('./consts');
42
44
  const bullmqPackage = require('bullmq/package.json');
43
45
 
@@ -531,6 +533,20 @@ module.exports = {
531
533
  return path;
532
534
  },
533
535
 
536
+ // Hashed component of a mailbox's per-folder Redis keys: a hash of the normalized path, so an
537
+ // arbitrarily long (or delimiter-heavy) folder name maps to a compact, stable key.
538
+ mailboxPathHash(path) {
539
+ return BigInt('0x' + createHash(MAILBOX_HASH).update(module.exports.normalizePath(path)).digest('hex')).toString(36);
540
+ },
541
+
542
+ // Redis key of a mailbox's status hash (message count, uidNext, ...). Defined here once
543
+ // because the writer (lib/email-client/imap/mailbox.js) and the reader
544
+ // (Account.getMailboxListing) must agree byte for byte or the counters silently go missing.
545
+ // NB: distinct from Account.getMailboxHashKey(), which is the account-wide message-id index.
546
+ getMailboxStatusKey(account, path) {
547
+ return `${REDIS_PREFIX}iam:${account}:h:${module.exports.mailboxPathHash(path)}`;
548
+ },
549
+
534
550
  async resolveCredentials(account, proto) {
535
551
  let authServer = await settings.get('authServer');
536
552
  if (!authServer) {
@@ -1134,11 +1150,11 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
1134
1150
  let mailboxList = [];
1135
1151
  for (let entry of mailboxes) {
1136
1152
  let mailbox = {};
1137
- Object.keys(entry).forEach(key => {
1138
- if (['path', 'specialUse', 'name', 'listed', 'subscribed', 'delimiter', 'specialUseSource', 'noInferiors'].includes(key)) {
1153
+ for (let key of MAILBOX_RESPONSE_FIELDS) {
1154
+ if (key in entry) {
1139
1155
  mailbox[key] = entry[key];
1140
1156
  }
1141
- });
1157
+ }
1142
1158
  if (mailbox.delimiter && mailbox.path.indexOf(mailbox.delimiter) >= 0) {
1143
1159
  mailbox.parentPath = mailbox.path.substr(0, mailbox.path.lastIndexOf(mailbox.delimiter));
1144
1160
  }
@@ -2258,6 +2274,7 @@ oPpCZh28fyCPv2TZ
2258
2274
  t0xCngRgaIZRuD3T
2259
2275
  dBb0Tc1IggSKY8dD
2260
2276
  exRqrporGRl2rjBf
2277
+ /3wJNVxD2zYMP0pk
2261
2278
  r+p1xHpDF4Ct0jfn
2262
2279
  QeunHH85jTFcsR7e
2263
2280
  kBFI6x6tfC8K1C8E
@@ -2373,6 +2390,12 @@ mF3GOI+Ev7mJODtG
2373
2390
  nQNwPlZ+tyx24XVo
2374
2391
  olObiSmdzVaMp7lH
2375
2392
  SruXHv6plKL9YuAW
2393
+ WVyvxP7wyEaQ/hzD
2394
+ YkdM9t/TzipfB13O
2395
+ LVvUBJQhWMOmq/mt
2396
+ +SJ8ylImwdExbw/8
2397
+ KvUe4HhYDNDXDouN
2398
+ jYfRjAsQtmeJcUTk
2376
2399
  cyp1GKV4Cl+eC8G/
2377
2400
  Q1y/TzbtUQCqnotR
2378
2401
  59Q2qOkuyTLzQDhd
@@ -2399,7 +2422,7 @@ QodzxvoJ6NPGhCgW
2399
2422
  b85BMAFRHn10uX8y
2400
2423
  vV2RgfFH2YFTYsly
2401
2424
  zcmIO3obSzUVHGtF
2402
- tzsA68uFVAffHmec
2425
+ Qm55I3Y1yUsDhHBU
2403
2426
  DkCU3OpaSa+rIVfU
2404
2427
  dcDjqpxVxivT46Rl
2405
2428
  QSgNcpNukC9CBNfe
@@ -13,6 +13,34 @@ const { redis } = require('../db');
13
13
  const { DEFAULT_PAGE_SIZE } = require('../consts');
14
14
  const { formatAccountData } = require('./route-helpers');
15
15
 
16
+ // Worker kinds in the order they are shown on the internals page (known kinds first; any
17
+ // unrecognized kind is appended so nothing is dropped).
18
+ const THREAD_TYPE_ORDER = ['main', 'api', 'imap', 'webhooks', 'submit', 'export', 'smtp', 'imapProxy', 'documents'];
19
+
20
+ // Severity ranking for the per-group health roll-up (higher wins).
21
+ const STATUS_RANK = { success: 0, neutral: 1, warning: 2, error: 3 };
22
+
23
+ // "Recently restarted" detection. Workers normally come online within seconds of the main
24
+ // process; one that came online much later was respawned after a crash (uncaught exception).
25
+ // A worker is flagged only when it started well after main (RESTART_GRACE, beyond any normal
26
+ // staggered-boot spread) AND that restart is still recent (RECENT_WINDOW), so a long-since
27
+ // recovered worker fades back to healthy while a flapping one stays flagged.
28
+ const WORKER_RESTART_GRACE = 3 * 60 * 1000; // 3 min after main = a restart, not normal boot
29
+ const WORKER_RESTART_RECENT_WINDOW = 30 * 60 * 1000; // keep flagging for 30 min after the restart
30
+
31
+ // Short description of what each worker kind does, shown on the group card header.
32
+ const THREAD_PURPOSE = {
33
+ main: 'Orchestrates everything else: spawns and monitors the other worker threads, assigns email accounts to the sync workers, routes inter-thread calls, and manages the Redis connection and licensing.',
34
+ api: 'Serves the REST API and the admin web interface (including this page), the OpenAPI documentation, and real-time account updates.',
35
+ imap: 'Keeps email accounts in sync - IMAP, Gmail API and Outlook/Graph - maintaining connections, detecting new and changed messages in real time, and running message and mailbox operations.',
36
+ webhooks: 'Delivers webhook notifications for email and account events over HTTP, with automatic retries and optional per-route filtering and transforms.',
37
+ submit: 'Sends queued outbound email through SMTP or a provider API (Gmail, Outlook), with retries and delivery, bounce and complaint tracking.',
38
+ export: 'Runs bulk account export jobs, extracting matching messages into compressed files for download.',
39
+ documents: 'Indexes emails into the Document Store (ElasticSearch) for search and processing. This is a deprecated feature.',
40
+ smtp: 'Accepts SMTP submissions from legacy applications and queues them for delivery through the associated account.',
41
+ imapProxy: 'Lets standard IMAP clients reach EmailEngine-managed accounts, hiding the OAuth2 complexity of providers like Gmail and Microsoft 365.'
42
+ };
43
+
16
44
  function init(args) {
17
45
  const { server, call } = args;
18
46
 
@@ -47,6 +75,144 @@ function init(args) {
47
75
  bytesFormatter = new Intl.NumberFormat('en-US', bytesFormatterOpts);
48
76
  }
49
77
 
78
+ // Reference point for "recently restarted" detection: the main thread's online
79
+ // time is the process start, so any worker that came online well after it was
80
+ // respawned after boot rather than started with the fleet.
81
+ let now = Date.now();
82
+ let mainThread = threads.find(threadInfo => threadInfo.isMain || threadInfo.type === 'main');
83
+ let mainOnline = mainThread && typeof mainThread.online === 'number' ? mainThread.online : null;
84
+
85
+ // Process each thread into row data. The per-thread config (expected worker
86
+ // count) is intentionally NOT surfaced per row here - it is a pool-level fact
87
+ // and is shown once on the group header below.
88
+ let processedThreads = threads.map(threadInfo => {
89
+ // Unresponsive / errored worker: the resource-usage probe failed or timed out.
90
+ if (threadInfo.resourceUsageError) {
91
+ threadInfo.isUnresponsive = true;
92
+ threadInfo.errorMessage = threadInfo.resourceUsageError.error;
93
+ }
94
+
95
+ // CPU metrics removed to prevent potential native code issues
96
+
97
+ // Single health signal (variant + label) used by both the per-row status dot
98
+ // and the per-group roll-up badge.
99
+ threadInfo.statusVariant = 'success';
100
+ threadInfo.statusLabel = 'Healthy';
101
+ if (threadInfo.isUnresponsive) {
102
+ threadInfo.statusVariant = 'error';
103
+ threadInfo.statusLabel = 'Unresponsive';
104
+ } else {
105
+ switch (threadInfo.healthStatus) {
106
+ case 'critical':
107
+ case 'restarting':
108
+ threadInfo.statusVariant = 'error';
109
+ threadInfo.statusLabel = 'Critical';
110
+ break;
111
+ case 'unhealthy':
112
+ threadInfo.statusVariant = 'warning';
113
+ threadInfo.statusLabel = 'Unhealthy';
114
+ break;
115
+ case 'unknown':
116
+ threadInfo.statusVariant = 'neutral';
117
+ threadInfo.statusLabel = 'Unknown';
118
+ break;
119
+ // 'healthy' or undefined -> success / Healthy
120
+ }
121
+ }
122
+
123
+ // A worker that came online well after the main process, recently, was most
124
+ // likely respawned after an uncaught exception. Surface it as a warning even
125
+ // when its health checks are otherwise passing; a real error/warning health
126
+ // status is more specific and takes precedence.
127
+ if (
128
+ !threadInfo.isMain &&
129
+ mainOnline !== null &&
130
+ typeof threadInfo.online === 'number' &&
131
+ threadInfo.online - mainOnline > WORKER_RESTART_GRACE &&
132
+ now - threadInfo.online < WORKER_RESTART_RECENT_WINDOW &&
133
+ STATUS_RANK[threadInfo.statusVariant] < STATUS_RANK.warning
134
+ ) {
135
+ threadInfo.statusVariant = 'warning';
136
+ threadInfo.statusLabel = 'Recently restarted';
137
+ threadInfo.recentlyRestarted = true;
138
+ }
139
+
140
+ if (threadInfo.online) {
141
+ threadInfo.timeStr = new Date(threadInfo.online).toISOString();
142
+ }
143
+
144
+ // Format the heap reading for responsive threads. Unresponsive ones have no
145
+ // reading, so the Memory cell shows a dash and the Status column carries the
146
+ // state (heapTotal/rss/external are available but deliberately not displayed).
147
+ if (!threadInfo.isUnresponsive && typeof threadInfo.heapUsed === 'number') {
148
+ threadInfo.heapUsed = bytesFormatter.format(threadInfo.heapUsed).replace(/BB$/, 'GB');
149
+ }
150
+
151
+ // Email (sync) workers own account assignment, but the count field is absent
152
+ // when a worker currently syncs none - show an explicit 0 instead of a blank.
153
+ if (threadInfo.type === 'imap' && typeof threadInfo.accounts !== 'number') {
154
+ threadInfo.accounts = 0;
155
+ }
156
+
157
+ return threadInfo;
158
+ });
159
+
160
+ // Group threads by worker kind so the pool-level facts (expected vs actual count,
161
+ // config env var, health roll-up) live on the group header instead of being
162
+ // repeated on every member row.
163
+ let groupMap = new Map();
164
+ for (let threadInfo of processedThreads) {
165
+ if (!groupMap.has(threadInfo.type)) {
166
+ groupMap.set(threadInfo.type, []);
167
+ }
168
+ groupMap.get(threadInfo.type).push(threadInfo);
169
+ }
170
+
171
+ let orderedTypes = THREAD_TYPE_ORDER.filter(type => groupMap.has(type)).concat(
172
+ [...groupMap.keys()].filter(type => !THREAD_TYPE_ORDER.includes(type))
173
+ );
174
+
175
+ let groups = orderedTypes.map(type => {
176
+ let list = groupMap.get(type);
177
+ let cfg = list[0].config; // { key, value } expected-count config, or undefined
178
+ let expected = cfg && cfg.value != null ? Number(cfg.value) : null;
179
+ let hasExpected = expected !== null && !isNaN(expected);
180
+ let actual = list.length;
181
+
182
+ // Fleet completeness: green when the running count matches the configured
183
+ // count, red when a worker is missing (crashed and not restarted), amber when
184
+ // there are more running than configured.
185
+ let countVariant = 'neutral';
186
+ if (hasExpected) {
187
+ countVariant = actual < expected ? 'error' : actual > expected ? 'warning' : 'success';
188
+ }
189
+
190
+ // Health roll-up = worst member status.
191
+ let rollup = list.reduce(
192
+ (worst, threadInfo) =>
193
+ STATUS_RANK[threadInfo.statusVariant] > STATUS_RANK[worst.variant]
194
+ ? { variant: threadInfo.statusVariant, label: threadInfo.statusLabel }
195
+ : worst,
196
+ { variant: 'success', label: 'Healthy' }
197
+ );
198
+
199
+ return {
200
+ type,
201
+ description: list[0].description || type,
202
+ purpose: THREAD_PURPOSE[type] || null,
203
+ threads: list,
204
+ // Only the sync (email) workers are assigned accounts, so the Accounts
205
+ // column is shown only for that pool.
206
+ showAccounts: type === 'imap',
207
+ hasExpected,
208
+ countLabel: hasExpected ? `${actual} / ${expected} running` : `${actual} running`,
209
+ countVariant,
210
+ configRef: hasExpected ? `${cfg.key}=${expected}` : null,
211
+ healthVariant: rollup.variant,
212
+ healthLabel: rollup.label
213
+ };
214
+ });
215
+
50
216
  return h.view(
51
217
  'internals/index',
52
218
  {
@@ -57,73 +223,7 @@ function init(args) {
57
223
 
58
224
  apiWorkerWarning: apiWorkerScaling && apiWorkerScaling.fallback ? apiWorkerScaling : false,
59
225
 
60
- threads: threads.map(threadInfo => {
61
- // Check if this worker is unresponsive
62
- if (threadInfo.resourceUsageError) {
63
- threadInfo.isUnresponsive = true;
64
- threadInfo.heapUsed = threadInfo.resourceUsageError.unresponsive ? 'UNRESPONSIVE' : 'ERROR';
65
- threadInfo.errorMessage = threadInfo.resourceUsageError.error;
66
- }
67
-
68
- // CPU metrics removed to prevent potential native code issues
69
-
70
- // Process health status
71
- if (threadInfo.healthStatus) {
72
- switch (threadInfo.healthStatus) {
73
- case 'unhealthy':
74
- threadInfo.healthBadge = 'Unhealthy';
75
- threadInfo.healthBadgeType = 'warning';
76
- break;
77
- case 'critical':
78
- case 'restarting':
79
- threadInfo.healthBadge = 'Critical';
80
- threadInfo.healthBadgeType = 'error';
81
- break;
82
- case 'unknown':
83
- threadInfo.healthBadge = 'Unknown';
84
- threadInfo.healthBadgeType = 'neutral';
85
- break;
86
- // healthy - no badge shown to avoid clutter
87
- }
88
- }
89
-
90
- for (let key of Object.keys(threadInfo)) {
91
- switch (key) {
92
- case 'online':
93
- threadInfo.timeStr = new Date(threadInfo.online).toISOString();
94
- break;
95
-
96
- /*
97
- // managed by the template helper
98
- case 'messages':
99
- case 'called':
100
- case 'accounts':
101
- case 'threadId':
102
- threadInfo[key] = threadInfo[key];
103
- break;
104
- */
105
-
106
- case 'heapUsed':
107
- if (!threadInfo.isUnresponsive) {
108
- threadInfo.heapUsed = bytesFormatter.format(threadInfo[key]).replace(/BB$/, 'GB');
109
- }
110
- break;
111
-
112
- case 'heapTotal':
113
- // Not displayed anymore to avoid confusion with heap limit
114
- break;
115
-
116
- // Handle other memory metrics from new format
117
- case 'rss':
118
- case 'external':
119
- case 'arrayBuffers':
120
- // These are available but not displayed in the current UI
121
- break;
122
- }
123
- }
124
-
125
- return threadInfo;
126
- })
226
+ groups
127
227
  },
128
228
  {
129
229
  layout: 'app'
@@ -22,20 +22,23 @@ const { REDIS_PREFIX } = require('../consts');
22
22
  const { oauth2ProviderData } = require('../oauth2-apps');
23
23
  const exampleDocumentsPayloads = require('../payload-examples-documents.json');
24
24
 
25
+ // Fallback model list, shown until the first successful "Refresh Models" call
26
+ // replaces it with the models actually available on the configured endpoint
27
+ // (stored in the openAiModels setting)
25
28
  const OPEN_AI_MODELS = [
26
29
  {
27
- name: 'GPT-3 (instruct)',
28
- id: 'gpt-3.5-turbo-instruct'
30
+ name: 'GPT-5 Mini',
31
+ id: 'gpt-5-mini'
29
32
  },
30
33
 
31
34
  {
32
- name: 'GPT-3 (chat)',
33
- id: 'gpt-3.5-turbo'
35
+ name: 'GPT-5',
36
+ id: 'gpt-5'
34
37
  },
35
38
 
36
39
  {
37
- name: 'GPT-4',
38
- id: 'gpt-4'
40
+ name: 'GPT-5 Nano',
41
+ id: 'gpt-5-nano'
39
42
  }
40
43
  ];
41
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.74.0",
3
+ "version": "2.74.2",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "homepage": "https://emailengine.app/",
51
51
  "dependencies": {
52
- "@bull-board/api": "8.1.2",
53
- "@bull-board/hapi": "8.1.2",
52
+ "@bull-board/api": "8.3.0",
53
+ "@bull-board/hapi": "8.3.0",
54
54
  "@elastic/elasticsearch": "8.15.3",
55
55
  "@hapi/accept": "6.0.3",
56
56
  "@hapi/bell": "13.1.0",
@@ -64,19 +64,19 @@
64
64
  "@postalsys/bounce-classifier": "3.0.0",
65
65
  "@postalsys/certs": "1.0.16",
66
66
  "@postalsys/ee-client": "1.5.0",
67
- "@postalsys/email-ai-tools": "1.13.13",
67
+ "@postalsys/email-ai-tools": "1.13.14",
68
68
  "@postalsys/email-text-tools": "2.4.11",
69
69
  "@postalsys/gettext": "4.1.1",
70
70
  "@postalsys/joi-messages": "1.0.5",
71
71
  "@postalsys/templates": "2.0.1",
72
- "@sentry/node": "10.67.0",
72
+ "@sentry/node": "10.68.0",
73
73
  "@simplewebauthn/browser": "13.3.0",
74
74
  "@simplewebauthn/server": "13.3.2",
75
75
  "@zone-eu/mailsplit": "5.4.14",
76
76
  "@zone-eu/wild-config": "1.7.6",
77
77
  "ace-builds": "1.44.0",
78
78
  "base32.js": "0.1.0",
79
- "bullmq": "5.80.11",
79
+ "bullmq": "5.81.2",
80
80
  "compare-versions": "6.1.1",
81
81
  "dotenv": "17.4.2",
82
82
  "encoding-japanese": "2.2.0",
@@ -115,20 +115,20 @@
115
115
  "socks": "2.8.9",
116
116
  "speakeasy": "2.0.0",
117
117
  "timezones-list": "3.1.0",
118
- "undici": "7.28.0",
118
+ "undici": "7.29.0",
119
119
  "xml2js": "0.6.2"
120
120
  },
121
121
  "devDependencies": {
122
122
  "@eslint/js": "10.0.1",
123
123
  "@iconify-json/tabler": "1.2.37",
124
124
  "@iconify/tailwind4": "1.2.3",
125
- "@playwright/test": "1.61.1",
125
+ "@playwright/test": "1.62.0",
126
126
  "@tailwindcss/cli": "4.3.3",
127
127
  "acorn": "8.17.0",
128
128
  "acorn-walk": "8.3.5",
129
129
  "chai": "4.5.0",
130
130
  "eerawlog": "1.5.5",
131
- "eslint": "10.7.0",
131
+ "eslint": "10.8.0",
132
132
  "flyonui": "2.4.1",
133
133
  "grunt": "1.6.2",
134
134
  "grunt-cli": "1.5.0",