emailengine-app 2.89.0 → 2.91.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/.ncurc.js +19 -8
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +73 -0
- package/Dockerfile +7 -3
- package/ENVIRONMENT.md +24 -23
- package/README.md +1 -1
- package/bin/healthcheck.js +1 -1
- package/copy-static-files.sh +0 -8
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -4
- package/lib/account/field-codec.js +396 -0
- package/lib/account-assignment.js +26 -9
- package/lib/account.js +196 -462
- package/lib/api-routes/account-routes.js +49 -6
- package/lib/api-routes/route-metadata.js +5 -2
- package/lib/api-routes/submit-routes.js +15 -2
- package/lib/api-token-auth.js +342 -274
- package/lib/arf-detect.js +174 -149
- package/lib/attachment-size.js +29 -0
- package/lib/autodetect-imap-settings.js +482 -296
- package/lib/consts.js +5 -5
- package/lib/db.js +1 -4
- package/lib/email-client/base-client.js +907 -780
- package/lib/email-client/gmail-client.js +557 -450
- package/lib/email-client/imap/cid-parts.js +61 -0
- package/lib/email-client/imap/mailbox.js +376 -422
- package/lib/email-client/imap/sync-operations.js +239 -178
- package/lib/email-client/imap-client.js +5 -5
- package/lib/email-client/message-builder.js +4 -5
- package/lib/email-client/new-message-steps.js +168 -2
- package/lib/email-client/outlook/graph-message.js +266 -0
- package/lib/email-client/outlook/subscription-expiry.js +30 -0
- package/lib/email-client/outlook-client.js +652 -808
- package/lib/get-raw-email.js +338 -232
- package/lib/get-secret.js +1 -4
- package/lib/imapproxy/imap-server.js +5 -5
- package/lib/license-subscription.js +60 -0
- package/lib/load-env.js +48 -0
- package/lib/logger-consts.js +37 -1
- package/lib/logger.js +1 -4
- package/lib/mail-probe.js +157 -0
- package/lib/mcp/tools.js +244 -207
- package/lib/metric-values.js +76 -0
- package/lib/metrics.js +320 -0
- package/lib/oauth/gmail.js +39 -120
- package/lib/oauth/http-request.js +195 -0
- package/lib/oauth/mail-ru.js +33 -60
- package/lib/oauth/outlook.js +37 -137
- package/lib/oauth/pubsub/google.js +176 -117
- package/lib/oauth2-apps.js +440 -463
- package/lib/openapi/build-document.js +10 -10
- package/lib/read-env-value.js +31 -7
- package/lib/redis-backend-warnings.js +70 -0
- package/lib/route-descriptors.js +78 -0
- package/lib/schemas.js +10 -1
- package/lib/sentry-integrations.js +299 -0
- package/lib/sentry.js +75 -27
- package/lib/sso-routes.js +249 -0
- package/lib/sso.js +29 -6
- package/lib/tools.js +17 -28
- package/lib/ui-routes/account-edit-form.js +198 -0
- package/lib/ui-routes/account-page.js +241 -0
- package/lib/ui-routes/account-routes.js +46 -349
- package/lib/ui-routes/account-setup.js +1 -1
- package/lib/ui-routes/auth-routes.js +10 -10
- package/lib/ui-routes/provider-signin.js +187 -0
- package/lib/ui-routes/route-helpers.js +1 -1
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/ui-view-context.js +328 -0
- package/lib/utils/public-suffix.js +22 -101
- package/lib/web-safe-html.js +20 -7
- package/lib/worker-metrics.js +82 -0
- package/list-generate.js +2 -5
- package/package.json +28 -24
- package/sbom.json +360 -1030
- package/scripts/refresh-test-tokens.js +1 -1
- package/server.js +400 -677
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +55 -1
- package/static/css/src/app.tailwind.css +18 -0
- package/static/js/ee-client.js +2619 -645
- package/static/js/ui.js +12 -2
- package/static/licenses.html +224 -764
- package/translations/de.mo +0 -0
- package/translations/de.po +429 -390
- package/translations/en.mo +0 -0
- package/translations/en.po +342 -257
- package/translations/es.mo +0 -0
- package/translations/es.po +440 -395
- package/translations/et.mo +0 -0
- package/translations/et.po +425 -375
- package/translations/fr.mo +0 -0
- package/translations/fr.po +425 -383
- package/translations/it.mo +0 -0
- package/translations/it.po +441 -394
- package/translations/ja.mo +0 -0
- package/translations/ja.po +408 -335
- package/translations/messages.pot +188 -130
- package/translations/nl.mo +0 -0
- package/translations/nl.po +419 -382
- package/translations/pl.mo +0 -0
- package/translations/pl.po +425 -379
- package/translations/sv.mo +0 -0
- package/translations/sv.po +440 -388
- package/translations/tr.mo +0 -0
- package/translations/tr.po +441 -387
- package/views/account-identity-error.hbs +1 -1
- package/views/account-workspace-error.hbs +2 -2
- package/views/accounts/browse.hbs +19 -1
- package/views/accounts/register/imap-server.hbs +22 -7
- package/views/accounts/register/imap.hbs +3 -0
- package/views/accounts/register/index.hbs +1 -27
- package/views/accounts/register/provider-signin.hbs +58 -0
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/provider_signin_button.hbs +30 -0
- package/views/queues/index.hbs +1 -1
- package/views/redirect.hbs +1 -1
- package/views/unsubscribe.hbs +6 -6
- package/workers/api.js +20 -451
- package/data/public_suffix_list.dat +0 -16698
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The account update the admin account edit form (POST /admin/accounts/{account}/edit in
|
|
4
|
+
// account-routes.js) asks for, built from the validated payload and the stored account. Pure, so
|
|
5
|
+
// test/account-edit-form-test.js covers it without a route.
|
|
6
|
+
//
|
|
7
|
+
// The rule that runs through all of it: an untouched form save must not add or change keys,
|
|
8
|
+
// because any imap diff forces a reconnect. So a value is written only when the effective state
|
|
9
|
+
// changes, and a field the form did not show is not written at all.
|
|
10
|
+
//
|
|
11
|
+
// The stored connection objects are copied before anything is applied to them: the update is
|
|
12
|
+
// built on the copy, so the loaded account is left as it was.
|
|
13
|
+
|
|
14
|
+
const { SPECIAL_USE_PATH_FIELDS } = require('./special-use-paths');
|
|
15
|
+
const { applyImapMaxIdleTimeForm } = require('./imap-idle-field');
|
|
16
|
+
const { applySecurityForm } = require('./connection-security-form');
|
|
17
|
+
const { parseCustomHeaders } = require('./form-lists');
|
|
18
|
+
|
|
19
|
+
// A copy of a stored connection object deep enough for the form to apply its changes to: the
|
|
20
|
+
// only nested objects it writes into are `auth` and `tls`
|
|
21
|
+
function copyConnection(stored) {
|
|
22
|
+
if (!stored) {
|
|
23
|
+
return stored;
|
|
24
|
+
}
|
|
25
|
+
let copy = Object.assign({}, stored);
|
|
26
|
+
for (let key of ['auth', 'tls']) {
|
|
27
|
+
if (copy[key] && typeof copy[key] === 'object') {
|
|
28
|
+
copy[key] = Object.assign({}, copy[key]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return copy;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The account-level fields of the update.
|
|
36
|
+
*
|
|
37
|
+
* @param {String} account - account ID
|
|
38
|
+
* @param {Object} payload - the validated form payload
|
|
39
|
+
* @returns {Object} the update, without the connection sections
|
|
40
|
+
*/
|
|
41
|
+
function buildBaseUpdates(account, payload) {
|
|
42
|
+
let updates = {
|
|
43
|
+
account,
|
|
44
|
+
name: payload.name || '',
|
|
45
|
+
email: payload.email,
|
|
46
|
+
// Empty clears the pin (Account.update hdel's it), which is the only way an operator
|
|
47
|
+
// can unblock a legitimate mailbox migration on a pinned account.
|
|
48
|
+
expectedEmail: payload.expectedEmail || null,
|
|
49
|
+
proxy: payload.proxy,
|
|
50
|
+
smtpEhloName: payload.smtpEhloName,
|
|
51
|
+
webhooks: payload.webhooks
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Absent only from a request that did not render the field, keep the stored headers then
|
|
55
|
+
if (typeof payload.customHeaders === 'string') {
|
|
56
|
+
updates.webhooksCustomHeaders = parseCustomHeaders(payload.customHeaders);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return updates;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The `imap` object of the update, for a payload whose IMAP section was submitted.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} payload - the validated form payload
|
|
66
|
+
* @param {Object} [storedImap] - the stored `imap` object
|
|
67
|
+
* @returns {Object} the stored object with the submitted changes applied
|
|
68
|
+
*/
|
|
69
|
+
function buildImapUpdates(payload, storedImap) {
|
|
70
|
+
let imap = copyConnection(storedImap);
|
|
71
|
+
let imapTls = (imap && imap.tls) || {};
|
|
72
|
+
|
|
73
|
+
let updateKeys = {};
|
|
74
|
+
|
|
75
|
+
for (let key of ['host', 'port', 'disabled']) {
|
|
76
|
+
// The form always submits the disabled checkbox, and a stored account that never had the key
|
|
77
|
+
// is enabled just like one that stores `false`, so `disabled` is written only when the
|
|
78
|
+
// effective state changes. Unchecking it on a parked account still writes `false`, which
|
|
79
|
+
// lifts the park
|
|
80
|
+
if (`imap_${key}` in payload && (key !== 'disabled' || !payload.imap_disabled !== !(imap && imap.disabled))) {
|
|
81
|
+
updateKeys[key] = payload[`imap_${key}`];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The special-use folder overrides. An empty input means "no override" and has to
|
|
86
|
+
// be written as null to unset one, while a field the form never showed must not be
|
|
87
|
+
// written at all: these inputs live inside the IMAP section, which is hidden for an
|
|
88
|
+
// account whose IMAP the operator switched off. The schema therefore allows the
|
|
89
|
+
// empty string instead of defaulting to null - a default is inserted by joi for
|
|
90
|
+
// every key the browser did not send, which made the presence check below always
|
|
91
|
+
// true, so an unrelated save (a rename, a new webhook URL) wiped every override set
|
|
92
|
+
// over PUT /v1/account/{account}. Same presence test imap_auth_user relies on.
|
|
93
|
+
for (const field of SPECIAL_USE_PATH_FIELDS) {
|
|
94
|
+
const payloadKey = `imap_${field.key}`;
|
|
95
|
+
if (!(payloadKey in payload)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const value = payload[payloadKey] || null;
|
|
99
|
+
// Written only when the effective value changes, like the TLS flags below: an
|
|
100
|
+
// untouched save must not add keys, because any imap diff forces a reconnect
|
|
101
|
+
if (value !== ((imap && imap[field.key]) || null)) {
|
|
102
|
+
updateKeys[field.key] = value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
applyImapMaxIdleTimeForm(payload, imap, updateKeys);
|
|
107
|
+
if ('imap_auth_user' in payload) {
|
|
108
|
+
let imapAuth = Object.assign((imap && imap.auth) || {}, { user: payload.imap_auth_user });
|
|
109
|
+
if (payload.imap_auth_pass) {
|
|
110
|
+
imapAuth.pass = payload.imap_auth_pass;
|
|
111
|
+
}
|
|
112
|
+
updateKeys.auth = imapAuth;
|
|
113
|
+
updateKeys.secure = payload.imap_secure;
|
|
114
|
+
// The connection settings section is hidden for OAuth2 and disabled
|
|
115
|
+
// accounts, so like `secure` these only apply when it was submitted.
|
|
116
|
+
// Written only when the effective state changes - an untouched form
|
|
117
|
+
// save must not add new keys, as any imap diff forces a reconnect
|
|
118
|
+
applySecurityForm(payload, 'imap', imap, updateKeys, imapTls);
|
|
119
|
+
if (payload.imap_disableIMAP4rev2 !== !!(imap && imap.disableIMAP4rev2)) {
|
|
120
|
+
updateKeys.disableIMAP4rev2 = payload.imap_disableIMAP4rev2;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// skipped while empty and absent from the stored account for the same
|
|
125
|
+
// reason as above - a no-op save must not introduce a tls:{} key
|
|
126
|
+
if (Object.keys(imapTls).length) {
|
|
127
|
+
updateKeys.tls = imapTls;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let updated = Object.assign(imap || {}, updateKeys);
|
|
131
|
+
|
|
132
|
+
if (payload.imap_resyncDelay) {
|
|
133
|
+
updated.resyncDelay = payload.imap_resyncDelay;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return updated;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The `smtp` object of the update, for a payload whose SMTP section was submitted.
|
|
141
|
+
*
|
|
142
|
+
* @param {Object} payload - the validated form payload
|
|
143
|
+
* @param {Object} [storedSmtp] - the stored `smtp` object
|
|
144
|
+
* @returns {Object} the stored object with the submitted changes applied
|
|
145
|
+
*/
|
|
146
|
+
function buildSmtpUpdates(payload, storedSmtp) {
|
|
147
|
+
let smtp = copyConnection(storedSmtp);
|
|
148
|
+
let smtpAuth = Object.assign((smtp && smtp.auth) || {}, { user: payload.smtp_auth_user });
|
|
149
|
+
let smtpTls = (smtp && smtp.tls) || {};
|
|
150
|
+
|
|
151
|
+
if (payload.smtp_auth_pass) {
|
|
152
|
+
smtpAuth.pass = payload.smtp_auth_pass;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let updated = Object.assign(smtp || {}, {
|
|
156
|
+
host: payload.smtp_host,
|
|
157
|
+
port: payload.smtp_port,
|
|
158
|
+
secure: payload.smtp_secure,
|
|
159
|
+
auth: smtpAuth
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// written only when the effective state changes, and the tls object is
|
|
163
|
+
// skipped while empty - same as the IMAP flags, a no-op save must not
|
|
164
|
+
// modify the stored account. When an SMTP object is stored, `updated` IS `smtp` (Object.assign
|
|
165
|
+
// wrote into the copy), so the comparison already sees the submitted host, port and auth; the
|
|
166
|
+
// security fields it reads are not among them. Without one, the comparison sees undefined.
|
|
167
|
+
applySecurityForm(payload, 'smtp', smtp, updated, smtpTls);
|
|
168
|
+
|
|
169
|
+
if (Object.keys(smtpTls).length) {
|
|
170
|
+
updated.tls = smtpTls;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return updated;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The whole update the form asks for.
|
|
178
|
+
*
|
|
179
|
+
* @param {String} account - account ID
|
|
180
|
+
* @param {Object} payload - the validated form payload
|
|
181
|
+
* @param {Object} oldData - the stored account
|
|
182
|
+
* @returns {Object} the update for Account.update()
|
|
183
|
+
*/
|
|
184
|
+
function buildAccountEditUpdates(account, payload, oldData) {
|
|
185
|
+
let updates = buildBaseUpdates(account, payload);
|
|
186
|
+
|
|
187
|
+
if (payload.imap) {
|
|
188
|
+
updates.imap = buildImapUpdates(payload, oldData.imap);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (payload.smtp) {
|
|
192
|
+
updates.smtp = buildSmtpUpdates(payload, oldData.smtp);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return updates;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
module.exports = { buildAccountEditUpdates, buildBaseUpdates, buildImapUpdates, buildSmtpUpdates };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Helpers of the account pages and the hosted setup form in lib/ui-routes/account-routes.js, kept apart so they can be
|
|
4
|
+
// tested without registering the routes and so the route module stays inside its size budget.
|
|
5
|
+
// Everything here is pure except loadWebhookRouting(), which reads the settings and routes the
|
|
6
|
+
// account page's webhook card describes.
|
|
7
|
+
|
|
8
|
+
const settings = require('../settings');
|
|
9
|
+
const { webhooks: Webhooks } = require('../webhooks');
|
|
10
|
+
const { describeEffectiveRouting, isDeliverableRoute } = require('../webhook-routing');
|
|
11
|
+
const { formatGmailWatch } = require('../account/account-state');
|
|
12
|
+
const { closedAfterConnectMessage } = require('./route-helpers');
|
|
13
|
+
|
|
14
|
+
// The SASL mechanisms the account page links to a specification, by upper-cased name
|
|
15
|
+
const SMTP_AUTH_INFO = {
|
|
16
|
+
LOGIN: { rfc: 'draft-murchison-sasl-login', url: 'https://datatracker.ietf.org/doc/html/draft-murchison-sasl-login' },
|
|
17
|
+
PLAIN: { rfc: 'RFC4616', url: 'https://www.rfc-editor.org/rfc/rfc4616.html' },
|
|
18
|
+
XOAUTH2: { rfc: 'xoauth2-protocol', url: 'https://developers.google.com/gmail/imap/xoauth2-protocol#smtp_protocol_exchange' },
|
|
19
|
+
OAUTHBEARER: { rfc: 'RFC7628', url: 'https://www.rfc-editor.org/rfc/rfc7628.html' }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Moves the AUTH lines out of an SMTP server's EHLO extension list and describes the mechanisms
|
|
24
|
+
* they name. The lines are read last to first, a repeated mechanism keeps its first place, and a
|
|
25
|
+
* known one becomes `{ auth, rfc, url }` while an unknown one stays a plain name.
|
|
26
|
+
*
|
|
27
|
+
* @param {string[]} smtpServerEhlo - EHLO extension lines, modified in place
|
|
28
|
+
* @returns {Array<string|Object>} the mechanisms
|
|
29
|
+
*/
|
|
30
|
+
function describeSmtpAuthMechanisms(smtpServerEhlo) {
|
|
31
|
+
let smtpAuthMechanisms = [];
|
|
32
|
+
for (let i = smtpServerEhlo.length - 1; i >= 0; i--) {
|
|
33
|
+
let entry = smtpServerEhlo[i];
|
|
34
|
+
if (/^auth\b/i.test(entry)) {
|
|
35
|
+
let authEntries = entry.split(/\s+/).slice(1);
|
|
36
|
+
if (authEntries.length) {
|
|
37
|
+
smtpAuthMechanisms = smtpAuthMechanisms.concat(authEntries);
|
|
38
|
+
}
|
|
39
|
+
smtpServerEhlo.splice(i, 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Array.from(new Set(smtpAuthMechanisms)).map(entry => {
|
|
44
|
+
let info = Object.hasOwn(SMTP_AUTH_INFO, entry.toUpperCase()) ? SMTP_AUTH_INFO[entry.toUpperCase()] : null;
|
|
45
|
+
return info ? { auth: entry, rfc: info.rfc, url: info.url } : entry;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The Gmail watch card of the account page, or false when the account has no watch to report.
|
|
51
|
+
*
|
|
52
|
+
* State comes from the same derivation the API reports, so the page and the response cannot
|
|
53
|
+
* disagree about whether push is working. The reason and the failed request stay here and out of
|
|
54
|
+
* the API: both are text the provider wrote, and this page is behind an admin session. NB! a watch
|
|
55
|
+
* that is still armed but whose last renewal failed now reads Failed rather than Active - it used
|
|
56
|
+
* to show the expiry alone and hide the failure in a tooltip, which said nothing was wrong right
|
|
57
|
+
* up to the day it lapsed
|
|
58
|
+
*
|
|
59
|
+
* @param {Object} accountData - the formatted account record
|
|
60
|
+
* @returns {Object|false}
|
|
61
|
+
*/
|
|
62
|
+
function buildGmailWatchView(accountData) {
|
|
63
|
+
let watchState = formatGmailWatch(accountData);
|
|
64
|
+
let gmailWatch = watchState
|
|
65
|
+
? {
|
|
66
|
+
lastCheckStr: watchState.lastCheck,
|
|
67
|
+
expiresStr: watchState.expires || false,
|
|
68
|
+
active: watchState.state === 'active',
|
|
69
|
+
stateLabel: { active: 'Active', error: 'Failed', expired: 'Expired' }[watchState.state] || 'Unknown',
|
|
70
|
+
// The reason and the failed request are read straight off the record here and
|
|
71
|
+
// deliberately absent from the shared derivation: both carry text the
|
|
72
|
+
// provider wrote, including the operator's own Pub/Sub topic path, and this
|
|
73
|
+
// page is behind an admin session while the API field is not
|
|
74
|
+
error: accountData.watchFailure ? accountData.watchFailure.err || 'Failed to set up Gmail pubsub watch' : false
|
|
75
|
+
}
|
|
76
|
+
: false;
|
|
77
|
+
|
|
78
|
+
// Not "watchFailure truthy means gmailWatch is": the derivation reports nothing for an
|
|
79
|
+
// account whose application has no Pub/Sub app, whatever record a previous one left
|
|
80
|
+
if (gmailWatch && accountData.watchFailure && accountData.watchFailure.req) {
|
|
81
|
+
gmailWatch.request = {
|
|
82
|
+
url: accountData.watchFailure.req.url,
|
|
83
|
+
status: accountData.watchFailure.req.status,
|
|
84
|
+
contentType: accountData.watchFailure.req.contentType,
|
|
85
|
+
response: accountData.watchFailure.req.response
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return gmailWatch;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Top-of-page alert for the account's primary problem, so a broken account is impossible to
|
|
94
|
+
* miss. Gated on the effective connection state (stateLabel.type) so a recovered account never
|
|
95
|
+
* shows a stale error; a stalled sync is surfaced separately because the account can otherwise
|
|
96
|
+
* be connected.
|
|
97
|
+
*
|
|
98
|
+
* @param {Object} accountData - the formatted account record
|
|
99
|
+
* @param {string|null} disabledByAuthFailureAt - when the auth-failure safety net parked it
|
|
100
|
+
* @returns {Object|null}
|
|
101
|
+
*/
|
|
102
|
+
function buildAccountAlert(accountData, disabledByAuthFailureAt) {
|
|
103
|
+
if (disabledByAuthFailureAt) {
|
|
104
|
+
// Ahead of the state alert: a parked account is not connecting at all, so why it
|
|
105
|
+
// was switched off is the more actionable of the two.
|
|
106
|
+
return {
|
|
107
|
+
title: 'Syncing was switched off',
|
|
108
|
+
message:
|
|
109
|
+
'EmailEngine stopped connecting this account after repeated authentication failures. Re-authenticating it turns syncing back on; "Resume syncing" retries with the stored credentials.',
|
|
110
|
+
timeLabel: 'Switched off',
|
|
111
|
+
time: disabledByAuthFailureAt
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (accountData.stateLabel && accountData.stateLabel.type === 'error') {
|
|
116
|
+
return {
|
|
117
|
+
title: accountData.stateLabel.name,
|
|
118
|
+
message: accountData.stateLabel.error
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (accountData.syncError) {
|
|
123
|
+
return {
|
|
124
|
+
title: 'Sync stalled',
|
|
125
|
+
path: accountData.syncError.path,
|
|
126
|
+
message: (accountData.syncError.error && (accountData.syncError.error.responseText || accountData.syncError.error.error)) || null
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The webhook routing card of the account page: where this account's events go.
|
|
135
|
+
*
|
|
136
|
+
* @param {Object} accountData - the formatted account record
|
|
137
|
+
* @returns {Promise<Object>} describeEffectiveRouting() output
|
|
138
|
+
*/
|
|
139
|
+
async function loadWebhookRouting(accountData) {
|
|
140
|
+
const [webhookSettings, webhookRoutesList] = await Promise.all([
|
|
141
|
+
settings.getMulti('webhooksEnabled', 'webhooks', 'webhookEvents', 'inboxNewOnly', 'webhooksCustomHeaders'),
|
|
142
|
+
Webhooks.list(0, 1000)
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
// The listing carries route metadata only, but the worker's delivery gate also
|
|
146
|
+
// requires a filter script, so the card needs the filter-presence markers for the
|
|
147
|
+
// routes it is about to present as delivering
|
|
148
|
+
const routeFilterInfo = await Webhooks.getFilterInfo(webhookRoutesList.webhooks.filter(isDeliverableRoute).map(route => route.id));
|
|
149
|
+
|
|
150
|
+
return describeEffectiveRouting({
|
|
151
|
+
webhooksEnabled: webhookSettings.webhooksEnabled,
|
|
152
|
+
globalWebhooks: webhookSettings.webhooks,
|
|
153
|
+
accountWebhooks: accountData.webhooks,
|
|
154
|
+
webhookEvents: webhookSettings.webhookEvents,
|
|
155
|
+
inboxNewOnly: webhookSettings.inboxNewOnly,
|
|
156
|
+
globalCustomHeaders: webhookSettings.webhooksCustomHeaders,
|
|
157
|
+
accountCustomHeaders: accountData.webhooksCustomHeaders,
|
|
158
|
+
// Non-deliverable routes were not probed; their hasFilter stays undefined, which
|
|
159
|
+
// describeEffectiveRouting() reads as "unknown" (and filters them out anyway)
|
|
160
|
+
routes: webhookRoutesList.webhooks.map(route => Object.assign({}, route, { hasFilter: routeFilterInfo.get(route.id) }))
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// The messages the hosted form's connection check shows for an IMAP error code. Built per call
|
|
165
|
+
// with the request's translator, and every message is a literal gettext() call so string
|
|
166
|
+
// extraction finds it. The raw socket or ImapFlow error text is not something the person at the
|
|
167
|
+
// form can act on. Closed-after-connect keeps the TLS hint the account state badge shows for it,
|
|
168
|
+
// because a wrong port/TLS pairing is the usual cause.
|
|
169
|
+
const IMAP_ERROR_MESSAGES = gt => ({
|
|
170
|
+
ENOTFOUND: gt.gettext('Server hostname was not found'),
|
|
171
|
+
EAI_AGAIN: gt.gettext('Server hostname was not found'),
|
|
172
|
+
AUTHENTICATIONFAILED: gt.gettext('Invalid username or password'),
|
|
173
|
+
ETIMEDOUT: gt.gettext('Connection timed out'),
|
|
174
|
+
ETIMEOUT: gt.gettext('Connection timed out'),
|
|
175
|
+
GREETING_TIMEOUT: gt.gettext('Connection timed out'),
|
|
176
|
+
ECONNREFUSED: gt.gettext('Could not connect to server'),
|
|
177
|
+
ECONNRESET: gt.gettext('Could not connect to server'),
|
|
178
|
+
EHOSTUNREACH: gt.gettext('Could not connect to server'),
|
|
179
|
+
ENETUNREACH: gt.gettext('Could not connect to server'),
|
|
180
|
+
ClosedAfterConnectTLS: closedAfterConnectMessage('ClosedAfterConnectTLS', gt),
|
|
181
|
+
ClosedAfterConnectText: closedAfterConnectMessage('ClosedAfterConnectText', gt),
|
|
182
|
+
EPROTO: gt.gettext('TLS protocol error'),
|
|
183
|
+
ERR_TLS_CERT_ALTNAME_INVALID: gt.gettext('TLS protocol error'),
|
|
184
|
+
ERR_SSL_WRONG_VERSION_NUMBER: gt.gettext('TLS protocol error'),
|
|
185
|
+
CERT_HAS_EXPIRED: gt.gettext('TLS protocol error'),
|
|
186
|
+
DEPTH_ZERO_SELF_SIGNED_CERT: gt.gettext('TLS protocol error'),
|
|
187
|
+
SELF_SIGNED_CERT_IN_CHAIN: gt.gettext('TLS protocol error'),
|
|
188
|
+
UNABLE_TO_VERIFY_LEAF_SIGNATURE: gt.gettext('TLS protocol error')
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// The same for the nodemailer error codes of the SMTP check
|
|
192
|
+
const SMTP_ERROR_MESSAGES = gt => ({
|
|
193
|
+
EDNS: gt.gettext('Server hostname was not found'),
|
|
194
|
+
EAUTH: gt.gettext('Invalid username or password'),
|
|
195
|
+
ENOAUTH: gt.gettext('Authentication credentials were not provided'),
|
|
196
|
+
EOAUTH2: gt.gettext('OAuth2 authentication failed'),
|
|
197
|
+
ETLS: gt.gettext('TLS protocol error'),
|
|
198
|
+
ETIMEDOUT: gt.gettext('Connection timed out'),
|
|
199
|
+
ECONNECTION: gt.gettext('Could not connect to server'),
|
|
200
|
+
EPROTOCOL: gt.gettext('Unexpected server response')
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Replaces `result.error` with the message for `result.code`. An unlisted code keeps its text
|
|
204
|
+
// unless `fallback` says the text describes a TLS failure.
|
|
205
|
+
function translateCheckError(result, messages, fallback, gt) {
|
|
206
|
+
if (Object.hasOwn(messages, result.code)) {
|
|
207
|
+
result.error = messages[result.code];
|
|
208
|
+
} else if (fallback(result)) {
|
|
209
|
+
result.error = gt.gettext('TLS protocol error');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// An unlisted IMAP code still reads as TLS when the text comes from OpenSSL, in any case
|
|
214
|
+
const imapTlsFallback = result => /openssl|ssl routines/i.test(result.error);
|
|
215
|
+
|
|
216
|
+
// Only an SMTP socket error is checked for OpenSSL text, and case-sensitively
|
|
217
|
+
const smtpTlsFallback = result => result.code === 'ESOCKET' && /openssl/.test(result.error);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Translates the error codes of a connection check (verifyAccountInfo) into messages the person
|
|
221
|
+
* at the hosted form can act on. Modifies the result in place; a side is only translated when it
|
|
222
|
+
* carries both an error and a code.
|
|
223
|
+
*
|
|
224
|
+
* @param {Object} verifyResult - `{ imap, smtp }` as verifyAccountInfo returns it, or a falsy value
|
|
225
|
+
* @param {Object} gt - the request's translator
|
|
226
|
+
*/
|
|
227
|
+
function translateConnectionErrors(verifyResult, gt) {
|
|
228
|
+
if (!verifyResult) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (verifyResult.imap && verifyResult.imap.error && verifyResult.imap.code) {
|
|
233
|
+
translateCheckError(verifyResult.imap, IMAP_ERROR_MESSAGES(gt), imapTlsFallback, gt);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (verifyResult.smtp && verifyResult.smtp.error && verifyResult.smtp.code) {
|
|
237
|
+
translateCheckError(verifyResult.smtp, SMTP_ERROR_MESSAGES(gt), smtpTlsFallback, gt);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
module.exports = { translateConnectionErrors, describeSmtpAuthMechanisms, buildGmailWatchView, buildAccountAlert, loadWebhookRouting };
|