emailengine-app 2.74.1 → 2.74.2
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/CHANGELOG.md +16 -0
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +23 -45
- package/lib/api-routes/changes-routes.js +51 -0
- package/lib/api-routes/index.js +160 -0
- package/lib/consts.js +15 -0
- package/lib/email-client/gmail/send-request.js +69 -0
- package/lib/email-client/gmail-client.js +4 -41
- package/lib/email-client/imap/detach-client.js +27 -0
- package/lib/email-client/imap/listing-diff.js +165 -0
- package/lib/email-client/imap/mailbox.js +32 -13
- package/lib/email-client/imap/subconnection.js +2 -4
- package/lib/email-client/imap/sync-operations.js +5 -3
- package/lib/email-client/imap-client.js +50 -84
- package/lib/email-client/outlook/send-request.js +48 -0
- package/lib/email-client/outlook-client.js +5 -14
- package/lib/export.js +97 -21
- package/lib/imapproxy/imap-core/lib/imap-connection.js +1 -1
- package/lib/logger.js +14 -6
- package/lib/rate-limit.js +33 -11
- package/lib/response-stream.js +138 -0
- package/lib/sentry.js +8 -0
- package/lib/smtp-message-processor.js +131 -0
- package/lib/tools.js +28 -5
- package/lib/ui-routes/internals-routes.js +32 -0
- package/package.json +6 -6
- package/sbom.json +1 -1
- package/static/licenses.html +22 -12
- package/translations/messages.pot +35 -35
- package/views/internals/index.hbs +8 -0
- package/workers/api.js +20 -216
- package/workers/export.js +29 -15
- package/workers/imap.js +47 -10
- package/workers/smtp.js +50 -91
package/workers/imap.js
CHANGED
|
@@ -49,6 +49,9 @@ const DEFAULT_STATES = {
|
|
|
49
49
|
disconnected: 0
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
// Minimum interval between reports about failed account log writes, see getAccountLogger()
|
|
53
|
+
const LOG_FAILURE_REPORT_INTERVAL = 60 * 1000;
|
|
54
|
+
|
|
52
55
|
const NO_ACTIVE_HANDLER_RESP_ERR = new Error('No active handler for requested account. Try again later.');
|
|
53
56
|
NO_ACTIVE_HANDLER_RESP_ERR.statusCode = 503;
|
|
54
57
|
NO_ACTIVE_HANDLER_RESP_ERR.code = 'WorkerNotAvailable';
|
|
@@ -116,11 +119,42 @@ class ConnectionHandler {
|
|
|
116
119
|
let logKey = this.getLogKey(account);
|
|
117
120
|
let logging = await settings.getLoggingInfo(account);
|
|
118
121
|
|
|
119
|
-
|
|
122
|
+
// log() runs once per protocol line, so a persistent write failure (Redis OOM, MISCONF,
|
|
123
|
+
// READONLY) would report itself on every single line. Report the first failure, then at
|
|
124
|
+
// most one summary per interval, otherwise a failing account log floods the main log.
|
|
125
|
+
let lastFailureReport = 0;
|
|
126
|
+
let suppressedFailures = 0;
|
|
127
|
+
let reportFailure = (msg, err) => {
|
|
128
|
+
let now = Date.now();
|
|
129
|
+
if (now - lastFailureReport < LOG_FAILURE_REPORT_INTERVAL) {
|
|
130
|
+
suppressedFailures++;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ioredis attaches the failed command to the error, and the arguments of these
|
|
135
|
+
// writes include the encoded log entry itself (protocol traces, and even raw
|
|
136
|
+
// credentials when EENGINE_LOG_RAW is set), so such errors are summarized instead
|
|
137
|
+
// of being handed to the log serializer, which copies all enumerable properties
|
|
138
|
+
let reported = err && (err.command || err.previousErrors) ? { name: err.name, code: err.code, message: err.message } : err;
|
|
139
|
+
|
|
140
|
+
let payload = { msg, account, err: reported };
|
|
141
|
+
if (suppressedFailures) {
|
|
142
|
+
payload.suppressed = suppressedFailures;
|
|
143
|
+
}
|
|
144
|
+
logger.error(payload);
|
|
145
|
+
|
|
146
|
+
lastFailureReport = now;
|
|
147
|
+
suppressedFailures = 0;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Members are referenced by name instead of through `this` as this object is passed
|
|
151
|
+
// around to client classes that might call log() detached from its receiver
|
|
152
|
+
let accountLogger = {
|
|
120
153
|
enabled: logging.enabled,
|
|
121
154
|
maxLogLines: logging.maxLogLines,
|
|
155
|
+
|
|
122
156
|
log(entry) {
|
|
123
|
-
if (!
|
|
157
|
+
if (!accountLogger.maxLogLines || !accountLogger.enabled) {
|
|
124
158
|
return;
|
|
125
159
|
}
|
|
126
160
|
|
|
@@ -134,19 +168,22 @@ class ConnectionHandler {
|
|
|
134
168
|
redis
|
|
135
169
|
.multi()
|
|
136
170
|
.rpush(logKey, logRow)
|
|
137
|
-
.ltrim(logKey, -
|
|
171
|
+
.ltrim(logKey, -accountLogger.maxLogLines, -1)
|
|
138
172
|
.exec()
|
|
139
|
-
.catch(err =>
|
|
173
|
+
.catch(err => reportFailure('Failed to update log entries', err));
|
|
140
174
|
} catch (err) {
|
|
141
|
-
|
|
175
|
+
reportFailure('Failed to encode log entry', err);
|
|
142
176
|
}
|
|
143
177
|
},
|
|
178
|
+
|
|
144
179
|
async reload() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
180
|
+
let updated = await settings.getLoggingInfo(account);
|
|
181
|
+
accountLogger.enabled = updated.enabled;
|
|
182
|
+
accountLogger.maxLogLines = updated.maxLogLines;
|
|
148
183
|
}
|
|
149
184
|
};
|
|
185
|
+
|
|
186
|
+
return accountLogger;
|
|
150
187
|
}
|
|
151
188
|
|
|
152
189
|
async assignConnection(account, runIndex, initOpts) {
|
|
@@ -264,7 +301,7 @@ class ConnectionHandler {
|
|
|
264
301
|
|
|
265
302
|
if (accountData.state) {
|
|
266
303
|
await redis.hSetExists(accountObject.connection.getAccountKey(), 'state', accountData.state);
|
|
267
|
-
await emitChangeEvent(
|
|
304
|
+
await emitChangeEvent(logger, account, 'state', accountData.state);
|
|
268
305
|
}
|
|
269
306
|
|
|
270
307
|
// do not wait before returning as it may take forever
|
|
@@ -299,7 +336,7 @@ class ConnectionHandler {
|
|
|
299
336
|
let state = 'connecting';
|
|
300
337
|
await redis.hSetExists(accountObject.connection.getAccountKey(), 'state', state);
|
|
301
338
|
accountObject.connection.state = state;
|
|
302
|
-
await emitChangeEvent(
|
|
339
|
+
await emitChangeEvent(logger, account, 'state', state);
|
|
303
340
|
await accountObject.connection.reconnect(true);
|
|
304
341
|
}
|
|
305
342
|
}
|
package/workers/smtp.js
CHANGED
|
@@ -17,8 +17,7 @@ const util = require('util');
|
|
|
17
17
|
const { redis } = require('../lib/db');
|
|
18
18
|
const { Account } = require('../lib/account');
|
|
19
19
|
const getSecret = require('../lib/get-secret');
|
|
20
|
-
const {
|
|
21
|
-
const { HeadersRewriter } = require('../lib/headers-rewriter');
|
|
20
|
+
const { collectMessage } = require('../lib/smtp-message-processor');
|
|
22
21
|
const settings = require('../lib/settings');
|
|
23
22
|
|
|
24
23
|
const { encrypt, decrypt } = require('../lib/encrypt');
|
|
@@ -113,31 +112,6 @@ for (let level of ['trace', 'debug', 'info', 'warn', 'error', 'fatal']) {
|
|
|
113
112
|
// so onAuth caches the Account for later processing steps.
|
|
114
113
|
const onAuth = createSmtpAuthHandler({ accountCache: ACCOUNT_CACHE, call });
|
|
115
114
|
|
|
116
|
-
function processMessage(stream, session, meta) {
|
|
117
|
-
meta = meta || {};
|
|
118
|
-
const splitter = new Splitter();
|
|
119
|
-
const joiner = new Joiner();
|
|
120
|
-
|
|
121
|
-
const headersRewriter = new HeadersRewriter(async headers => {
|
|
122
|
-
let requestedAccount = headers.getFirst('x-ee-account');
|
|
123
|
-
headers.remove('x-ee-account');
|
|
124
|
-
if (requestedAccount) {
|
|
125
|
-
meta.requestedAccount = requestedAccount;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let idempotencyKey = headers.getFirst('x-ee-idempotency-key');
|
|
129
|
-
headers.remove('x-ee-idempotency-key');
|
|
130
|
-
if (idempotencyKey) {
|
|
131
|
-
meta.idempotencyKey = idempotencyKey;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
stream.once('error', err => joiner.emit('error', err));
|
|
136
|
-
headersRewriter.once('error', err => joiner.emit('error', err));
|
|
137
|
-
|
|
138
|
-
return stream.pipe(splitter).pipe(headersRewriter).pipe(joiner);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
115
|
async function checkAccountData(session, messageMeta) {
|
|
142
116
|
let accountObject;
|
|
143
117
|
|
|
@@ -243,74 +217,59 @@ async function init() {
|
|
|
243
217
|
};
|
|
244
218
|
|
|
245
219
|
serverOptions.onData = (rawStream, session, callback) => {
|
|
246
|
-
let chunks = [];
|
|
247
|
-
let chunklen = 0;
|
|
248
|
-
|
|
249
220
|
let messageMeta = {};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
221
|
+
|
|
222
|
+
// Collecting the message lives in lib/smtp-message-processor.js so that the control
|
|
223
|
+
// header stripping, the stream error handling and the size verdict are unit testable -
|
|
224
|
+
// this worker can not be required from a test, it boots an SMTP server on load.
|
|
225
|
+
// collectMessage() rejects on a processing error instead of leaving it unhandled, which
|
|
226
|
+
// used to kill the entire worker thread rather than the one failing submission.
|
|
227
|
+
collectMessage(rawStream, messageMeta)
|
|
228
|
+
.then(async ({ message, sizeExceeded }) => {
|
|
229
|
+
if (sizeExceeded) {
|
|
230
|
+
let err = new Error('Message exceeds fixed maximum message size');
|
|
231
|
+
err.responseCode = 552;
|
|
232
|
+
throw err;
|
|
258
233
|
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
234
|
|
|
262
|
-
|
|
263
|
-
let err;
|
|
264
|
-
if (stream.sizeExceeded) {
|
|
265
|
-
err = new Error('Message exceeds fixed maximum message size');
|
|
266
|
-
err.responseCode = 552;
|
|
267
|
-
return callback(err);
|
|
268
|
-
}
|
|
235
|
+
let accountObject = await checkAccountData(session, messageMeta);
|
|
269
236
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
event: 'smtpSubmitFail'
|
|
307
|
-
});
|
|
308
|
-
logger.error({ msg: 'Failed to submit message', account: session.user, err });
|
|
309
|
-
callback(err);
|
|
310
|
-
});
|
|
311
|
-
})
|
|
312
|
-
.catch(err => callback(err));
|
|
313
|
-
});
|
|
237
|
+
let payload = {
|
|
238
|
+
envelope: {
|
|
239
|
+
from: session.envelope.mailFrom.address,
|
|
240
|
+
to: session.envelope.rcptTo.map(entry => entry.address)
|
|
241
|
+
},
|
|
242
|
+
raw: message
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
let res = await accountObject.queueMessage(payload, {
|
|
246
|
+
source: 'smtp',
|
|
247
|
+
idempotencyKey: messageMeta.idempotencyKey
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// queued for later
|
|
251
|
+
metrics(logger, 'events', 'inc', {
|
|
252
|
+
event: 'smtpSubmitQueued'
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
logger.info({
|
|
256
|
+
msg: 'Message queued',
|
|
257
|
+
account: session.user,
|
|
258
|
+
messageId: res.messageId,
|
|
259
|
+
sendAt: res.sendAt,
|
|
260
|
+
queueId: res.queueId,
|
|
261
|
+
idempotency: res.idempotency
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
callback(null, `Message queued for delivery as ${res.queueId} (${new Date(res.sendAt).toISOString()})`);
|
|
265
|
+
})
|
|
266
|
+
.catch(err => {
|
|
267
|
+
metrics(logger, 'events', 'inc', {
|
|
268
|
+
event: 'smtpSubmitFail'
|
|
269
|
+
});
|
|
270
|
+
logger.error({ msg: 'Failed to submit message', account: session.user, err });
|
|
271
|
+
callback(err);
|
|
272
|
+
});
|
|
314
273
|
};
|
|
315
274
|
|
|
316
275
|
let tls = await settings.get('smtpServerTLSEnabled');
|