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,266 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// How a Microsoft Graph message is asked for and read back, shared by the single fetch
|
|
4
|
+
// (OutlookClient.getMessage()) and the batched one the export uses (getMessages()). Both carried
|
|
5
|
+
// their own copy of the field list and the header parsing.
|
|
6
|
+
|
|
7
|
+
const { pushHeaderValue } = require('../../utils/header-map');
|
|
8
|
+
|
|
9
|
+
// Every field a formatted message is built from. internetMessageHeaders is not included by
|
|
10
|
+
// default, so the full list has to be named
|
|
11
|
+
const GRAPH_MESSAGE_SELECT_FULL = [
|
|
12
|
+
'id',
|
|
13
|
+
'conversationId',
|
|
14
|
+
'receivedDateTime',
|
|
15
|
+
'isRead',
|
|
16
|
+
'isDraft',
|
|
17
|
+
'flag',
|
|
18
|
+
'body',
|
|
19
|
+
'subject',
|
|
20
|
+
'from',
|
|
21
|
+
'replyTo',
|
|
22
|
+
'sender',
|
|
23
|
+
'toRecipients',
|
|
24
|
+
'ccRecipients',
|
|
25
|
+
'bccRecipients',
|
|
26
|
+
'internetMessageId',
|
|
27
|
+
'bodyPreview',
|
|
28
|
+
'internetMessageHeaders',
|
|
29
|
+
'parentFolderId',
|
|
30
|
+
'categories'
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// The same list as a $select value
|
|
34
|
+
const GRAPH_MESSAGE_SELECT = GRAPH_MESSAGE_SELECT_FULL.join(',');
|
|
35
|
+
|
|
36
|
+
// The attachment list of a message, without the content
|
|
37
|
+
const GRAPH_ATTACHMENT_EXPAND = 'attachments($select=id,name,contentType,size,isInline,microsoft.graph.fileAttachment/contentId)';
|
|
38
|
+
|
|
39
|
+
// The fields of a listing entry, by detail level: the ids and the date for minimalFields, the
|
|
40
|
+
// flags and the sender for metadataOnly, and everything a listed message shows otherwise
|
|
41
|
+
const GRAPH_LIST_SELECT_MINIMAL = ['id', 'conversationId', 'receivedDateTime'];
|
|
42
|
+
const GRAPH_LIST_SELECT_METADATA = [
|
|
43
|
+
'id',
|
|
44
|
+
'conversationId',
|
|
45
|
+
'receivedDateTime',
|
|
46
|
+
'isRead',
|
|
47
|
+
'isDraft',
|
|
48
|
+
'flag',
|
|
49
|
+
'body',
|
|
50
|
+
'subject',
|
|
51
|
+
'from',
|
|
52
|
+
'replyTo',
|
|
53
|
+
'sender',
|
|
54
|
+
'internetMessageId'
|
|
55
|
+
];
|
|
56
|
+
const GRAPH_LIST_SELECT_FULL = [
|
|
57
|
+
'id',
|
|
58
|
+
'conversationId',
|
|
59
|
+
'receivedDateTime',
|
|
60
|
+
'isRead',
|
|
61
|
+
'isDraft',
|
|
62
|
+
'flag',
|
|
63
|
+
'body',
|
|
64
|
+
'subject',
|
|
65
|
+
'from',
|
|
66
|
+
'replyTo',
|
|
67
|
+
'sender',
|
|
68
|
+
'toRecipients',
|
|
69
|
+
'ccRecipients',
|
|
70
|
+
'bccRecipients',
|
|
71
|
+
'internetMessageId',
|
|
72
|
+
'bodyPreview',
|
|
73
|
+
'categories'
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The $select and $expand values of a message listing. Only the full set expands the attachment
|
|
78
|
+
* list. A listing across every folder also selects parentFolderId, which is how each message
|
|
79
|
+
* finds its path
|
|
80
|
+
* @param {Object} options - Listing options
|
|
81
|
+
* @param {boolean} [options.minimalFields] - Ids and date only
|
|
82
|
+
* @param {boolean} [options.metadataOnly] - No recipients, no attachments
|
|
83
|
+
* @param {boolean} crossFolder - Whether the listing spans every folder
|
|
84
|
+
* @returns {{$select: string, $expand: (string|undefined)}}
|
|
85
|
+
*/
|
|
86
|
+
function buildListSelect(options, crossFolder) {
|
|
87
|
+
let selectFields;
|
|
88
|
+
let expandFields;
|
|
89
|
+
|
|
90
|
+
if (options.minimalFields) {
|
|
91
|
+
selectFields = GRAPH_LIST_SELECT_MINIMAL.slice();
|
|
92
|
+
} else if (options.metadataOnly) {
|
|
93
|
+
selectFields = GRAPH_LIST_SELECT_METADATA.slice();
|
|
94
|
+
} else {
|
|
95
|
+
selectFields = GRAPH_LIST_SELECT_FULL.slice();
|
|
96
|
+
expandFields = GRAPH_ATTACHMENT_EXPAND;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (crossFolder) {
|
|
100
|
+
selectFields.push('parentFolderId');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return { $select: selectFields.join(','), $expand: expandFields };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Whether Graph refused a listing as too complex ("InefficientFilter"), which a categories/any()
|
|
108
|
+
* filter combined with $orderBy can be
|
|
109
|
+
* @param {Error} err - The failed request
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
function isInefficientFilterError(err) {
|
|
113
|
+
let graphCode = err?.oauthRequest?.response?.error?.code || '';
|
|
114
|
+
let graphMessage = err?.oauthRequest?.response?.error?.message || '';
|
|
115
|
+
return /inefficientfilter/i.test(graphCode) || /restriction or sort order is too complex/i.test(graphMessage);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// A batch request that failed with one of these is sent again
|
|
119
|
+
const BATCH_MAX_RETRIES = 3;
|
|
120
|
+
const BATCH_RETRY_BASE_DELAY = 5000;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The Prefer header value that asks Graph for a body format. For '*' or nothing Graph returns its default
|
|
124
|
+
* @param {string} [textType] - plain, html or *
|
|
125
|
+
* @returns {string} Empty when no preference is expressed
|
|
126
|
+
*/
|
|
127
|
+
function bodyPreferHeader(textType) {
|
|
128
|
+
if (textType === 'plain') {
|
|
129
|
+
return 'outlook.body-content-type="text"';
|
|
130
|
+
}
|
|
131
|
+
if (textType === 'html') {
|
|
132
|
+
return 'outlook.body-content-type="html"';
|
|
133
|
+
}
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Turns internetMessageHeaders into a `headers` map of lowercase names to value lists, and
|
|
139
|
+
* sets `inReplyTo` from the In-Reply-To header. Nothing is set when Graph sent no headers
|
|
140
|
+
* @param {Object} messageData - Graph message, updated in place
|
|
141
|
+
*/
|
|
142
|
+
function parseGraphHeaders(messageData) {
|
|
143
|
+
if (!messageData.internetMessageHeaders) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let headers = {};
|
|
148
|
+
for (let header of messageData.internetMessageHeaders) {
|
|
149
|
+
let { name, value } = header;
|
|
150
|
+
name = (name || '').toString().trim().toLowerCase();
|
|
151
|
+
value = (value || '').toString().trim();
|
|
152
|
+
if (!pushHeaderValue(headers, name, value)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (name === 'in-reply-to') {
|
|
156
|
+
messageData.inReplyTo = value;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
messageData.headers = headers;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The error a failed single message fetch is reported with: 404 is an unknown message, 400
|
|
164
|
+
* carries what Graph said
|
|
165
|
+
* @param {Error} err - Error from the Graph request
|
|
166
|
+
* @returns {Error|null} The error to throw, or null when the failure is to be thrown as is
|
|
167
|
+
*/
|
|
168
|
+
function mapGetMessageError(err) {
|
|
169
|
+
switch (err.oauthRequest?.status) {
|
|
170
|
+
case 404: {
|
|
171
|
+
let error = new Error('Unknown message');
|
|
172
|
+
error.info = {
|
|
173
|
+
response: `Message does not exist`
|
|
174
|
+
};
|
|
175
|
+
error.code = 'NotFound';
|
|
176
|
+
error.statusCode = 404;
|
|
177
|
+
return error;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
case 400: {
|
|
181
|
+
let error = new Error('Invalid request');
|
|
182
|
+
error.info = {
|
|
183
|
+
response: err.oauthRequest?.response?.error?.message || `Invalid request`
|
|
184
|
+
};
|
|
185
|
+
error.code = err.oauthRequest?.response?.error?.code || 'InvalidRequest';
|
|
186
|
+
error.statusCode = 400;
|
|
187
|
+
return error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The requests of one /$batch call, one GET per message
|
|
195
|
+
* @param {string[]} emailIds - Message ids of the batch
|
|
196
|
+
* @param {string} oauth2UserPath - Graph user path ("me" or "users/<id>")
|
|
197
|
+
* @param {string} preferHeader - Prefer header value, empty for none
|
|
198
|
+
* @param {Function} nextRequestId - Returns the next request id, unique across the batches of one call
|
|
199
|
+
* @returns {{requests: Object[], messageMap: Map<string, string>}} The requests, and the message id of each request id
|
|
200
|
+
*/
|
|
201
|
+
function buildMessageBatchRequests(emailIds, oauth2UserPath, preferHeader, nextRequestId) {
|
|
202
|
+
const messageMap = new Map();
|
|
203
|
+
|
|
204
|
+
const requests = emailIds.map(emailId => {
|
|
205
|
+
const reqId = nextRequestId();
|
|
206
|
+
messageMap.set(reqId, emailId);
|
|
207
|
+
|
|
208
|
+
const request = {
|
|
209
|
+
id: reqId,
|
|
210
|
+
method: 'GET',
|
|
211
|
+
url: `/${oauth2UserPath}/messages/${emailId}?$select=${GRAPH_MESSAGE_SELECT}&$expand=${GRAPH_ATTACHMENT_EXPAND}`
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// Add Prefer header for body content type if specified
|
|
215
|
+
if (preferHeader) {
|
|
216
|
+
request.headers = { Prefer: preferHeader };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return request;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return { requests, messageMap };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Whether a failed batch call is worth sending again: throttled (429) or a server error (5xx)
|
|
227
|
+
* @param {Error} err - Error from the Graph request
|
|
228
|
+
* @returns {boolean}
|
|
229
|
+
*/
|
|
230
|
+
function isRetryableBatchError(err) {
|
|
231
|
+
return err.oauthRequest?.status === 429 || (err.oauthRequest?.status >= 500 && err.oauthRequest?.status < 600);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Reports every request of a batch that got no response, after the ones that did
|
|
236
|
+
* @param {Map<string, string>} messageMap - Message id of each request id
|
|
237
|
+
* @param {Set<string>} respondedIds - Request ids a response was received for
|
|
238
|
+
* @param {Object[]} results - Results, appended to
|
|
239
|
+
*/
|
|
240
|
+
function reconcileMissingBatchResponses(messageMap, respondedIds, results) {
|
|
241
|
+
for (const [reqId, emailId] of messageMap) {
|
|
242
|
+
if (!respondedIds.has(reqId)) {
|
|
243
|
+
results.push({
|
|
244
|
+
messageId: emailId,
|
|
245
|
+
data: null,
|
|
246
|
+
error: { message: 'No response received from batch API', code: 'EMISSING_RESPONSE' }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = {
|
|
253
|
+
GRAPH_MESSAGE_SELECT_FULL,
|
|
254
|
+
GRAPH_MESSAGE_SELECT,
|
|
255
|
+
GRAPH_ATTACHMENT_EXPAND,
|
|
256
|
+
BATCH_MAX_RETRIES,
|
|
257
|
+
BATCH_RETRY_BASE_DELAY,
|
|
258
|
+
bodyPreferHeader,
|
|
259
|
+
buildListSelect,
|
|
260
|
+
isInefficientFilterError,
|
|
261
|
+
parseGraphHeaders,
|
|
262
|
+
mapGetMessageError,
|
|
263
|
+
buildMessageBatchRequests,
|
|
264
|
+
isRetryableBatchError,
|
|
265
|
+
reconcileMissingBatchResponses
|
|
266
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// What a stored MS Graph change subscription needs, by how long it has left. Kept pure so
|
|
4
|
+
// test/outlook-subscription-expiry-test.js can pin the boundaries without a client.
|
|
5
|
+
|
|
6
|
+
const { OUTLOOK_CLOCK_SKEW_BUFFER, OUTLOOK_EXPIRATION_RENEW_TIME } = require('../../consts');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Classifies a stored subscription by its expiry.
|
|
10
|
+
*
|
|
11
|
+
* @param {Date|null} expirationDate - the parsed expiry, null when absent or unparseable
|
|
12
|
+
* @param {number} now - current time in ms
|
|
13
|
+
* @returns {'expired'|'renew'|'valid'} `expired` once inside the clock-skew buffer (Graph may
|
|
14
|
+
* already consider it gone), `renew` inside the renewal window, `valid` otherwise. An expiry
|
|
15
|
+
* that could not be parsed counts as valid: nothing says it needs anything.
|
|
16
|
+
*/
|
|
17
|
+
function classifyExistingSubscription(expirationDate, now) {
|
|
18
|
+
if (!expirationDate) {
|
|
19
|
+
return 'valid';
|
|
20
|
+
}
|
|
21
|
+
if (expirationDate.getTime() < now + OUTLOOK_CLOCK_SKEW_BUFFER) {
|
|
22
|
+
return 'expired';
|
|
23
|
+
}
|
|
24
|
+
if (expirationDate.getTime() < now + OUTLOOK_EXPIRATION_RENEW_TIME) {
|
|
25
|
+
return 'renew';
|
|
26
|
+
}
|
|
27
|
+
return 'valid';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { classifyExistingSubscription };
|