emailengine-app 2.83.2 → 2.84.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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/SECURITY.md +126 -47
- package/data/google-crawlers.json +1 -1
- package/lib/api-routes/outbox-routes.js +132 -9
- package/lib/api-routes/permission-map.js +11 -1
- package/lib/consts.js +0 -4
- package/lib/email-client/imap/idle-settings.js +44 -0
- package/lib/email-client/imap/mailbox.js +19 -7
- package/lib/email-client/imap-client.js +3 -21
- package/lib/enum-descriptions.js +7 -0
- package/lib/export.js +2 -6
- package/lib/field-usage.js +4 -0
- package/lib/handlebars-helpers.js +4 -0
- package/lib/outbox.js +338 -10
- package/lib/queue-browser/definitions.js +132 -0
- package/lib/queue-browser/format.js +387 -0
- package/lib/queue-browser/index.js +568 -0
- package/lib/queue-job-actions.js +75 -0
- package/lib/queue-retention.js +53 -1
- package/lib/routes-ui.js +5 -0
- package/lib/schemas.js +42 -2
- package/lib/security-headers.js +2 -24
- package/lib/token-permission-view.js +1 -1
- package/lib/ui-routes/account-routes.js +6 -0
- package/lib/ui-routes/imap-idle-field.js +42 -0
- package/lib/ui-routes/queue-routes.js +371 -0
- package/lib/utils/status-error.js +21 -0
- package/package.json +15 -17
- package/prepare-bundle-deps.sh +1 -1
- package/sbom.json +1 -1
- package/server.js +10 -0
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +2 -0
- package/static/js/queues.js +117 -0
- package/static/licenses.html +122 -246
- package/translations/messages.pot +57 -42
- package/views/accounts/account.hbs +31 -0
- package/views/accounts/edit.hbs +2 -0
- package/views/config/service.hbs +1 -2
- package/views/dashboard.hbs +2 -2
- package/views/partials/queue_cell_account.hbs +20 -0
- package/views/partials/queue_cell_failure.hbs +6 -0
- package/views/partials/queue_clean_items.hbs +9 -0
- package/views/partials/queue_clean_modal.hbs +9 -0
- package/views/partials/queue_entry_actions.hbs +41 -0
- package/views/partials/queue_job_actions.hbs +15 -0
- package/views/partials/queue_pause_controls.hbs +18 -0
- package/views/partials/queue_retention_note.hbs +49 -0
- package/views/partials/queue_rows_export.hbs +58 -0
- package/views/partials/queue_rows_notify.hbs +73 -0
- package/views/partials/queue_rows_submit.hbs +70 -0
- package/views/partials/side_menu.hbs +1 -1
- package/views/partials/ui/tooltip.hbs +5 -3
- package/views/queues/index.hbs +104 -0
- package/views/queues/job.hbs +224 -0
- package/views/queues/queue.hbs +93 -0
- package/views/webhooks/webhook.hbs +3 -0
- package/workers/api.js +0 -4
- package/workers/submit.js +19 -5
- package/workers/webhooks.js +13 -0
- package/lib/api-routes/bull-board-routes.js +0 -56
package/lib/queue-retention.js
CHANGED
|
@@ -50,9 +50,61 @@ function buildRetentionPolicy(queueKeep) {
|
|
|
50
50
|
return { removeOnComplete, removeOnFail };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// The raw content of a message whose delivery failed for good is kept so the message can be
|
|
54
|
+
// retried from the queue browser or through POST /v1/outbox/{queueId}/retry. The job's own
|
|
55
|
+
// retention (above) only bounds the job record, which is a few hundred bytes of metadata; the
|
|
56
|
+
// content it points at is the whole message, up to EENGINE_MAX_SMTP_MESSAGE_SIZE, so it gets a
|
|
57
|
+
// bound of its own on both the count and the total size. Both defaults are deliberately well
|
|
58
|
+
// below the failed-job bounds: the record of a failure should outlive the ability to retry it.
|
|
59
|
+
const DEFAULT_FAILED_CONTENT_RETENTION_COUNT = 100;
|
|
60
|
+
const DEFAULT_FAILED_CONTENT_RETENTION_SIZE = 100 * 1024 * 1024;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Picks the retained failed-message contents that have to go to stay within the limits.
|
|
64
|
+
*
|
|
65
|
+
* Pure, so the three bounds can be tested without Redis. Entries are considered newest first:
|
|
66
|
+
* the most recent failures are the ones an operator is looking at, so when something has to be
|
|
67
|
+
* dropped it is the oldest. An entry is dropped when it is older than `maxAge`, when it is past
|
|
68
|
+
* the `maxCount` newest, or when the sizes of it and every newer entry add up to more than
|
|
69
|
+
* `maxBytes`. A single message larger than `maxBytes` on its own is therefore never retained,
|
|
70
|
+
* which is the point of a size bound.
|
|
71
|
+
*
|
|
72
|
+
* @param {Array<{account: string, queueId: string, size: number, finishedOn: number}>} entries - Retained contents, any order
|
|
73
|
+
* @param {Object} limits - Bounds to apply
|
|
74
|
+
* @param {number} limits.maxCount - How many contents to keep at most
|
|
75
|
+
* @param {number} limits.maxBytes - Total size of the kept contents, in bytes
|
|
76
|
+
* @param {number} limits.maxAge - How long a content is kept after the failure, in seconds
|
|
77
|
+
* @param {number} [limits.now] - The current time, for tests (defaults to Date.now())
|
|
78
|
+
* @returns {Array<Object>} The entries to drop, oldest first
|
|
79
|
+
*/
|
|
80
|
+
function selectFailedContentToDrop(entries, limits) {
|
|
81
|
+
const now = limits.now || Date.now();
|
|
82
|
+
const cutoff = now - limits.maxAge * 1000;
|
|
83
|
+
|
|
84
|
+
const newestFirst = entries.slice().sort((a, b) => b.finishedOn - a.finishedOn);
|
|
85
|
+
|
|
86
|
+
const drop = [];
|
|
87
|
+
let kept = 0;
|
|
88
|
+
let keptBytes = 0;
|
|
89
|
+
for (const entry of newestFirst) {
|
|
90
|
+
const size = Number(entry.size) || 0;
|
|
91
|
+
if (entry.finishedOn < cutoff || kept >= limits.maxCount || keptBytes + size > limits.maxBytes) {
|
|
92
|
+
drop.push(entry);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
kept++;
|
|
96
|
+
keptBytes += size;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return drop.reverse();
|
|
100
|
+
}
|
|
101
|
+
|
|
53
102
|
module.exports = {
|
|
54
103
|
buildRetentionPolicy,
|
|
104
|
+
selectFailedContentToDrop,
|
|
55
105
|
COMPLETED_JOB_RETENTION_AGE,
|
|
56
106
|
FAILED_JOB_RETENTION_AGE,
|
|
57
|
-
FAILED_JOB_RETENTION_COUNT
|
|
107
|
+
FAILED_JOB_RETENTION_COUNT,
|
|
108
|
+
DEFAULT_FAILED_CONTENT_RETENTION_COUNT,
|
|
109
|
+
DEFAULT_FAILED_CONTENT_RETENTION_SIZE
|
|
58
110
|
};
|
package/lib/routes-ui.js
CHANGED
|
@@ -15,6 +15,7 @@ const adminConfigRoutes = require('./ui-routes/admin-config-routes');
|
|
|
15
15
|
const accountRoutes = require('./ui-routes/account-routes');
|
|
16
16
|
const mcpConsentRoutes = require('./ui-routes/mcp-consent-routes');
|
|
17
17
|
const tlsConfigRoutes = require('./ui-routes/tls-config-routes');
|
|
18
|
+
const queueRoutes = require('./ui-routes/queue-routes');
|
|
18
19
|
|
|
19
20
|
function applyRoutes(server, call) {
|
|
20
21
|
// Initialize admin entity routes (webhooks, templates, gateways, tokens)
|
|
@@ -32,6 +33,10 @@ function applyRoutes(server, call) {
|
|
|
32
33
|
// System internals / threads tools routes
|
|
33
34
|
internalsRoutes({ server, call });
|
|
34
35
|
|
|
36
|
+
// The queue browser (webhook deliveries, outgoing messages, exports) and the redirects
|
|
37
|
+
// from the retired bull-board page
|
|
38
|
+
queueRoutes({ server });
|
|
39
|
+
|
|
35
40
|
// Dashboard and standalone informational pages (legal, upgrade)
|
|
36
41
|
dashboardRoutes({ server, call });
|
|
37
42
|
|
package/lib/schemas.js
CHANGED
|
@@ -62,6 +62,11 @@ const externalAccountCustomValidator = (value, helpers) => {
|
|
|
62
62
|
|
|
63
63
|
const RESYNC_DELAY = 15 * 60;
|
|
64
64
|
|
|
65
|
+
// Bounds for the per-account IDLE restart interval, in milliseconds. Anything shorter than the
|
|
66
|
+
// floor is polling rather than idling, and the RFC 3501 autologout timer is 30 minutes
|
|
67
|
+
const IMAP_MAX_IDLE_TIME_MIN = 10 * 1000;
|
|
68
|
+
const IMAP_MAX_IDLE_TIME_MAX = 30 * 60 * 1000;
|
|
69
|
+
|
|
65
70
|
config.api = config.api || {
|
|
66
71
|
port: 3000,
|
|
67
72
|
host: '127.0.0.1',
|
|
@@ -673,6 +678,14 @@ const settingsQuerySchema = Object.fromEntries(
|
|
|
673
678
|
})
|
|
674
679
|
);
|
|
675
680
|
|
|
681
|
+
const imapMaxIdleTimeSchema = Joi.number()
|
|
682
|
+
.integer()
|
|
683
|
+
.min(IMAP_MAX_IDLE_TIME_MIN)
|
|
684
|
+
.max(IMAP_MAX_IDLE_TIME_MAX)
|
|
685
|
+
.example(2 * 60 * 1000)
|
|
686
|
+
.description('Restart IDLE after this many milliseconds. Also caps the polling interval for servers without IDLE support.')
|
|
687
|
+
.meta({ usage: FIELD_USAGE.maxIdleTime });
|
|
688
|
+
|
|
676
689
|
const imapSchema = {
|
|
677
690
|
auth: Joi.object({
|
|
678
691
|
user: Joi.string().max(256).required().example('myuser@gmail.com').description('Username or email address for IMAP authentication'),
|
|
@@ -742,6 +755,7 @@ const imapSchema = {
|
|
|
742
755
|
.description('Do not use IMAP4rev2 even if the server supports it')
|
|
743
756
|
.meta({ usage: FIELD_USAGE.disableIMAP4rev2 }),
|
|
744
757
|
resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations').default(RESYNC_DELAY),
|
|
758
|
+
maxIdleTime: imapMaxIdleTimeSchema,
|
|
745
759
|
disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
|
|
746
760
|
|
|
747
761
|
sentMailPath: Joi.string()
|
|
@@ -948,6 +962,7 @@ const imapUpdateSchema = {
|
|
|
948
962
|
.description('Do not use IMAP4rev2 even if the server supports it')
|
|
949
963
|
.meta({ usage: FIELD_USAGE.disableIMAP4rev2 }),
|
|
950
964
|
resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations'),
|
|
965
|
+
maxIdleTime: imapMaxIdleTimeSchema.allow(null),
|
|
951
966
|
|
|
952
967
|
disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
|
|
953
968
|
|
|
@@ -2304,6 +2319,13 @@ const outboxEntrySchema = Joi.object({
|
|
|
2304
2319
|
attemptsMade: Joi.number().integer().example(3).description('Number of delivery attempts made'),
|
|
2305
2320
|
attempts: Joi.number().integer().example(3).description('Maximum delivery attempts before marking as failed'),
|
|
2306
2321
|
|
|
2322
|
+
state: Joi.string()
|
|
2323
|
+
.valid('delayed', 'waiting', 'active', 'failed')
|
|
2324
|
+
.example('waiting')
|
|
2325
|
+
.description('Where the message is in the queue')
|
|
2326
|
+
.meta({ enumDescriptions: ENUM_DESCRIPTIONS.outboxState })
|
|
2327
|
+
.label('OutboxState'),
|
|
2328
|
+
|
|
2307
2329
|
progress: Joi.object({
|
|
2308
2330
|
status: Joi.string()
|
|
2309
2331
|
.valid('queued', 'processing', 'smtp-starting', 'smtp-completed', 'submitted', 'error')
|
|
@@ -2319,7 +2341,11 @@ const outboxEntrySchema = Joi.object({
|
|
|
2319
2341
|
error: Joi.object({
|
|
2320
2342
|
message: Joi.string().example('Authentication failed').description('Error description'),
|
|
2321
2343
|
code: Joi.string().example('EAUTH').description('Error code'),
|
|
2322
|
-
statusCode: Joi.number().integer().example(502).description('SMTP response code')
|
|
2344
|
+
statusCode: Joi.number().integer().example(502).description('SMTP response code'),
|
|
2345
|
+
responseCode: Joi.number()
|
|
2346
|
+
.integer()
|
|
2347
|
+
.example(550)
|
|
2348
|
+
.description('The SMTP reply code when the receiving server answered. A 5xx other than 503 is a permanent rejection that is not retried')
|
|
2323
2349
|
})
|
|
2324
2350
|
.label('OutboxListProgressError')
|
|
2325
2351
|
.description('Error details (when status is "error")'),
|
|
@@ -2600,6 +2626,18 @@ const errorResponseSchemas = {
|
|
|
2600
2626
|
}
|
|
2601
2627
|
}),
|
|
2602
2628
|
|
|
2629
|
+
409: errorResponseEntry({
|
|
2630
|
+
statusCode: 409,
|
|
2631
|
+
statusText: 'Conflict',
|
|
2632
|
+
messageExample: 'Only a message whose delivery has failed can be retried',
|
|
2633
|
+
label: 'ConflictErrorResponse',
|
|
2634
|
+
title: 'Conflict error',
|
|
2635
|
+
description: 'Conflict - the entity is not in a state the operation applies to',
|
|
2636
|
+
fields: {
|
|
2637
|
+
code: Joi.string().example('NotFailed').description('Machine-readable error code')
|
|
2638
|
+
}
|
|
2639
|
+
}),
|
|
2640
|
+
|
|
2603
2641
|
422: errorResponseEntry({
|
|
2604
2642
|
statusCode: 422,
|
|
2605
2643
|
statusText: 'Unprocessable Entity',
|
|
@@ -2747,5 +2785,7 @@ module.exports = {
|
|
|
2747
2785
|
exportIdSchema,
|
|
2748
2786
|
pubSubErrorSchema,
|
|
2749
2787
|
apiResponses,
|
|
2750
|
-
ENUM_DESCRIPTIONS
|
|
2788
|
+
ENUM_DESCRIPTIONS,
|
|
2789
|
+
IMAP_MAX_IDLE_TIME_MIN,
|
|
2790
|
+
IMAP_MAX_IDLE_TIME_MAX
|
|
2751
2791
|
};
|
package/lib/security-headers.js
CHANGED
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
// server rendered with the request's nonce run, so markup that reaches the page
|
|
19
19
|
// (the message browser renders sanitised email HTML, the error logs show inbound
|
|
20
20
|
// headers) cannot bring code with it.
|
|
21
|
-
// bullBoard - /admin/bull-board, third-party markup this code does not render: no nonce, and
|
|
22
|
-
// the Google Fonts stylesheet its shell links.
|
|
23
21
|
// public - everything else: the hosted authentication form, unsubscribe, the OAuth landing
|
|
24
22
|
// page, error pages. Operators inject their own HTML into these pages
|
|
25
23
|
// (templateHtmlHead / templateHeader, a documented feature whose own example is
|
|
@@ -36,7 +34,6 @@
|
|
|
36
34
|
// not care about the case.
|
|
37
35
|
|
|
38
36
|
const crypto = require('crypto');
|
|
39
|
-
const { BULL_BOARD_BASE_PATH } = require('./consts');
|
|
40
37
|
|
|
41
38
|
const CSP_HEADER = 'content-security-policy';
|
|
42
39
|
const CSP_REPORT_ONLY_HEADER = 'content-security-policy-report-only';
|
|
@@ -94,21 +91,6 @@ const CSP_PRESETS = Object.freeze({
|
|
|
94
91
|
})
|
|
95
92
|
}),
|
|
96
93
|
|
|
97
|
-
bullBoard: Object.freeze({
|
|
98
|
-
directives: Object.freeze({
|
|
99
|
-
'default-src': "'self'",
|
|
100
|
-
'script-src': "'self'",
|
|
101
|
-
'style-src': "'self' 'unsafe-inline' https://fonts.googleapis.com",
|
|
102
|
-
'font-src': "'self' https://fonts.gstatic.com",
|
|
103
|
-
'img-src': "'self' data:",
|
|
104
|
-
'connect-src': "'self'",
|
|
105
|
-
'object-src': "'none'",
|
|
106
|
-
// its shell carries a <base href> for the mount path
|
|
107
|
-
'base-uri': "'self'",
|
|
108
|
-
'form-action': "'self'"
|
|
109
|
-
})
|
|
110
|
-
}),
|
|
111
|
-
|
|
112
94
|
api: Object.freeze({
|
|
113
95
|
directives: Object.freeze({
|
|
114
96
|
'default-src': "'none'"
|
|
@@ -186,8 +168,7 @@ const PROFILES = Object.freeze({
|
|
|
186
168
|
cacheControl: 'no-store'
|
|
187
169
|
}),
|
|
188
170
|
public: Object.freeze({ headers: PAGE_HEADERS, csp: 'public', frameAncestors: null, cacheControl: null }),
|
|
189
|
-
admin: Object.freeze({ headers: ADMIN_HEADERS, csp: 'admin', frameAncestors: "'self'", cacheControl: 'no-store' })
|
|
190
|
-
bullBoard: Object.freeze({ headers: ADMIN_HEADERS, csp: 'bullBoard', frameAncestors: "'self'", cacheControl: 'no-store' })
|
|
171
|
+
admin: Object.freeze({ headers: ADMIN_HEADERS, csp: 'admin', frameAncestors: "'self'", cacheControl: 'no-store' })
|
|
191
172
|
});
|
|
192
173
|
|
|
193
174
|
/**
|
|
@@ -259,12 +240,9 @@ function attachSecurityContext(request, { secureOrigin = false } = {}) {
|
|
|
259
240
|
function profileNameFor(path, tags = []) {
|
|
260
241
|
path = typeof path === 'string' ? path : '';
|
|
261
242
|
|
|
262
|
-
if (tags.includes('static')
|
|
243
|
+
if (tags.includes('static')) {
|
|
263
244
|
return 'static';
|
|
264
245
|
}
|
|
265
|
-
if (path === BULL_BOARD_BASE_PATH || path.startsWith(`${BULL_BOARD_BASE_PATH}/`)) {
|
|
266
|
-
return 'bullBoard';
|
|
267
|
-
}
|
|
268
246
|
if (isAdminPath(path)) {
|
|
269
247
|
return 'admin';
|
|
270
248
|
}
|
|
@@ -172,7 +172,7 @@ const MCP_SECTIONS = {
|
|
|
172
172
|
{
|
|
173
173
|
value: 'operate',
|
|
174
174
|
label: 'Operate',
|
|
175
|
-
hint: 'Also reconnect, add and test accounts, change settings, and manage OAuth2 applications, gateways and templates.',
|
|
175
|
+
hint: 'Also reconnect, add and test accounts, change settings, retry or expedite queued messages, and manage OAuth2 applications, gateways and templates.',
|
|
176
176
|
caveat: 'Settings changes take effect at once, and moving the webhook target sends future message notifications, message text included, elsewhere. Reconfiguring an account or gateway can send its stored credential to a new host, and reconfiguring an OAuth2 application can redirect where future sign-ins deliver their authorization codes. It cannot delete anything, create tokens or read stored credentials.',
|
|
177
177
|
pairs: pairsOf(MCP_SCOPES.manage, grant => grant.action !== ACTION.DESTRUCTIVE)
|
|
178
178
|
},
|
|
@@ -19,6 +19,7 @@ const capa = require('../capa');
|
|
|
19
19
|
const { Account, authFailureDisabledAt, isOperatorDisabled } = require('../account');
|
|
20
20
|
const { formatGmailWatch } = require('../account/account-state');
|
|
21
21
|
const { SPECIAL_USE_PATH_FIELDS } = require('./special-use-paths');
|
|
22
|
+
const { imapMaxIdleTimeFormSchema, imapMaxIdleTimeFormValue, applyImapMaxIdleTimeForm } = require('./imap-idle-field');
|
|
22
23
|
|
|
23
24
|
const { Gateway } = require('../gateway');
|
|
24
25
|
const { autodetectImapSettings, resolveAppPassword, getAppPassword } = require('../autodetect-imap-settings');
|
|
@@ -58,6 +59,7 @@ const {
|
|
|
58
59
|
windowedPageLinks
|
|
59
60
|
} = require('./route-helpers');
|
|
60
61
|
const { webhooks: Webhooks } = require('../webhooks');
|
|
62
|
+
const { accountQueueSummary } = require('../queue-browser');
|
|
61
63
|
const { describeEffectiveRouting, isDeliverableRoute } = require('../webhook-routing');
|
|
62
64
|
const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
|
|
63
65
|
|
|
@@ -1635,6 +1637,7 @@ function init(args) {
|
|
|
1635
1637
|
'accounts/account',
|
|
1636
1638
|
{
|
|
1637
1639
|
pageTitle: `Accounts - ${accountData.email}`,
|
|
1640
|
+
queuedMessages: await accountQueueSummary(request.params.account),
|
|
1638
1641
|
|
|
1639
1642
|
menuAccounts: true,
|
|
1640
1643
|
account: accountData,
|
|
@@ -2122,6 +2125,7 @@ function init(args) {
|
|
|
2122
2125
|
// shown and the save writes `disabled: false`, which lifts the park.
|
|
2123
2126
|
imap_disabled: (!accountData.imap && !accountData.oauth2) || isOperatorDisabled(accountData),
|
|
2124
2127
|
imap_tls_ignoreCertErrors: !!(accountData.imap && accountData.imap.tls && accountData.imap.tls.rejectUnauthorized === false),
|
|
2128
|
+
imap_maxIdleTime: imapMaxIdleTimeFormValue(accountData.imap),
|
|
2125
2129
|
smtp: !!accountData.smtp,
|
|
2126
2130
|
smtp_tls_ignoreCertErrors: !!(accountData.smtp && accountData.smtp.tls && accountData.smtp.tls.rejectUnauthorized === false),
|
|
2127
2131
|
oauth2: !!accountData.oauth2,
|
|
@@ -2251,6 +2255,7 @@ function init(args) {
|
|
|
2251
2255
|
}
|
|
2252
2256
|
}
|
|
2253
2257
|
|
|
2258
|
+
applyImapMaxIdleTimeForm(request.payload, oldData.imap, updateKeys);
|
|
2254
2259
|
if ('imap_auth_user' in request.payload) {
|
|
2255
2260
|
let imapAuth = Object.assign((oldData.imap && oldData.imap.auth) || {}, { user: request.payload.imap_auth_user });
|
|
2256
2261
|
if (request.payload.imap_auth_pass) {
|
|
@@ -2448,6 +2453,7 @@ function init(args) {
|
|
|
2448
2453
|
.description('Disable IMAP if you are using this email account to only send emails.'),
|
|
2449
2454
|
|
|
2450
2455
|
imap_resyncDelay: Joi.number().integer().empty(''),
|
|
2456
|
+
imap_maxIdleTime: imapMaxIdleTimeFormSchema,
|
|
2451
2457
|
|
|
2452
2458
|
// allow('') rather than empty('').default(null): see the write loop above, where the
|
|
2453
2459
|
// presence of the key is what says the form showed the field at all
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Joi = require('joi');
|
|
4
|
+
const { IMAP_MAX_IDLE_TIME_MIN, IMAP_MAX_IDLE_TIME_MAX } = require('../schemas');
|
|
5
|
+
|
|
6
|
+
// The IDLE restart interval on the account edit form. The form takes seconds, like the resync
|
|
7
|
+
// interval next to it, while the account stores milliseconds, the unit of the ImapFlow option it
|
|
8
|
+
// feeds. Split out of ./account-routes.js, which is at its size budget.
|
|
9
|
+
|
|
10
|
+
// allow('') with no default, so the key is present exactly when the page showed the input (see the
|
|
11
|
+
// folder overrides in ./account-routes.js for what a default does to that presence test)
|
|
12
|
+
const imapMaxIdleTimeFormSchema = Joi.number()
|
|
13
|
+
.integer()
|
|
14
|
+
.min(IMAP_MAX_IDLE_TIME_MIN / 1000)
|
|
15
|
+
.max(IMAP_MAX_IDLE_TIME_MAX / 1000)
|
|
16
|
+
.allow('', null);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The value the edit form shows for a stored account
|
|
20
|
+
* @param {Object} [accountImap] - The account's stored `imap` object
|
|
21
|
+
* @returns {number|string} Seconds, or an empty string when unset
|
|
22
|
+
*/
|
|
23
|
+
const imapMaxIdleTimeFormValue = accountImap => (accountImap?.maxIdleTime ? accountImap.maxIdleTime / 1000 : '');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Writes a submitted interval into the IMAP update. Written only when the page showed the input and
|
|
27
|
+
* the effective value changed, because any `imap` diff forces a reconnect
|
|
28
|
+
* @param {Object} payload - The validated form payload
|
|
29
|
+
* @param {Object} [oldImap] - The account's stored `imap` object
|
|
30
|
+
* @param {Object} updateKeys - The IMAP keys to write, modified in place
|
|
31
|
+
*/
|
|
32
|
+
function applyImapMaxIdleTimeForm(payload, oldImap, updateKeys) {
|
|
33
|
+
if (!('imap_maxIdleTime' in payload)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const value = payload.imap_maxIdleTime ? payload.imap_maxIdleTime * 1000 : null;
|
|
37
|
+
if (value !== (oldImap?.maxIdleTime || null)) {
|
|
38
|
+
updateKeys.maxIdleTime = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { imapMaxIdleTimeFormSchema, imapMaxIdleTimeFormValue, applyImapMaxIdleTimeForm };
|