emailengine-app 2.79.7 → 2.79.9
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/.github/dependabot.yml +22 -0
- package/.github/workflows/test.yml +39 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +37 -0
- package/DOCKER_DEPLOYMENT.md +8 -7
- package/Dockerfile +35 -11
- package/bin/emailengine.js +29 -13
- package/config/default.toml +15 -4
- package/copy-static-files.sh +23 -5
- package/data/google-crawlers.json +7 -1
- package/docker-compose.yml +12 -3
- package/install.sh +2 -0
- package/lib/account.js +26 -1
- package/lib/api-routes/account-routes.js +14 -3
- package/lib/api-routes/bull-board-routes.js +3 -2
- package/lib/api-routes/mailbox-routes.js +4 -1
- package/lib/api-routes/message-routes.js +6 -5
- package/lib/api-routes/outbox-routes.js +7 -4
- package/lib/api-routes/route-helpers.js +8 -0
- package/lib/api-routes/settings-routes.js +34 -25
- package/lib/api-routes/stats-routes.js +8 -1
- package/lib/api-routes/submit-routes.js +2 -1
- package/lib/api-routes/template-routes.js +3 -2
- package/lib/auth-token.js +73 -2
- package/lib/autodetect-imap-settings.js +33 -25
- package/lib/bounce-detect.js +45 -0
- package/lib/consts.js +13 -2
- package/lib/egress-fetch.js +133 -0
- package/lib/egress-filter.js +39 -4
- package/lib/email-client/base-client.js +274 -24
- package/lib/email-client/gmail/gmail-api.js +15 -7
- package/lib/email-client/gmail-client.js +121 -64
- package/lib/email-client/imap/mailbox.js +18 -59
- package/lib/email-client/imap-client.js +53 -29
- package/lib/email-client/notification-handler.js +11 -2
- package/lib/email-client/outlook/graph-api.js +106 -90
- package/lib/email-client/outlook-client.js +222 -106
- package/lib/export.js +35 -2
- package/lib/generate-text-preview.js +10 -5
- package/lib/handlebars-helpers.js +129 -0
- package/lib/headers-rewriter.js +1 -1
- package/lib/imap-proxy-auth.js +41 -21
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
- package/lib/imapproxy/imap-server.js +9 -10
- package/lib/llm-pre-process.js +4 -1
- package/lib/mcp/json-schema.js +50 -2
- package/lib/openapi/index.js +3 -0
- package/lib/outbox.js +50 -8
- package/lib/pre-process.js +4 -1
- package/lib/rate-limit.js +23 -4
- package/lib/rewrite-text-nodes.js +12 -1
- package/lib/schemas.js +37 -8
- package/lib/security-headers.js +396 -0
- package/lib/sentry.js +36 -4
- package/lib/settings.js +19 -1
- package/lib/smtp-auth.js +86 -7
- package/lib/sso.js +13 -3
- package/lib/submit-progress.js +29 -0
- package/lib/templates.js +11 -0
- package/lib/tools.js +361 -173
- package/lib/ui-routes/account-routes.js +73 -13
- package/lib/ui-routes/admin-config-routes.js +7 -21
- package/lib/ui-routes/admin-entities-routes.js +42 -12
- package/lib/ui-routes/auth-routes.js +87 -28
- package/lib/ui-routes/dashboard-routes.js +1 -1
- package/lib/ui-routes/export-routes.js +4 -0
- package/lib/ui-routes/internals-routes.js +2 -0
- package/lib/ui-routes/mcp-consent-routes.js +12 -2
- package/lib/ui-routes/network-config-routes.js +6 -5
- package/lib/ui-routes/oauth-config-routes.js +12 -1
- package/lib/ui-routes/route-helpers.js +65 -14
- package/lib/ui-routes/settings-page.js +10 -0
- package/lib/ui-routes/smtp-test-routes.js +7 -0
- package/lib/ui-routes/suppression-list-routes.js +16 -5
- package/lib/ui-routes/unsubscribe-routes.js +22 -3
- package/lib/webhook-egress.js +5 -0
- package/lib/webhooks.js +14 -2
- package/package.json +23 -26
- package/sbom.json +1 -1
- package/server.js +100 -71
- package/static/css/flyonui.css +1 -1
- package/static/js/ace/css/ace.css +1462 -0
- package/static/js/ace/css/kuroir-1.png +0 -0
- package/static/js/ace/css/kuroir-2.png +0 -0
- package/static/js/ace/css/main-1.png +0 -0
- package/static/js/ace/css/main-10.svg +4 -0
- package/static/js/ace/css/main-11.svg +5 -0
- package/static/js/ace/css/main-12.svg +4 -0
- package/static/js/ace/css/main-13.png +0 -0
- package/static/js/ace/css/main-14.png +0 -0
- package/static/js/ace/css/main-15.png +0 -0
- package/static/js/ace/css/main-16.png +0 -0
- package/static/js/ace/css/main-17.png +0 -0
- package/static/js/ace/css/main-18.png +0 -0
- package/static/js/ace/css/main-19.png +0 -0
- package/static/js/ace/css/main-2.png +0 -0
- package/static/js/ace/css/main-20.png +0 -0
- package/static/js/ace/css/main-21.png +0 -0
- package/static/js/ace/css/main-22.png +0 -0
- package/static/js/ace/css/main-23.png +0 -0
- package/static/js/ace/css/main-24.png +0 -0
- package/static/js/ace/css/main-25.svg +1 -0
- package/static/js/ace/css/main-26.png +0 -0
- package/static/js/ace/css/main-3.png +0 -0
- package/static/js/ace/css/main-4.png +0 -0
- package/static/js/ace/css/main-5.svg +7 -0
- package/static/js/ace/css/main-6.svg +9 -0
- package/static/js/ace/css/main-7.svg +7 -0
- package/static/js/ace/css/main-8.svg +9 -0
- package/static/js/ace/css/main-9.svg +6 -0
- package/static/js/ace/css/theme/kuroir.css +78 -0
- package/static/js/ace/css/theme/tomorrow_night.css +128 -0
- package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
- package/static/js/ace/css/theme/xcode.css +106 -0
- package/static/js/ace/css/tomorrow_night-1.png +0 -0
- package/static/js/ace/css/tomorrow_night-2.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
- package/static/js/ace/css/xcode-1.png +0 -0
- package/static/js/ace/css/xcode-2.png +0 -0
- package/static/js/ee-client.js +256 -102
- package/static/js/public.js +7 -0
- package/static/js/ui.js +32 -0
- package/static/licenses.html +338 -298
- package/static/vendor/simplewebauthn/browser.min.js +2 -2
- package/translations/messages.pot +158 -112
- package/views/account/passkeys.hbs +8 -0
- package/views/account/password.hbs +11 -0
- package/views/account/security.hbs +18 -7
- package/views/accounts/account.hbs +21 -38
- package/views/accounts/browse.hbs +3 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +11 -3
- package/views/config/ai.hbs +3 -1
- package/views/config/branding.hbs +4 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/email-processing.hbs +2 -0
- package/views/config/imap-proxy.hbs +3 -1
- package/views/config/license.hbs +1 -1
- package/views/config/logging.hbs +3 -1
- package/views/config/mcp.hbs +3 -1
- package/views/config/network.hbs +16 -16
- package/views/config/oauth/app.hbs +4 -4
- package/views/config/security.hbs +2 -0
- package/views/config/service.hbs +3 -1
- package/views/config/smtp.hbs +3 -1
- package/views/config/webhooks.hbs +4 -2
- package/views/error.hbs +10 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +9 -14
- package/views/layout/login.hbs +1 -1
- package/views/layout/prompt.hbs +1 -1
- package/views/layout/public.hbs +1 -1
- package/views/legal.hbs +1 -1
- package/views/mcp/authorize.hbs +1 -1
- package/views/partials/ace_assets.hbs +13 -0
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +3 -3
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +6 -6
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/template_form.hbs +2 -2
- package/views/partials/test_send.hbs +7 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/ui/details.hbs +2 -2
- package/views/partials/ui/env-managed-alert.hbs +19 -0
- package/views/partials/webhook_form.hbs +1 -1
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/templates/template.hbs +2 -2
- package/views/tokens/new.hbs +1 -1
- package/views/unsubscribe.hbs +7 -1
- package/views/webhooks/webhook.hbs +2 -2
- package/workers/api.js +179 -175
- package/workers/export.js +1 -5
- package/workers/imap.js +33 -6
- package/workers/smtp.js +19 -43
- package/workers/submit.js +31 -13
- package/workers/webhooks.js +9 -24
- package/lib/reconnection-manager.js +0 -106
- package/static/front/EmailEngine_logo_horiz.png +0 -0
- package/static/front/EmailEngine_logo_vert.png +0 -0
- package/static/front/index.html +0 -57
- package/static/front/logo.png +0 -0
- package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
package/workers/smtp.js
CHANGED
|
@@ -6,8 +6,8 @@ const packageData = require('../package.json');
|
|
|
6
6
|
const config = require('@zone-eu/wild-config');
|
|
7
7
|
const logger = require('../lib/logger');
|
|
8
8
|
|
|
9
|
-
const { getDuration, emitChangeEvent, readEnvValue, threadStats, loadTlsConfig, getByteSize } = require('../lib/tools');
|
|
10
|
-
const { createSmtpAuthHandler } = require('../lib/smtp-auth');
|
|
9
|
+
const { getDuration, emitChangeEvent, readEnvValue, threadStats, loadTlsConfig, assertTlsCredentials, getByteSize, httpAgent } = require('../lib/tools');
|
|
10
|
+
const { createSmtpAuthHandler, createSmtpAccountResolver } = require('../lib/smtp-auth');
|
|
11
11
|
|
|
12
12
|
const { initSentry } = require('../lib/sentry');
|
|
13
13
|
initSentry('smtp');
|
|
@@ -15,7 +15,6 @@ initSentry('smtp');
|
|
|
15
15
|
const { SMTPServer } = require('smtp-server');
|
|
16
16
|
const util = require('util');
|
|
17
17
|
const { redis } = require('../lib/db');
|
|
18
|
-
const { Account } = require('../lib/account');
|
|
19
18
|
const getSecret = require('../lib/get-secret');
|
|
20
19
|
const { collectMessage } = require('../lib/smtp-message-processor');
|
|
21
20
|
const settings = require('../lib/settings');
|
|
@@ -40,6 +39,12 @@ const DEFAULT_EENGINE_TIMEOUT = 10 * 1000;
|
|
|
40
39
|
const MAX_SMTP_MESSAGE_SIZE = getByteSize(readEnvValue('EENGINE_MAX_SMTP_MESSAGE_SIZE') || config.smtp.maxMessageSize) || DEFAULT_MAX_SMTP_MESSAGE_SIZE;
|
|
41
40
|
const EENGINE_TIMEOUT = getDuration(readEnvValue('EENGINE_TIMEOUT') || config.service.commandTimeout) || DEFAULT_EENGINE_TIMEOUT;
|
|
42
41
|
|
|
42
|
+
// Every connection buffers its message in memory up to MAX_SMTP_MESSAGE_SIZE before it is queued,
|
|
43
|
+
// so the concurrent connection count is what bounds this worker's memory. Excess connections are
|
|
44
|
+
// refused with a 421, which any SMTP client retries. The default matches Postfix's smtpd limit.
|
|
45
|
+
const DEFAULT_SMTP_MAX_CLIENTS = 100;
|
|
46
|
+
const SMTP_MAX_CLIENTS = Number(readEnvValue('EENGINE_SMTP_MAX_CLIENTS') || config.smtp.maxClients) || DEFAULT_SMTP_MAX_CLIENTS;
|
|
47
|
+
|
|
43
48
|
const ACCOUNT_CACHE = new WeakMap();
|
|
44
49
|
|
|
45
50
|
let callQueue = new Map();
|
|
@@ -107,46 +112,11 @@ for (let level of ['trace', 'debug', 'info', 'warn', 'error', 'fatal']) {
|
|
|
107
112
|
};
|
|
108
113
|
}
|
|
109
114
|
|
|
110
|
-
// Authentication
|
|
111
|
-
// without booting this worker. The shared ACCOUNT_CACHE and call() are injected
|
|
112
|
-
//
|
|
115
|
+
// Authentication and account resolution live in lib/smtp-auth.js so they can be unit tested
|
|
116
|
+
// without booting this worker. The shared ACCOUNT_CACHE and call() are injected so onAuth
|
|
117
|
+
// caches the Account that the resolver hands to the submission.
|
|
113
118
|
const onAuth = createSmtpAuthHandler({ accountCache: ACCOUNT_CACHE, call });
|
|
114
|
-
|
|
115
|
-
async function checkAccountData(session, messageMeta) {
|
|
116
|
-
let accountObject;
|
|
117
|
-
|
|
118
|
-
if (!session.eeAuthEnabled && messageMeta.requestedAccount) {
|
|
119
|
-
// load account data
|
|
120
|
-
accountObject = new Account({ account: messageMeta.requestedAccount, redis, call, secret: await getSecret() });
|
|
121
|
-
let accountData;
|
|
122
|
-
try {
|
|
123
|
-
// throws if unknown user
|
|
124
|
-
accountData = await accountObject.loadAccountData();
|
|
125
|
-
if (accountData) {
|
|
126
|
-
ACCOUNT_CACHE.set(session, accountObject);
|
|
127
|
-
logger.debug({ msg: 'Resolved requested account', account: messageMeta.requestedAccount });
|
|
128
|
-
}
|
|
129
|
-
} catch (err) {
|
|
130
|
-
logger.warn({ msg: 'Failed to resolve requested account', account: messageMeta.requestedAccount, err });
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
accountObject = ACCOUNT_CACHE.get(session);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!session.eeAuthEnabled && !messageMeta.requestedAccount && !accountObject) {
|
|
137
|
-
let err = new Error('Sender account ID not provided, can not send mail');
|
|
138
|
-
err.responseCode = 451;
|
|
139
|
-
throw err;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!accountObject) {
|
|
143
|
-
let err = new Error('Failed to load account');
|
|
144
|
-
err.responseCode = 451;
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return accountObject;
|
|
149
|
-
}
|
|
119
|
+
const resolveAccount = createSmtpAccountResolver({ accountCache: ACCOUNT_CACHE, call });
|
|
150
120
|
|
|
151
121
|
async function init() {
|
|
152
122
|
let server;
|
|
@@ -158,6 +128,7 @@ async function init() {
|
|
|
158
128
|
disableReverseLookup: true,
|
|
159
129
|
banner: 'EmailEngine MSA',
|
|
160
130
|
size: MAX_SMTP_MESSAGE_SIZE,
|
|
131
|
+
maxClients: SMTP_MAX_CLIENTS,
|
|
161
132
|
useProxy: await settings.get('smtpServerProxy')
|
|
162
133
|
};
|
|
163
134
|
|
|
@@ -167,6 +138,9 @@ async function init() {
|
|
|
167
138
|
|
|
168
139
|
environment: 'ee',
|
|
169
140
|
|
|
141
|
+
// long-lived client, see LiveDispatcher in lib/tools.js
|
|
142
|
+
dispatcher: httpAgent.live,
|
|
143
|
+
|
|
170
144
|
logger: logger.child({ sub: 'acme' }),
|
|
171
145
|
|
|
172
146
|
encryptFn: async value => {
|
|
@@ -232,7 +206,7 @@ async function init() {
|
|
|
232
206
|
throw err;
|
|
233
207
|
}
|
|
234
208
|
|
|
235
|
-
let accountObject = await
|
|
209
|
+
let accountObject = await resolveAccount(session, messageMeta);
|
|
236
210
|
|
|
237
211
|
let payload = {
|
|
238
212
|
envelope: {
|
|
@@ -302,6 +276,8 @@ async function init() {
|
|
|
302
276
|
serverOptions.key = certificateData.privateKey;
|
|
303
277
|
}
|
|
304
278
|
}
|
|
279
|
+
|
|
280
|
+
assertTlsCredentials(serverOptions, 'The SMTP server');
|
|
305
281
|
} else {
|
|
306
282
|
serverOptions.disabledCommands = ['STARTTLS'];
|
|
307
283
|
serverOptions.hideSTARTTLS = true;
|
package/workers/submit.js
CHANGED
|
@@ -7,7 +7,7 @@ const config = require('@zone-eu/wild-config');
|
|
|
7
7
|
const logger = require('../lib/logger');
|
|
8
8
|
|
|
9
9
|
const { REDIS_PREFIX } = require('../lib/consts');
|
|
10
|
-
const { getDuration, readEnvValue, threadStats
|
|
10
|
+
const { getDuration, readEnvValue, threadStats } = require('../lib/tools');
|
|
11
11
|
const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
12
12
|
const settings = require('../lib/settings');
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ const { redis, queueConf, submitQueue } = require('../lib/db');
|
|
|
19
19
|
const { Worker, UnrecoverableError } = require('bullmq');
|
|
20
20
|
const { Account } = require('../lib/account');
|
|
21
21
|
const getSecret = require('../lib/get-secret');
|
|
22
|
-
const
|
|
22
|
+
const { decodeQueueEntry } = require('../lib/outbox');
|
|
23
23
|
|
|
24
24
|
const { EMAIL_FAILED_NOTIFY } = require('../lib/consts');
|
|
25
25
|
|
|
@@ -43,6 +43,7 @@ const SUBMIT_QC = (readEnvValue('EENGINE_SUBMIT_QC') && Number(readEnvValue('EEN
|
|
|
43
43
|
const SUBMIT_DELAY = getDuration(readEnvValue('EENGINE_SUBMIT_DELAY') || config.submitDelay) || null;
|
|
44
44
|
|
|
45
45
|
const { shouldDiscardJob, willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
46
|
+
const { isAlreadySent } = require('../lib/submit-progress');
|
|
46
47
|
const { packRpcError, unpackRpcError } = require('../lib/worker-rpc-error');
|
|
47
48
|
|
|
48
49
|
let callQueue = new Map();
|
|
@@ -142,6 +143,29 @@ const submitWorker = new Worker(
|
|
|
142
143
|
job.data.queueId = job.data.qId;
|
|
143
144
|
}
|
|
144
145
|
|
|
146
|
+
// A job re-run after a stall (heartbeat kill, crash, a shutdown drain that could not cover
|
|
147
|
+
// a long SMTP transaction plus the Sent-folder upload) comes back with the progress its
|
|
148
|
+
// previous run stored. Once that says the MTA accepted the message, sending again would
|
|
149
|
+
// deliver a duplicate under the same queueId: the message is done, only the bookkeeping
|
|
150
|
+
// after the 250 was cut short. The catch below covers the same state for a run that got
|
|
151
|
+
// as far as throwing; this covers the run that never got to throw anything.
|
|
152
|
+
if (isAlreadySent(job.progress)) {
|
|
153
|
+
logger.info({
|
|
154
|
+
msg: 'Skipping re-run of an already sent message',
|
|
155
|
+
action: 'submit',
|
|
156
|
+
queue: job.queue.name,
|
|
157
|
+
code: 'result_success',
|
|
158
|
+
job: job.id,
|
|
159
|
+
event: job.name,
|
|
160
|
+
account: job.data.account,
|
|
161
|
+
queueId: job.data.queueId,
|
|
162
|
+
messageId: job.data.messageId,
|
|
163
|
+
progress: job.progress.status,
|
|
164
|
+
attemptsMade: job.attemptsMade
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
145
169
|
let queueEntryBuf = await redis.hgetBuffer(`${REDIS_PREFIX}iaq:${job.data.account}`, job.data.queueId);
|
|
146
170
|
if (!queueEntryBuf) {
|
|
147
171
|
// nothing to do here
|
|
@@ -155,7 +179,10 @@ const submitWorker = new Worker(
|
|
|
155
179
|
|
|
156
180
|
let queueEntry;
|
|
157
181
|
try {
|
|
158
|
-
|
|
182
|
+
// Rejects a value that decodes to something other than a map as well, otherwise the
|
|
183
|
+
// job metadata assignment below throws a TypeError against it and the entry is retried
|
|
184
|
+
// as a failed delivery instead of being dropped as the corrupt entry it is
|
|
185
|
+
queueEntry = decodeQueueEntry(queueEntryBuf);
|
|
159
186
|
} catch (err) {
|
|
160
187
|
logger.error({ msg: 'Failed to parse queued email entry', job: job.id, account: job.data.account, queueId: job.data.queueId, err });
|
|
161
188
|
try {
|
|
@@ -166,11 +193,6 @@ const submitWorker = new Worker(
|
|
|
166
193
|
return;
|
|
167
194
|
}
|
|
168
195
|
|
|
169
|
-
if (!queueEntry) {
|
|
170
|
-
//could be expired?
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
196
|
let accountObject = new Account({ account: job.data.account, redis, call, secret: await getSecret() });
|
|
175
197
|
|
|
176
198
|
logger.trace({
|
|
@@ -231,7 +253,7 @@ const submitWorker = new Worker(
|
|
|
231
253
|
} catch (err) {
|
|
232
254
|
try {
|
|
233
255
|
const submitJobEntry = await submitQueue.getJob(job.id);
|
|
234
|
-
if (submitJobEntry &&
|
|
256
|
+
if (submitJobEntry && isAlreadySent(submitJobEntry.progress)) {
|
|
235
257
|
// SMTP transition succeeded, can accept even if the process yielded in error
|
|
236
258
|
logger.trace({
|
|
237
259
|
msg: 'Submitted queued message for delivery',
|
|
@@ -484,10 +506,6 @@ parentPort.on('message', message => {
|
|
|
484
506
|
parentPort.postMessage(Object.assign({ cmd: 'resp', mid: message.mid }, packRpcError(err)));
|
|
485
507
|
});
|
|
486
508
|
}
|
|
487
|
-
|
|
488
|
-
if (message && message.cmd === 'settings') {
|
|
489
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
490
|
-
}
|
|
491
509
|
});
|
|
492
510
|
|
|
493
511
|
logger.info({ msg: 'Started SMTP submission worker thread', version: packageData.version });
|
package/workers/webhooks.js
CHANGED
|
@@ -10,7 +10,7 @@ const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
|
10
10
|
|
|
11
11
|
const { GooglePubSub } = require('../lib/oauth/pubsub/google');
|
|
12
12
|
|
|
13
|
-
const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret,
|
|
13
|
+
const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, redactUrlCredentials, splitUrlCredentials } = require('../lib/tools');
|
|
14
14
|
const { sendWebhookRequest } = require('../lib/webhook-request');
|
|
15
15
|
const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
16
16
|
const { validateWebhookTarget } = require('../lib/webhook-egress');
|
|
@@ -24,7 +24,6 @@ const { Worker, UnrecoverableError } = require('bullmq');
|
|
|
24
24
|
const settings = require('../lib/settings');
|
|
25
25
|
|
|
26
26
|
const { REDIS_PREFIX, ACCOUNT_DELETED_NOTIFY, MESSAGE_NEW_NOTIFY } = require('../lib/consts');
|
|
27
|
-
const he = require('he');
|
|
28
27
|
|
|
29
28
|
const { fetch: fetchCmd } = require('undici');
|
|
30
29
|
|
|
@@ -190,10 +189,6 @@ parentPort.on('message', message => {
|
|
|
190
189
|
});
|
|
191
190
|
});
|
|
192
191
|
}
|
|
193
|
-
|
|
194
|
-
if (message && message.cmd === 'settings') {
|
|
195
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
196
|
-
}
|
|
197
192
|
});
|
|
198
193
|
|
|
199
194
|
const notifyWorker = new Worker(
|
|
@@ -393,21 +388,9 @@ const notifyWorker = new Worker(
|
|
|
393
388
|
'X-EE-Wh-Queued-Time': Math.round(Math.max(0, (Date.now() - job.timestamp) / 1000)) + 's'
|
|
394
389
|
};
|
|
395
390
|
|
|
396
|
-
let parsed =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (parsed.username) {
|
|
400
|
-
username = he.decode(parsed.username);
|
|
401
|
-
parsed.username = '';
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (parsed.password) {
|
|
405
|
-
password = he.decode(parsed.password);
|
|
406
|
-
parsed.password = '';
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (username || password) {
|
|
410
|
-
headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
|
|
391
|
+
let { url: parsed, authorization } = splitUrlCredentials(webhooks);
|
|
392
|
+
if (authorization) {
|
|
393
|
+
headers.Authorization = authorization;
|
|
411
394
|
}
|
|
412
395
|
|
|
413
396
|
if (customRoute) {
|
|
@@ -522,7 +505,9 @@ const notifyWorker = new Worker(
|
|
|
522
505
|
event: job.name,
|
|
523
506
|
message: err.message,
|
|
524
507
|
time: Date.now(),
|
|
525
|
-
|
|
508
|
+
// stored without credentials: the flag is read back through the
|
|
509
|
+
// webhook route listing, the account page and the settings API
|
|
510
|
+
url: redactUrlCredentials(customRoute.targetUrl),
|
|
526
511
|
code: err.code,
|
|
527
512
|
statusCode: err.statusCode
|
|
528
513
|
})
|
|
@@ -535,7 +520,7 @@ const notifyWorker = new Worker(
|
|
|
535
520
|
event: job.name,
|
|
536
521
|
message: err.message,
|
|
537
522
|
time: Date.now(),
|
|
538
|
-
url:
|
|
523
|
+
url: redactedWebhooks,
|
|
539
524
|
code: err.code,
|
|
540
525
|
statusCode: err.statusCode
|
|
541
526
|
})
|
|
@@ -545,7 +530,7 @@ const notifyWorker = new Worker(
|
|
|
545
530
|
event: job.name,
|
|
546
531
|
message: err.message,
|
|
547
532
|
time: Date.now(),
|
|
548
|
-
url:
|
|
533
|
+
url: redactedWebhooks,
|
|
549
534
|
code: err.code,
|
|
550
535
|
statusCode: err.statusCode
|
|
551
536
|
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ReconnectionManager - Helper class for consistent reconnection behavior
|
|
5
|
-
* Provides capped exponential backoff with jitter for reconnection attempts
|
|
6
|
-
*/
|
|
7
|
-
class ReconnectionManager {
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
this.baseDelay = options.baseDelay || 2000;
|
|
10
|
-
this.maxDelay = options.maxDelay || 30000;
|
|
11
|
-
this.backoffMultiplier = options.backoffMultiplier || 1.5;
|
|
12
|
-
this.jitterMs = options.jitterMs || 1000;
|
|
13
|
-
this.attempts = 0;
|
|
14
|
-
this.currentDelay = this.baseDelay;
|
|
15
|
-
this.logger = options.logger;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Calculate the next reconnection delay with exponential backoff and jitter
|
|
20
|
-
* @returns {number} Delay in milliseconds before next reconnection attempt
|
|
21
|
-
*/
|
|
22
|
-
getNextDelay() {
|
|
23
|
-
// Calculate delay with exponential backoff, capped at maxDelay
|
|
24
|
-
this.currentDelay = Math.min(this.maxDelay, this.baseDelay * Math.pow(this.backoffMultiplier, Math.min(this.attempts, 10)));
|
|
25
|
-
|
|
26
|
-
// Add jitter to prevent synchronized reconnection storms
|
|
27
|
-
const jitter = Math.random() * this.jitterMs;
|
|
28
|
-
const totalDelay = this.currentDelay + jitter;
|
|
29
|
-
|
|
30
|
-
this.attempts++;
|
|
31
|
-
|
|
32
|
-
if (this.logger) {
|
|
33
|
-
this.logger.debug({
|
|
34
|
-
msg: 'Calculated reconnection delay',
|
|
35
|
-
attempt: this.attempts,
|
|
36
|
-
delay: totalDelay,
|
|
37
|
-
baseDelay: this.currentDelay
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return totalDelay;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Reset the reconnection manager state (typically called on successful connection)
|
|
46
|
-
*/
|
|
47
|
-
reset() {
|
|
48
|
-
this.attempts = 0;
|
|
49
|
-
this.currentDelay = this.baseDelay;
|
|
50
|
-
|
|
51
|
-
if (this.logger) {
|
|
52
|
-
this.logger.debug({
|
|
53
|
-
msg: 'Reconnection manager reset'
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Wait for the calculated delay and then execute the reconnection function
|
|
60
|
-
* @param {Function} reconnectFn - The async function to execute for reconnection
|
|
61
|
-
* @returns {Promise} Result of the reconnection function
|
|
62
|
-
*/
|
|
63
|
-
async waitAndReconnect(reconnectFn) {
|
|
64
|
-
const delay = this.getNextDelay();
|
|
65
|
-
|
|
66
|
-
if (this.logger) {
|
|
67
|
-
this.logger.debug({
|
|
68
|
-
msg: 'Waiting before reconnection attempt',
|
|
69
|
-
delay,
|
|
70
|
-
attempt: this.attempts
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const result = await reconnectFn();
|
|
78
|
-
this.reset(); // Reset on success
|
|
79
|
-
return result;
|
|
80
|
-
} catch (err) {
|
|
81
|
-
// Don't reset, keep incrementing delay
|
|
82
|
-
if (this.logger) {
|
|
83
|
-
this.logger.warn({
|
|
84
|
-
msg: 'Reconnection attempt failed',
|
|
85
|
-
attempt: this.attempts,
|
|
86
|
-
err
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get current state of the manager
|
|
95
|
-
* @returns {Object} Current state including attempts and delay
|
|
96
|
-
*/
|
|
97
|
-
getState() {
|
|
98
|
-
return {
|
|
99
|
-
attempts: this.attempts,
|
|
100
|
-
currentDelay: this.currentDelay,
|
|
101
|
-
nextDelay: this.getNextDelay()
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = { ReconnectionManager };
|
|
Binary file
|
|
Binary file
|
package/static/front/index.html
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" class="h-100">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
|
6
|
-
<meta name="description" content="EmailEngine" />
|
|
7
|
-
<title>EmailEngine Set-up</title>
|
|
8
|
-
<link
|
|
9
|
-
rel="stylesheet"
|
|
10
|
-
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"
|
|
11
|
-
integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn"
|
|
12
|
-
crossorigin="anonymous"
|
|
13
|
-
/>
|
|
14
|
-
</head>
|
|
15
|
-
|
|
16
|
-
<body class="d-flex flex-column h-100">
|
|
17
|
-
<main role="main" class="flex-shrink-0">
|
|
18
|
-
<div class="container mt-4">
|
|
19
|
-
<div class="d-flex">
|
|
20
|
-
<img src="./EmailEngine_logo_horiz.png" style="display: block; max-height: 80px; max-width: 100%" />
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
<div class="row mt-4">
|
|
24
|
-
<div class="col-12 col-sm-12 col-md-12 col-lg-8">
|
|
25
|
-
<p>
|
|
26
|
-
EmailEngine is an email client software designed for applications, not individual users. It connects to users' email servers and
|
|
27
|
-
translates REST API requests from the app into IMAP and SMTP commands, or into Gmail API or Microsoft Graph API requests.
|
|
28
|
-
Additionally, it sends webhooks to notify the app of events such as new or deleted emails.
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
<div class="mt-4 alert alert-info">
|
|
32
|
-
To continue setting up your EmailEngine installation, log in to your server using SSH:<br />
|
|
33
|
-
<kbd style="display: block; padding: 1.2rem; margin-top: 1rem">$ ssh root@<span id="hostname">example.com</span></kbd>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
</main>
|
|
39
|
-
|
|
40
|
-
<footer class="footer mt-auto py-3">
|
|
41
|
-
<div class="container">
|
|
42
|
-
<div class="row">
|
|
43
|
-
<div class="col-sm-8">
|
|
44
|
-
EmailEngine
|
|
45
|
-
<span class="text-muted">© 2020-<span id="curyear">2025</span></span>
|
|
46
|
-
Postal Systems OÜ.
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</footer>
|
|
51
|
-
|
|
52
|
-
<script>
|
|
53
|
-
document.getElementById('hostname').textContent = window.location.hostname;
|
|
54
|
-
document.getElementById('curyear').textContent = new Date().getFullYear();
|
|
55
|
-
</script>
|
|
56
|
-
</body>
|
|
57
|
-
</html>
|
package/static/front/logo.png
DELETED
|
Binary file
|