emailengine-app 2.79.5 → 2.79.7

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/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +24 -0
  3. package/data/google-crawlers.json +1 -1
  4. package/lib/api-routes/account-routes.js +6 -3
  5. package/lib/api-routes/behavior-notes.js +6 -3
  6. package/lib/consts.js +4 -2
  7. package/lib/email-client/imap/mailbox.js +32 -8
  8. package/lib/enum-descriptions.js +1 -1
  9. package/lib/passkeys.js +39 -7
  10. package/lib/sso.js +47 -4
  11. package/lib/tools.js +19 -0
  12. package/lib/ui-routes/account-routes.js +9 -1
  13. package/lib/ui-routes/auth-routes.js +158 -62
  14. package/lib/ui-routes/network-config-routes.js +10 -1
  15. package/package.json +21 -21
  16. package/sbom.json +1 -1
  17. package/static/css/flyonui.css +1 -1
  18. package/static/css/src/app.tailwind.css +55 -0
  19. package/static/js/app.js +4 -35
  20. package/static/js/passkey-register.js +50 -1
  21. package/static/js/public.js +128 -0
  22. package/static/js/ui.js +183 -6
  23. package/static/licenses.html +375 -774
  24. package/translations/messages.pot +66 -66
  25. package/views/account/passkeys.hbs +133 -0
  26. package/views/account/security.hbs +300 -319
  27. package/views/accounts/account.hbs +84 -114
  28. package/views/accounts/register/imap-server.hbs +8 -10
  29. package/views/config/document-store/index.hbs +6 -6
  30. package/views/config/license.hbs +4 -1
  31. package/views/config/oauth/app.hbs +1 -1
  32. package/views/config/oauth/edit.hbs +1 -1
  33. package/views/config/oauth/new.hbs +1 -1
  34. package/views/config/webhooks.hbs +7 -6
  35. package/views/partials/gateway_js.hbs +7 -6
  36. package/views/partials/ui/btn.hbs +8 -2
  37. package/views/partials/ui/confirm-modal.hbs +2 -3
  38. package/views/partials/ui/empty-state.hbs +25 -0
  39. package/views/partials/webhooks_editor_functions.hbs +5 -5
  40. package/workers/api.js +56 -18
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "2.79.5"
2
+ ".": "2.79.7"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.79.7](https://github.com/postalsys/emailengine/compare/v2.79.6...v2.79.7) (2026-08-31)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * bind WebAuthn challenges to the ceremony that minted them ([6b2073b](https://github.com/postalsys/emailengine/commit/6b2073b5c8e50ab75a02d2c6a0f54a43d2c295e6))
9
+ * **deps:** collapse encoding-japanese to a single copy for the CP932 areas ([8ae2109](https://github.com/postalsys/emailengine/commit/8ae21099dd86a3dd9467dc0ca4ead9880e147e27))
10
+ * **deps:** update dependencies and collapse nodemailer to a single copy ([cf814e9](https://github.com/postalsys/emailengine/commit/cf814e9e4c91c4430fce01687ead6bdb38bc3879))
11
+ * retry OIDC discovery instead of disabling SSO for the process lifetime ([dbbbf43](https://github.com/postalsys/emailengine/commit/dbbbf432ed6593b7fd5457e8fc6d2f8d03316ea6))
12
+ * **tls:** renew certificates before they expire, not a month after ([fa150e8](https://github.com/postalsys/emailengine/commit/fa150e87bbe7aa317847f3d676053ecc99dc69f1))
13
+ * **ui:** disable the stored-log download when an account has no logs ([5137b71](https://github.com/postalsys/emailengine/commit/5137b71bbaf9a935b91437a53b7b369237a445a2))
14
+ * **ui:** move the passkey list onto a page of its own ([7cb42c4](https://github.com/postalsys/emailengine/commit/7cb42c4dc1a8ece1468f8754f37cd9f763c97130))
15
+ * **ui:** show a busy state on the buttons that start slow work ([6c63479](https://github.com/postalsys/emailengine/commit/6c6347946bed0c06f836826de0425b328740bf81))
16
+ * **ui:** stop offering to clear stored logs an account does not have ([e02f09a](https://github.com/postalsys/emailengine/commit/e02f09a596b5d0a1f40e37297d86aea7a046b813))
17
+
18
+ ## [2.79.6](https://github.com/postalsys/emailengine/compare/v2.79.5...v2.79.6) (2026-08-27)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **deps:** update nodemailer to 9.0.6 and refresh dependencies ([85ce711](https://github.com/postalsys/emailengine/commit/85ce7116d766d3c9b81b77b3d39496ca6119c2d2))
24
+ * **imap:** recover addresses when the ENVELOPE reports an unusable one ([78d5fbd](https://github.com/postalsys/emailengine/commit/78d5fbd62211d79b4c108622e1ad771b34156d06))
25
+ * **reference:** correct three wrong provider claims in the API documentation ([df9fa95](https://github.com/postalsys/emailengine/commit/df9fa95bf542cf086f34d215edd48bb2007e84d6))
26
+
3
27
  ## [2.79.5](https://github.com/postalsys/emailengine/compare/v2.79.4...v2.79.5) (2026-08-26)
4
28
 
5
29
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "creationTime": "2026-08-21T14:46:19.000000",
2
+ "creationTime": "2026-08-31T14:46:39.000000",
3
3
  "prefixes": [
4
4
  {
5
5
  "ipv6Prefix": "2001:4860:4801:2008::/64"
@@ -1584,8 +1584,11 @@ async function init(args) {
1584
1584
  return getLogs(redis, request.params.account);
1585
1585
  },
1586
1586
  options: {
1587
- description: 'Return IMAP logs for an account',
1588
- notes: ['Output is a downloadable text file', BEHAVIOR.IMAP_ONLY],
1587
+ description: 'Return stored logs for an account',
1588
+ notes: [
1589
+ 'Output is a downloadable text file with one JSON log entry per line, or a plain-text notice when nothing is stored',
1590
+ BEHAVIOR.ACCOUNT_LOG_SCOPE
1591
+ ],
1589
1592
  tags: ['api', 'Logs'],
1590
1593
 
1591
1594
  auth: {
@@ -1596,7 +1599,7 @@ async function init(args) {
1596
1599
 
1597
1600
  plugins: {
1598
1601
  openapi: {
1599
- 'x-ee-behavior': [BEHAVIOR.IMAP_ONLY],
1602
+ 'x-ee-behavior': [BEHAVIOR.ACCOUNT_LOG_SCOPE],
1600
1603
  produces: ['text/plain'],
1601
1604
  responses: apiResponses('Returns the account log as a plain text stream.', 400, 401, 403, 429, 500)
1602
1605
  }
@@ -16,10 +16,11 @@
16
16
  // The provider notes are transcribed by hand from the transports, and nothing enforces the
17
17
  // copy. When changing one, check the code that actually implements the limit - not the
18
18
  // ASCII capability matrices at the top of those files, which are comments too:
19
- // NO_LABEL_SET_ON_GMAIL lib/email-client/gmail-client.js, prepareLabelUpdate throw
19
+ // NO_LABEL_SET_ON_GMAIL lib/email-client/gmail-client.js, assertLabelSetSupported throw
20
20
  // GMAIL_DELETE_IS_TRASH lib/email-client/gmail-client.js, deleteMessage
21
21
  // UPLOAD_DRAFTS_ONLY_GRAPH lib/email-client/outlook-client.js, uploadMessage
22
22
  // NO_QUOTA_ON_API_ACCOUNTS getQuota on both clients
23
+ // ACCOUNT_LOG_SCOPE lib/email-client/base-client.js, getLogger; workers/imap.js, getAccountLogger
23
24
 
24
25
  module.exports = {
25
26
  // --- asynchronous work -------------------------------------------------------------
@@ -43,7 +44,8 @@ module.exports = {
43
44
  'Removes the account, its credentials, its cached data and any messages still queued for delivery. Webhook events generated before the deletion are never delivered afterwards and are discarded once the queue reaches them. Records of deliveries that had already failed permanently are not removed here; they expire on the queue retention window, seven days by default.',
44
45
 
45
46
  // --- provider differences ----------------------------------------------------------
46
- NO_QUOTA_ON_API_ACCOUNTS: 'Quota reporting is not available for Gmail API or MS Graph accounts; the quota field is omitted for those.',
47
+ NO_QUOTA_ON_API_ACCOUNTS:
48
+ 'Quota reporting is not available for Gmail API or MS Graph accounts; the quota field is returned as false for those, the same value an IMAP server without QUOTA support produces.',
47
49
 
48
50
  UPLOAD_DRAFTS_ONLY_GRAPH: 'For MS Graph accounts only drafts can be uploaded, and the draft flag cannot be changed afterwards.',
49
51
 
@@ -53,5 +55,6 @@ module.exports = {
53
55
  GMAIL_DELETE_IS_TRASH:
54
56
  'For Gmail API accounts the message is always moved to Trash. The force option, which permanently deletes on IMAP accounts, has no effect.',
55
57
 
56
- IMAP_ONLY: 'Only available for IMAP accounts. Gmail API and MS Graph accounts have no equivalent.'
58
+ ACCOUNT_LOG_SCOPE:
59
+ 'Nothing is stored unless logging is enabled for the account, either with the account logs flag or the global logs.all setting. IMAP accounts record the protocol trace, Gmail API and MS Graph accounts record their API requests, and SMTP transactions are recorded for any account that sends over SMTP.'
57
60
  };
package/lib/consts.js CHANGED
@@ -160,8 +160,10 @@ module.exports = {
160
160
 
161
161
  REDIS_BATCH_DELETE_SIZE: 1000,
162
162
 
163
- // start renewing TLS if the certificate expires in 30 days
164
- RENEW_TLS_AFTER: 30 * 24 * 3600 * 1000,
163
+ // When renewal becomes due is derived from each certificate's own lifetime by
164
+ // isRenewalDue() in @postalsys/certs, so there is no constant for it here. Let's Encrypt is
165
+ // shortening certificates from 90 days to 64 and then 45, and a fixed threshold is correct
166
+ // for exactly one lifetime. https://letsencrypt.org/2025/12/02/from-90-to-45
165
167
 
166
168
  // do not attempt certificate renewal more often than once in 8 hours
167
169
  BLOCK_TLS_RENEW: 8 * 3600 * 1000,
@@ -116,6 +116,31 @@ function notificationHeaderFields(configuredHeaders) {
116
116
  return Array.from(fetchHeaders);
117
117
  }
118
118
 
119
+ // Runs for every address of every message, so both patterns are built once
120
+ const HAS_WHITESPACE = /\s/;
121
+ // An addr-spec that carries its whitespace legally, inside a quoted local part
122
+ const QUOTED_LOCAL_ADDR = /^"(?:[^"\\]|\\[\s\S])*"@\S+$/;
123
+
124
+ /**
125
+ * Tells whether an address is usable as a mailbox.
126
+ *
127
+ * A server that failed to parse a malformed header does not always report the wreckage as
128
+ * an empty address - Gmail hands back "user@example.com user@example.com" when the header
129
+ * separated the two copies with a non-breaking space. Unquoted whitespace is not addr-spec,
130
+ * so a value carrying it is no more usable than an empty one, and the raw header is the
131
+ * better source. Whitespace inside a quoted local part is legal and stays usable.
132
+ *
133
+ * @param {String} address - Address to check
134
+ * @returns {Boolean} True if the address can be used as a mailbox
135
+ */
136
+ function isUsableAddress(address) {
137
+ if (!address) {
138
+ return false;
139
+ }
140
+
141
+ return !HAS_WHITESPACE.test(address) || QUOTED_LOCAL_ADDR.test(address);
142
+ }
143
+
119
144
  /**
120
145
  * Parses a raw address header into the address objects the API exposes.
121
146
  *
@@ -129,7 +154,7 @@ function parseAddressHeader(values) {
129
154
 
130
155
  try {
131
156
  let addressList = addressparser(values)
132
- .filter(address => !!address.address)
157
+ .filter(address => isUsableAddress(address.address))
133
158
  .map(address => {
134
159
  let name = address.name;
135
160
  try {
@@ -150,12 +175,11 @@ function parseAddressHeader(values) {
150
175
  /**
151
176
  * Picks the address list to expose for a header, preferring the server's ENVELOPE.
152
177
  *
153
- * An ENVELOPE list can come back holding no usable address at all: RFC 9051 7.5.2 group
154
- * markers carry a group name and nothing else, and a server that failed to parse a
155
- * malformed header reports the wreckage the same way, as a display name with an empty
156
- * address. The raw header is the better answer in that case, because addressparser sees
157
- * the original value and can still recover the recipient. Falling back on emptiness alone
158
- * was not enough - the broken list is not empty, just useless.
178
+ * An ENVELOPE list can come back holding no address anyone could use: RFC 9051 7.5.2 group
179
+ * markers carry a group name and nothing else, and a server that failed to parse a malformed
180
+ * header reports the wreckage in the shapes isUsableAddress() turns down. The raw header is
181
+ * the better answer then, because addressparser sees the original value and can still recover
182
+ * the recipient. A list has to be judged on what its entries hold, not on being non-empty.
159
183
  *
160
184
  * The header is parsed only when the ENVELOPE turns out to be unusable, which is rare.
161
185
  * Parsing all four address fields up front would be work discarded on every message.
@@ -166,7 +190,7 @@ function parseAddressHeader(values) {
166
190
  * @returns {Object[]|undefined} The list to expose, or undefined if neither source has one
167
191
  */
168
192
  function preferAddressList(envelopeList, headers, key) {
169
- if (envelopeList?.some(entry => entry.address)) {
193
+ if (envelopeList?.some(entry => isUsableAddress(entry.address))) {
170
194
  return envelopeList;
171
195
  }
172
196
 
@@ -122,7 +122,7 @@ const ENUM_DESCRIPTIONS = {
122
122
  gateway: 'Manage SMTP gateways, which hold outbound SMTP credentials',
123
123
  events: 'Subscribe to the instance-wide change stream, which covers every account',
124
124
  diagnostics: 'Read statistics and service status',
125
- logs: 'Read the per-account connection log. Entries are the raw protocol trace, so they include folder names and message subjects'
125
+ logs: 'Read the per-account connection log. Entries include the protocol or API trace, so they include folder names and message subjects'
126
126
  },
127
127
 
128
128
  queueId: {
package/lib/passkeys.js CHANGED
@@ -7,6 +7,29 @@ const { REDIS_PREFIX, WEBAUTHN_CHALLENGE_TTL } = require('./consts');
7
7
 
8
8
  const KEY_PREFIX = `${REDIS_PREFIX}webauthn:`;
9
9
 
10
+ // A WebAuthn challenge is a bare nonce, and nothing in the signed response the authenticator
11
+ // returns says which ceremony the server minted it for - that binding is the server's job.
12
+ // Registration is gated behind a password confirmation and sign-in deliberately is not, so while
13
+ // both ceremonies drew from one keyspace a nonce minted by the unauthenticated sign-in endpoint
14
+ // could be spent completing a registration, skipping the gate entirely. The purpose is part of the
15
+ // key, so each ceremony can only consume what it minted.
16
+ const CHALLENGE_REGISTER = 'register';
17
+ const CHALLENGE_AUTH = 'auth';
18
+ const CHALLENGE_PURPOSES = new Set([CHALLENGE_REGISTER, CHALLENGE_AUTH]);
19
+
20
+ function assertPurpose(purpose) {
21
+ if (!CHALLENGE_PURPOSES.has(purpose)) {
22
+ // Every caller passes one of the exported constants, so this is a programming error and
23
+ // must not degrade into an unnamespaced key that would restore the bypass
24
+ throw new Error(`Unknown WebAuthn challenge purpose: ${purpose}`);
25
+ }
26
+ }
27
+
28
+ function challengeKey(challengeId, purpose) {
29
+ assertPurpose(purpose);
30
+ return `${KEY_PREFIX}challenge:${purpose}:${challengeId}`;
31
+ }
32
+
10
33
  // Passkey data does not require encryption at rest. Unlike TOTP seeds or OAuth
11
34
  // client secrets (which are shared secrets), passkeys use public-key cryptography.
12
35
  // Only the public key is stored here -- the private key never leaves the
@@ -90,6 +113,9 @@ function credentialKeys(id, user) {
90
113
  }
91
114
 
92
115
  module.exports = {
116
+ CHALLENGE_REGISTER,
117
+ CHALLENGE_AUTH,
118
+
93
119
  async getRpConfig() {
94
120
  let serviceUrl = await settings.get('serviceUrl');
95
121
  if (!serviceUrl) {
@@ -99,18 +125,20 @@ module.exports = {
99
125
  return { rpId: url.hostname, origin: url.origin };
100
126
  },
101
127
 
102
- async storeChallenge(challenge) {
128
+ async storeChallenge(challenge, purpose) {
103
129
  let challengeId = crypto.randomBytes(32).toString('hex');
104
- await redis.set(`${KEY_PREFIX}challenge:${challengeId}`, challenge, 'EX', WEBAUTHN_CHALLENGE_TTL);
130
+ await redis.set(challengeKey(challengeId, purpose), challenge, 'EX', WEBAUTHN_CHALLENGE_TTL);
105
131
  return challengeId;
106
132
  },
107
133
 
108
- async consumeChallenge(challengeId) {
134
+ async consumeChallenge(challengeId, purpose) {
135
+ // Before the id check, so a caller that forgot the purpose trips the guardrail whatever
136
+ // it passed as an id rather than getting a plausible null back
137
+ assertPurpose(purpose);
109
138
  if (!challengeId || typeof challengeId !== 'string') {
110
139
  return null;
111
140
  }
112
- let key = `${KEY_PREFIX}challenge:${challengeId}`;
113
- let challenge = await redis.getdel(key);
141
+ let challenge = await redis.getdel(challengeKey(challengeId, purpose));
114
142
  return challenge || null;
115
143
  },
116
144
 
@@ -142,8 +170,12 @@ module.exports = {
142
170
  return hydrateCredential(data);
143
171
  },
144
172
 
145
- async updateCounter(credentialId, newCounter) {
146
- await redis.hset(`${KEY_PREFIX}cred:${credentialId}`, 'counter', String(newCounter));
173
+ // Called after a verified assertion, so it stamps the sign-in time alongside the
174
+ // signature counter. The stamp is what the security page shows as "Last used";
175
+ // credentials registered before it existed carry no field and render as unknown
176
+ // rather than as never used.
177
+ async recordAuthentication(credentialId, newCounter) {
178
+ await redis.hset(`${KEY_PREFIX}cred:${credentialId}`, 'counter', String(newCounter), 'lastUsedAt', new Date().toISOString());
147
179
  },
148
180
 
149
181
  async listCredentials(user) {
package/lib/sso.js CHANGED
@@ -35,6 +35,7 @@
35
35
  // dotted path (e.g. "realm_access.roles") for IdPs that nest it.
36
36
 
37
37
  const { fetch: fetchCmd } = require('undici');
38
+ const { backOff } = require('exponential-backoff');
38
39
  const { readEnvValue, httpAgent, getBoolean } = require('./tools');
39
40
  const packageData = require('../package.json');
40
41
 
@@ -67,6 +68,13 @@ const USE_OIDC_AUTH = !!(OIDC_ISSUER && OIDC_CLIENT_ID && OIDC_CLIENT_SECRET);
67
68
 
68
69
  const DISCOVERY_TIMEOUT = 10 * 1000;
69
70
 
71
+ // Backoff bounds for retryDiscovery(). Quick at first, because the common failure is
72
+ // an IdP that is merely slower to boot than we are (a shared host restarting both at
73
+ // once, where the IdP can be a minute behind), then doubling to one probe every five
74
+ // minutes so a genuine multi-hour outage costs almost nothing.
75
+ const DISCOVERY_RETRY_MIN = 5 * 1000;
76
+ const DISCOVERY_RETRY_MAX = 5 * 60 * 1000;
77
+
70
78
  // `openid` is what makes the request an OIDC request; `profile` and `email`
71
79
  // populate the userinfo claims mapped by mapUserinfoProfile().
72
80
  const DEFAULT_SCOPES = ['openid', 'profile', 'email'];
@@ -259,10 +267,13 @@ function mapUserinfoProfile(userinfo, groupsClaim) {
259
267
  };
260
268
  }
261
269
 
262
- // Fetch and validate the discovery document for the configured issuer. Uses the
270
+ // Fetch and validate the discovery document for the configured issuer. Defaults to the
263
271
  // shared RetryAgent (transient DNS/socket retries) with a hard timeout so a
264
- // slow/unreachable IdP cannot stall API-worker startup indefinitely.
265
- async function fetchOidcDiscovery() {
272
+ // slow/unreachable IdP cannot stall API-worker startup indefinitely. Callers that
273
+ // retry on their own schedule pass a plain dispatcher instead - see retryDiscovery().
274
+ async function fetchOidcDiscovery(options) {
275
+ options = options || {};
276
+
266
277
  let url = getDiscoveryUrl(OIDC_ISSUER);
267
278
 
268
279
  let res = await fetchCmd(url, {
@@ -271,7 +282,7 @@ async function fetchOidcDiscovery() {
271
282
  'User-Agent': `${packageData.name}/${packageData.version} (+${packageData.homepage})`,
272
283
  Accept: 'application/json'
273
284
  },
274
- dispatcher: httpAgent.retry,
285
+ dispatcher: options.dispatcher || httpAgent.retry,
275
286
  signal: AbortSignal.timeout(DISCOVERY_TIMEOUT)
276
287
  });
277
288
 
@@ -283,6 +294,37 @@ async function fetchOidcDiscovery() {
283
294
  return validateDiscoveryDocument(doc, OIDC_ISSUER);
284
295
  }
285
296
 
297
+ // Keep probing the discovery endpoint until it answers, resolving with the document.
298
+ // Callers use this after a failed startup fetch: discovery is what the bell strategy is
299
+ // built from, so a failure that is never retried leaves SSO switched off for the
300
+ // lifetime of the process - silently, and on a forced instance that looks like the
301
+ // admin panel reverting to password login on its own.
302
+ //
303
+ // Two deliberate departures from a plain fetch-with-retry. It waits before the first
304
+ // attempt, because this continues a fetch that has just failed rather than starting a
305
+ // fresh one. And each probe uses the plain dispatcher instead of the retrying one
306
+ // fetchOidcDiscovery() defaults to: this loop is itself the retry layer, and undici's
307
+ // ladder underneath it would turn every "cheap probe" into five connect attempts
308
+ // holding a socket for the whole 10s timeout.
309
+ async function retryDiscovery(options) {
310
+ options = options || {};
311
+
312
+ let fetchDiscovery = options.fetchDiscovery || (() => fetchOidcDiscovery({ dispatcher: httpAgent.fetch }));
313
+
314
+ return backOff(fetchDiscovery, {
315
+ delayFirstAttempt: true,
316
+ startingDelay: options.minDelay || DISCOVERY_RETRY_MIN,
317
+ maxDelay: options.maxDelay || DISCOVERY_RETRY_MAX,
318
+ numOfAttempts: Infinity,
319
+ retry: (err, attempt) => {
320
+ if (options.onError) {
321
+ options.onError(err, attempt);
322
+ }
323
+ return true;
324
+ }
325
+ });
326
+ }
327
+
286
328
  // Build an OIDC RP-initiated logout URL against the IdP's end_session_endpoint.
287
329
  // id_token_hint is included when available so the IdP skips its logout-confirmation
288
330
  // prompt; client_id + post_logout_redirect_uri (the latter must be registered at the
@@ -350,6 +392,7 @@ module.exports = {
350
392
  validateDiscoveryDocument,
351
393
  mapUserinfoProfile,
352
394
  fetchOidcDiscovery,
395
+ retryDiscovery,
353
396
  buildLogoutUrl,
354
397
  buildOidcBellProvider
355
398
  };
package/lib/tools.js CHANGED
@@ -400,10 +400,29 @@ function cidReferenceRegex() {
400
400
  return new RegExp(CID_REFERENCE_SOURCE, 'g');
401
401
  }
402
402
 
403
+ // Both the SMTP server and the IMAP proxy read the TLS certificate into their server options once,
404
+ // when their worker starts, rather than per handshake, so a newly issued certificate only reaches
405
+ // them through a reload. The list lives here rather than at each call site because the bug this
406
+ // replaces was exactly that: the renewal path reloaded the SMTP server and forgot the IMAP proxy,
407
+ // which then went on offering the expired certificate until something unrelated restarted it.
408
+ async function reloadTlsServers(call, logger, context) {
409
+ for (let cmd of ['smtpReload', 'imapProxyReload']) {
410
+ try {
411
+ await call({ cmd });
412
+ } catch (err) {
413
+ // Caught per command so a server that fails to come back does not cost the other one
414
+ // its new certificate, and so the failure is not reported as an acquisition failure.
415
+ logger.error(Object.assign({ msg: 'Failed to reload server after certificate change', cmd, err }, context || {}));
416
+ }
417
+ }
418
+ }
419
+
403
420
  module.exports = {
404
421
  // keep the re-export, lib/utils/to-camel-case.js holds it so pure modules can use it too
405
422
  toCamelCase,
406
423
 
424
+ reloadTlsServers,
425
+
407
426
  cidReferenceRegex,
408
427
 
409
428
  /**
@@ -1345,9 +1345,16 @@ function init(args) {
1345
1345
  }
1346
1346
  }
1347
1347
 
1348
- let logInfo = (await settings.get('logs')) || {
1348
+ // Stored entries outlive the logging switch - turning logging off does not clear what
1349
+ // was already collected - so the download control is gated on the entries themselves,
1350
+ // not on whether logging is currently enabled. Both are snapshots taken at render
1351
+ // time, the same as everything else on this page.
1352
+ let [logSettings, storedLogCount] = await Promise.all([settings.get('logs'), redis.llen(accountObject.getLogKey())]);
1353
+
1354
+ let logInfo = logSettings || {
1349
1355
  all: false
1350
1356
  };
1357
+ let hasStoredLogs = storedLogCount > 0;
1351
1358
 
1352
1359
  accountData.path = [].concat(accountData.path || '*');
1353
1360
  if (accountData.path.includes('*')) {
@@ -1455,6 +1462,7 @@ function init(args) {
1455
1462
  accountAlert,
1456
1463
  accountParked: !!disabledByAuthFailureAt,
1457
1464
  logs: logInfo,
1465
+ hasStoredLogs,
1458
1466
  smtpError: accountData.smtpStatus && accountData.smtpStatus.status === 'error',
1459
1467
 
1460
1468
  showSmtp: accountData.smtp || (accountData.oauth2 && accountData.oauth2.provider),