emailengine-app 2.79.6 → 2.79.8
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 +32 -0
- package/DOCKER_DEPLOYMENT.md +2 -0
- package/bin/emailengine.js +29 -13
- package/config/default.toml +13 -3
- package/data/google-crawlers.json +7 -1
- package/docker-compose.yml +12 -3
- package/install.sh +2 -0
- package/lib/api-routes/account-routes.js +14 -3
- 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/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/bounce-detect.js +45 -0
- package/lib/consts.js +9 -3
- 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/generate-text-preview.js +10 -5
- package/lib/headers-rewriter.js +1 -1
- package/lib/llm-pre-process.js +4 -1
- package/lib/mcp/json-schema.js +50 -2
- package/lib/outbox.js +22 -5
- package/lib/passkeys.js +39 -7
- package/lib/pre-process.js +4 -1
- package/lib/rewrite-text-nodes.js +12 -1
- package/lib/schemas.js +27 -5
- package/lib/settings.js +19 -1
- package/lib/sso.js +60 -7
- package/lib/submit-progress.js +29 -0
- package/lib/templates.js +11 -0
- package/lib/tools.js +115 -53
- package/lib/ui-routes/account-routes.js +79 -12
- 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 +242 -87
- package/lib/ui-routes/dashboard-routes.js +1 -1
- package/lib/ui-routes/internals-routes.js +2 -0
- package/lib/ui-routes/mcp-consent-routes.js +5 -2
- package/lib/ui-routes/network-config-routes.js +12 -3
- package/lib/ui-routes/oauth-config-routes.js +12 -1
- package/lib/ui-routes/route-helpers.js +41 -6
- package/lib/ui-routes/settings-page.js +10 -0
- package/lib/ui-routes/suppression-list-routes.js +16 -5
- package/lib/ui-routes/unsubscribe-routes.js +22 -3
- package/lib/webhooks.js +14 -2
- package/package.json +17 -17
- package/sbom.json +1 -1
- package/server.js +63 -35
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +55 -0
- package/static/js/app.js +4 -35
- package/static/js/passkey-register.js +50 -1
- package/static/js/public.js +128 -0
- package/static/js/ui.js +183 -6
- package/static/licenses.html +371 -770
- package/translations/messages.pot +66 -66
- package/views/account/passkeys.hbs +141 -0
- package/views/account/password.hbs +11 -0
- package/views/account/security.hbs +318 -326
- package/views/accounts/account.hbs +90 -115
- package/views/accounts/register/imap-server.hbs +18 -12
- package/views/config/ai.hbs +2 -0
- package/views/config/branding.hbs +2 -0
- package/views/config/document-store/index.hbs +6 -6
- package/views/config/email-processing.hbs +2 -0
- package/views/config/imap-proxy.hbs +2 -0
- package/views/config/license.hbs +4 -1
- package/views/config/logging.hbs +3 -1
- package/views/config/mcp.hbs +2 -0
- package/views/config/network.hbs +2 -0
- package/views/config/oauth/app.hbs +3 -3
- package/views/config/oauth/edit.hbs +1 -1
- package/views/config/oauth/new.hbs +1 -1
- package/views/config/security.hbs +2 -0
- package/views/config/service.hbs +2 -0
- package/views/config/smtp.hbs +2 -0
- package/views/config/webhooks.hbs +9 -6
- package/views/error.hbs +6 -0
- package/views/layout/app.hbs +6 -3
- 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/partials/filter_editor_js.hbs +1 -1
- package/views/partials/gateway_js.hbs +7 -6
- package/views/partials/oauth_form.hbs +5 -5
- package/views/partials/ui/btn.hbs +8 -2
- package/views/partials/ui/confirm-modal.hbs +2 -3
- package/views/partials/ui/empty-state.hbs +25 -0
- 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 +5 -5
- package/views/unsubscribe.hbs +6 -0
- package/workers/api.js +193 -81
- package/workers/imap.js +32 -3
- package/workers/smtp.js +7 -0
- package/workers/submit.js +25 -1
- package/workers/webhooks.js +13 -17
- package/lib/reconnection-manager.js +0 -106
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { metricsMeta } = require('../base-client');
|
|
3
|
+
const { metricsMeta, markRejectedAccessToken, renewRejectedAccessToken, isTransientNetworkError } = require('../base-client');
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
OUTLOOK_MAX_BATCH_SIZE,
|
|
7
|
-
OUTLOOK_MAX_RETRY_ATTEMPTS,
|
|
8
|
-
OUTLOOK_RETRY_BASE_DELAY,
|
|
9
|
-
OUTLOOK_RETRY_MAX_DELAY,
|
|
10
|
-
TRANSIENT_NETWORK_CODES
|
|
11
|
-
} = require('../../consts');
|
|
5
|
+
const { OUTLOOK_MAX_BATCH_SIZE, OUTLOOK_MAX_RETRY_ATTEMPTS, OUTLOOK_RETRY_BASE_DELAY, OUTLOOK_RETRY_MAX_DELAY } = require('../../consts');
|
|
12
6
|
|
|
13
7
|
// Maximum number of operations in a single batch request to Microsoft Graph API
|
|
14
8
|
const MAX_BATCH_SIZE = OUTLOOK_MAX_BATCH_SIZE;
|
|
@@ -58,103 +52,125 @@ function createGraphError(graphError, graphErrorCode) {
|
|
|
58
52
|
* @returns {Promise<*>} API response
|
|
59
53
|
*/
|
|
60
54
|
async function request(context, url, method, payload, options = {}) {
|
|
61
|
-
let
|
|
55
|
+
let tokenRenewed = false;
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
context.logger.warn({ msg: 'Failed to load access token', account: context.account, err });
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
if (!context.oAuth2Client) {
|
|
72
|
-
await context.getClient();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
options.headers = options.headers || {};
|
|
57
|
+
// Loops only for the single repeat after a rejected cached token
|
|
58
|
+
for (;;) {
|
|
59
|
+
let tokenData;
|
|
76
60
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// If caller already set a Prefer header, merge it
|
|
83
|
-
if (options.headers.Prefer) {
|
|
84
|
-
preferValues.push(options.headers.Prefer);
|
|
61
|
+
try {
|
|
62
|
+
tokenData = await context.getTokenData();
|
|
63
|
+
} catch (err) {
|
|
64
|
+
context.logger.warn({ msg: 'Failed to load access token', account: context.account, err });
|
|
65
|
+
throw err;
|
|
85
66
|
}
|
|
86
67
|
|
|
87
|
-
|
|
68
|
+
try {
|
|
69
|
+
if (!context.oAuth2Client) {
|
|
70
|
+
await context.getClient();
|
|
71
|
+
}
|
|
88
72
|
|
|
89
|
-
|
|
90
|
-
let apiUrl = /^https:/.test(url) ? url : new URL(`/v1.0${url}`, context.oAuth2Client.apiBase).href;
|
|
73
|
+
options.headers = options.headers || {};
|
|
91
74
|
|
|
92
|
-
|
|
75
|
+
// Build Prefer header with multiple preferences
|
|
76
|
+
// Request immutable IDs that don't change when messages are moved between folders
|
|
77
|
+
// https://learn.microsoft.com/en-us/graph/outlook-immutable-id
|
|
78
|
+
// The merge is idempotent: requestWithRetry() and the repeat below reuse the options
|
|
79
|
+
let preferValues = (options.headers.Prefer || '')
|
|
80
|
+
.split(',')
|
|
81
|
+
.map(value => value.trim())
|
|
82
|
+
.filter(value => value && value !== 'IdType="ImmutableId"');
|
|
83
|
+
preferValues.unshift('IdType="ImmutableId"');
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
metricsMeta({ account: context.account }, context.logger, 'oauth2ApiRequest', 'inc', {
|
|
96
|
-
status: 'success',
|
|
97
|
-
provider: context.oAuth2Client?.provider || 'outlook',
|
|
98
|
-
statusCode: '200'
|
|
99
|
-
});
|
|
100
|
-
} catch (err) {
|
|
101
|
-
// Track failed API request
|
|
102
|
-
const statusCode = String(err.oauthRequest?.status || 0);
|
|
103
|
-
metricsMeta({ account: context.account }, context.logger, 'oauth2ApiRequest', 'inc', {
|
|
104
|
-
status: 'failure',
|
|
105
|
-
provider: context.oAuth2Client?.provider || 'outlook',
|
|
106
|
-
statusCode
|
|
107
|
-
});
|
|
85
|
+
options.headers.Prefer = preferValues.join(', ');
|
|
108
86
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const graphError = createGraphError(err.oauthRequest?.response?.error, graphErrorCode);
|
|
87
|
+
// Construct full API URL if not already absolute
|
|
88
|
+
let apiUrl = /^https:/.test(url) ? url : new URL(`/v1.0${url}`, context.oAuth2Client.apiBase).href;
|
|
112
89
|
|
|
113
|
-
|
|
114
|
-
// Carry the raw Graph exchange over to the mapped error. Callers in outlook-client.js
|
|
115
|
-
// build their own responses by switching on `err.oauthRequest.response.error.code` and
|
|
116
|
-
// `err.oauthRequest.status`, so dropping it here silently disables every one of those
|
|
117
|
-
// branches and turns a mapped 404 into a generic 400 with an undefined code.
|
|
118
|
-
graphError.oauthRequest = err.oauthRequest;
|
|
90
|
+
let result = await context.oAuth2Client.request(tokenData.accessToken, apiUrl, method, payload, options);
|
|
119
91
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
92
|
+
// Track successful API request
|
|
93
|
+
metricsMeta({ account: context.account }, context.logger, 'oauth2ApiRequest', 'inc', {
|
|
94
|
+
status: 'success',
|
|
95
|
+
provider: context.oAuth2Client?.provider || 'outlook',
|
|
96
|
+
statusCode: '200'
|
|
125
97
|
});
|
|
126
|
-
throw graphError;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Handle HTTP status codes
|
|
130
|
-
const status = err.oauthRequest?.status;
|
|
131
|
-
const isClientError = status >= 400 && status < 500;
|
|
132
98
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// Rate limiting
|
|
142
|
-
context.logger.warn({ msg: 'API request was throttled', account: context.account, err });
|
|
143
|
-
throw err;
|
|
99
|
+
return result;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
// A rejected cached token is renewed and the request repeated once, see
|
|
102
|
+
// renewRejectedAccessToken()
|
|
103
|
+
if (await renewRejectedAccessToken(context, err, tokenData, tokenRenewed)) {
|
|
104
|
+
tokenRenewed = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
144
107
|
|
|
145
|
-
|
|
146
|
-
// Log client errors (4xx) at debug level - these are expected operational errors
|
|
147
|
-
// Log server errors (5xx) and other failures at error level
|
|
148
|
-
if (isClientError) {
|
|
149
|
-
context.logger.debug({ msg: 'API request failed with client error', account: context.account, err });
|
|
150
|
-
} else {
|
|
151
|
-
context.logger.error({ msg: 'Failed to run API request', account: context.account, err });
|
|
152
|
-
}
|
|
153
|
-
throw err;
|
|
108
|
+
throw handleRequestError(context, err);
|
|
154
109
|
}
|
|
155
110
|
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Records and maps a failed Graph API request. Always returns an error to throw
|
|
115
|
+
* @param {Object} context - The client context (OutlookClient instance)
|
|
116
|
+
* @param {Error} err - The error raised by the OAuth2 request layer
|
|
117
|
+
* @returns {Error} The error to throw
|
|
118
|
+
*/
|
|
119
|
+
function handleRequestError(context, err) {
|
|
120
|
+
// Track failed API request
|
|
121
|
+
const statusCode = String(err.oauthRequest?.status || 0);
|
|
122
|
+
metricsMeta({ account: context.account }, context.logger, 'oauth2ApiRequest', 'inc', {
|
|
123
|
+
status: 'failure',
|
|
124
|
+
provider: context.oAuth2Client?.provider || 'outlook',
|
|
125
|
+
statusCode
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Handle specific Graph API error codes using standardized mapping
|
|
129
|
+
const graphErrorCode = err.oauthRequest?.response?.error?.code;
|
|
130
|
+
const graphError = createGraphError(err.oauthRequest?.response?.error, graphErrorCode);
|
|
131
|
+
|
|
132
|
+
if (graphError) {
|
|
133
|
+
// Carry the raw Graph exchange over to the mapped error. Callers in outlook-client.js
|
|
134
|
+
// build their own responses by switching on `err.oauthRequest.response.error.code` and
|
|
135
|
+
// `err.oauthRequest.status`, so dropping it here silently disables every one of those
|
|
136
|
+
// branches and turns a mapped 404 into a generic 400 with an undefined code.
|
|
137
|
+
graphError.oauthRequest = err.oauthRequest;
|
|
138
|
+
|
|
139
|
+
context.logger.debug({
|
|
140
|
+
msg: 'Graph API error mapped to internal code',
|
|
141
|
+
account: context.account,
|
|
142
|
+
graphErrorCode,
|
|
143
|
+
internalCode: graphError.code
|
|
144
|
+
});
|
|
145
|
+
return graphError;
|
|
146
|
+
}
|
|
156
147
|
|
|
157
|
-
|
|
148
|
+
// Handle HTTP status codes
|
|
149
|
+
const status = err.oauthRequest?.status;
|
|
150
|
+
const isClientError = status >= 400 && status < 500;
|
|
151
|
+
|
|
152
|
+
switch (status) {
|
|
153
|
+
case 401:
|
|
154
|
+
// NOTE: never include `accessToken` here - this logger persists to the per-account
|
|
155
|
+
// log store (exposed via the account logs API/UI) and to Sentry (security review M3).
|
|
156
|
+
context.logger.warn({ msg: 'Failed to authenticate API request', account: context.account, err });
|
|
157
|
+
return markRejectedAccessToken(err);
|
|
158
|
+
|
|
159
|
+
case 429:
|
|
160
|
+
// Rate limiting
|
|
161
|
+
context.logger.warn({ msg: 'API request was throttled', account: context.account, err });
|
|
162
|
+
return err;
|
|
163
|
+
|
|
164
|
+
default:
|
|
165
|
+
// Log client errors (4xx) at debug level - these are expected operational errors
|
|
166
|
+
// Log server errors (5xx) and other failures at error level
|
|
167
|
+
if (isClientError) {
|
|
168
|
+
context.logger.debug({ msg: 'API request failed with client error', account: context.account, err });
|
|
169
|
+
} else {
|
|
170
|
+
context.logger.error({ msg: 'Failed to run API request', account: context.account, err });
|
|
171
|
+
}
|
|
172
|
+
return err;
|
|
173
|
+
}
|
|
158
174
|
}
|
|
159
175
|
|
|
160
176
|
/**
|
|
@@ -178,7 +194,7 @@ async function requestWithRetry(context, url, method, payload, options = {}) {
|
|
|
178
194
|
return await request(context, url, method, payload, options);
|
|
179
195
|
} catch (err) {
|
|
180
196
|
// Retry on transient network errors
|
|
181
|
-
if (
|
|
197
|
+
if (isTransientNetworkError(err) && attempt < maxRetries) {
|
|
182
198
|
lastError = err;
|
|
183
199
|
const delay = Math.min(OUTLOOK_RETRY_BASE_DELAY * Math.pow(2, attempt), OUTLOOK_RETRY_MAX_DELAY);
|
|
184
200
|
|