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/lib/smtp-auth.js
CHANGED
|
@@ -9,7 +9,7 @@ const settings = require('./settings');
|
|
|
9
9
|
const { redis } = require('./db');
|
|
10
10
|
const { Account } = require('./account');
|
|
11
11
|
const getSecret = require('./get-secret');
|
|
12
|
-
const { validateAuthToken, REASON_MESSAGES } = require('./auth-token');
|
|
12
|
+
const { validateAuthToken, withAuthFailureBudget, REASON_MESSAGES } = require('./auth-token');
|
|
13
13
|
const { constantTimeEqual } = require('./tools');
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -21,11 +21,9 @@ const { constantTimeEqual } = require('./tools');
|
|
|
21
21
|
* @returns {Function} async onAuth(auth, session)
|
|
22
22
|
*/
|
|
23
23
|
function createSmtpAuthHandler({ accountCache, call }) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
24
|
+
// The credential check proper. Everything it throws is a refusal the client caused, which
|
|
25
|
+
// is what the failure budget in onAuth() counts.
|
|
26
|
+
async function authenticate(auth, session) {
|
|
29
27
|
let account = auth.username;
|
|
30
28
|
|
|
31
29
|
let smtpPassword = await settings.get('smtpServerPassword');
|
|
@@ -65,7 +63,88 @@ function createSmtpAuthHandler({ accountCache, call }) {
|
|
|
65
63
|
|
|
66
64
|
accountCache.set(session, accountObject);
|
|
67
65
|
return { user: accountData.account };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return async function onAuth(auth, session) {
|
|
69
|
+
if (!session.eeAuthEnabled) {
|
|
70
|
+
throw new Error('Authentication not enabled');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return await withAuthFailureBudget(
|
|
74
|
+
{ remoteAddress: session.remoteAddress, account: auth.username },
|
|
75
|
+
() => authenticate(auth, session),
|
|
76
|
+
() => {
|
|
77
|
+
let err = new Error(REASON_MESSAGES.limited);
|
|
78
|
+
// A temporary failure, so the client retries later instead of concluding that its
|
|
79
|
+
// credentials are wrong
|
|
80
|
+
err.responseCode = 454;
|
|
81
|
+
return err;
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Builds the resolver that finds the Account a submitted message is sent through.
|
|
89
|
+
*
|
|
90
|
+
* Lives beside the auth handler for the same reason it does: the worker can not be required
|
|
91
|
+
* from a test, and this is the other half of the decision of who may submit through which
|
|
92
|
+
* account. An authenticated session submits through the account it logged in as; a session
|
|
93
|
+
* opened while authentication was off names the account with the X-EE-Account header.
|
|
94
|
+
*
|
|
95
|
+
* @param {Object} deps
|
|
96
|
+
* @param {WeakMap} deps.accountCache - session -> Account cache shared with the auth handler
|
|
97
|
+
* @param {Function} deps.call - RPC function passed to the Account instance
|
|
98
|
+
* @returns {Function} async resolveAccount(session, messageMeta) -> Account
|
|
99
|
+
*/
|
|
100
|
+
function createSmtpAccountResolver({ accountCache, call }) {
|
|
101
|
+
return async function resolveAccount(session, messageMeta) {
|
|
102
|
+
let accountObject;
|
|
103
|
+
|
|
104
|
+
if (!session.eeAuthEnabled) {
|
|
105
|
+
// The session decided at connect time that no authentication was required. A client
|
|
106
|
+
// can hold a connection open for as long as it likes, so if the operator has switched
|
|
107
|
+
// authentication on since, the stale decision must not keep admitting submissions.
|
|
108
|
+
if (await settings.get('smtpServerAuthEnabled')) {
|
|
109
|
+
let err = new Error('Authentication required');
|
|
110
|
+
err.responseCode = 530;
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!session.eeAuthEnabled && messageMeta.requestedAccount) {
|
|
116
|
+
// Only a loaded account counts as resolved. Keeping the instance after a failed load
|
|
117
|
+
// let an unknown header value through here, to fail later inside the queueing with
|
|
118
|
+
// an error that never named the reason
|
|
119
|
+
let requested = new Account({ account: messageMeta.requestedAccount, redis, call, secret: await getSecret() });
|
|
120
|
+
try {
|
|
121
|
+
// throws if unknown user
|
|
122
|
+
if (await requested.loadAccountData()) {
|
|
123
|
+
accountObject = requested;
|
|
124
|
+
accountCache.set(session, accountObject);
|
|
125
|
+
logger.debug({ msg: 'Resolved requested account', account: messageMeta.requestedAccount });
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
logger.warn({ msg: 'Failed to resolve requested account', account: messageMeta.requestedAccount, err });
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
accountObject = accountCache.get(session);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!session.eeAuthEnabled && !messageMeta.requestedAccount && !accountObject) {
|
|
135
|
+
let err = new Error('Sender account ID not provided, can not send mail');
|
|
136
|
+
err.responseCode = 451;
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!accountObject) {
|
|
141
|
+
let err = new Error('Failed to load account');
|
|
142
|
+
err.responseCode = 451;
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return accountObject;
|
|
68
147
|
};
|
|
69
148
|
}
|
|
70
149
|
|
|
71
|
-
module.exports = { createSmtpAuthHandler };
|
|
150
|
+
module.exports = { createSmtpAuthHandler, createSmtpAccountResolver };
|
package/lib/sso.js
CHANGED
|
@@ -99,14 +99,24 @@ function parseScopes(scopeStr) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// Parse OIDC_ALLOWED_USERS into a normalized list of allow-list entries. Entries
|
|
102
|
-
//
|
|
103
|
-
//
|
|
102
|
+
// containing "@" are exact email matches, unless the "@" comes first, which makes
|
|
103
|
+
// the entry a domain match. An entry with no "@" at all cannot be an email, so it
|
|
104
|
+
// is read as a domain too: as an exact-email rule it could never match, and a bare
|
|
105
|
+
// "example.com" would have locked every user out with a generic "not authorized".
|
|
106
|
+
// Matching is case-insensitive.
|
|
104
107
|
function parseAllowList(str) {
|
|
105
108
|
return (str || '')
|
|
106
109
|
.split(',')
|
|
107
110
|
.map(entry => entry.trim().toLowerCase())
|
|
108
111
|
.filter(entry => entry)
|
|
109
|
-
.map(entry =>
|
|
112
|
+
.map(entry => {
|
|
113
|
+
const at = entry.indexOf('@');
|
|
114
|
+
if (at > 0) {
|
|
115
|
+
return { type: 'email', value: entry };
|
|
116
|
+
}
|
|
117
|
+
return { type: 'domain', value: at === 0 ? entry.slice(1) : entry };
|
|
118
|
+
})
|
|
119
|
+
.filter(entry => entry.value);
|
|
110
120
|
}
|
|
111
121
|
|
|
112
122
|
// Normalize a single group name: coerce to string, trim, and strip leading slashes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Progress states a submit job reaches only once the message has been accepted. The email client
|
|
4
|
+
// writes 'smtp-completed' right after the MTA's 250 (or the provider API's accept), and the submit
|
|
5
|
+
// worker writes 'submitted' once the post-send bookkeeping is through as well. Everything a job
|
|
6
|
+
// does after either state is bookkeeping (Sent-folder copy, draft cleanup, flag updates, gateway
|
|
7
|
+
// stats), so a job that is running again in one of these states must not send the message again.
|
|
8
|
+
//
|
|
9
|
+
// Split out of workers/submit.js because the worker boots a BullMQ consumer on require, which
|
|
10
|
+
// keeps the decision itself out of reach of a unit test.
|
|
11
|
+
const SENT_PROGRESS_STATES = new Set(['smtp-completed', 'submitted']);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tells whether a submit job's stored progress says the message was already accepted.
|
|
15
|
+
*
|
|
16
|
+
* BullMQ hands a re-run job the progress its previous run stored, so this is what a stalled job
|
|
17
|
+
* (heartbeat kill, crash, a shutdown drain that could not cover a long SMTP transaction) looks
|
|
18
|
+
* like when it comes back. A retry after a real delivery failure never carries one of these states:
|
|
19
|
+
* the failure path writes 'error' before it throws, and a run cut short before the 250 leaves
|
|
20
|
+
* 'processing' or 'smtp-starting' behind.
|
|
21
|
+
*
|
|
22
|
+
* @param {*} progress - job.progress as BullMQ hydrates it (an object, or 0 when never set)
|
|
23
|
+
* @returns {boolean} True when the message was already sent
|
|
24
|
+
*/
|
|
25
|
+
function isAlreadySent(progress) {
|
|
26
|
+
return !!(progress && typeof progress === 'object' && SENT_PROGRESS_STATES.has(progress.status));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { isAlreadySent, SENT_PROGRESS_STATES };
|
package/lib/templates.js
CHANGED
|
@@ -84,8 +84,19 @@ class TemplateHandler {
|
|
|
84
84
|
return id;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
// The inverse of generateId(): an 8-byte timestamp, a 4-byte counter, then the account id.
|
|
88
|
+
// Anything shorter than the fixed 12-byte header cannot be an id this module issued, and the
|
|
89
|
+
// routes accept any string up to 256 characters, so a malformed id is refused as "not found"
|
|
90
|
+
// here rather than failing on the header read.
|
|
87
91
|
unpackId(id) {
|
|
88
92
|
let idBuf = Buffer.from(id, 'base64');
|
|
93
|
+
if (idBuf.length < 4 + 8) {
|
|
94
|
+
let err = new Error('Document was not found');
|
|
95
|
+
err.code = 'NotFound';
|
|
96
|
+
err.statusCode = 404;
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
return {
|
|
90
101
|
counter: idBuf.readUInt32BE(8),
|
|
91
102
|
created: new Date(Number(idBuf.readBigUInt64BE(0))).toISOString(),
|