emailengine-app 2.76.0 → 2.78.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/.github/workflows/release.yaml +24 -19
- package/.github/workflows/test.yml +80 -0
- package/.ncurc.js +14 -2
- package/.release-please-manifest.json +3 -0
- package/CHANGELOG.md +54 -0
- package/README.md +1 -1
- package/bin/emailengine.js +1 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +72 -5
- package/lib/account/expected-identity.js +88 -0
- package/lib/account.js +75 -26
- package/lib/address-strategies.js +18 -0
- package/lib/api-reference/code-samples.js +194 -0
- package/lib/api-reference/format.js +193 -0
- package/lib/api-reference/index.js +222 -0
- package/lib/api-reference/model.js +338 -0
- package/lib/api-reference/schema-tree.js +366 -0
- package/lib/api-routes/account-routes.js +136 -39
- package/lib/api-routes/behavior-notes.js +57 -0
- package/lib/api-routes/blocklist-routes.js +9 -9
- package/lib/api-routes/changes-routes.js +6 -4
- package/lib/api-routes/chat-routes.js +3 -3
- package/lib/api-routes/delivery-test-routes.js +24 -6
- package/lib/api-routes/export-routes.js +14 -12
- package/lib/api-routes/gateway-routes.js +11 -11
- package/lib/api-routes/license-routes.js +7 -7
- package/lib/api-routes/mailbox-routes.js +18 -9
- package/lib/api-routes/message-routes.js +55 -35
- package/lib/api-routes/oauth2-app-routes.js +22 -16
- package/lib/api-routes/outbox-routes.js +7 -7
- package/lib/api-routes/pubsub-routes.js +3 -3
- package/lib/api-routes/settings-routes.js +10 -9
- package/lib/api-routes/stats-routes.js +3 -3
- package/lib/api-routes/submit-routes.js +58 -8
- package/lib/api-routes/template-routes.js +13 -13
- package/lib/api-routes/token-routes.js +15 -10
- package/lib/api-routes/webhook-route-routes.js +5 -5
- package/lib/append-list.js +3 -14
- package/lib/arf-detect.js +23 -1
- package/lib/autodetect-imap-settings.js +40 -16
- package/lib/base32.js +30 -0
- package/lib/bounce-detect.js +182 -62
- package/lib/consts.js +7 -0
- package/lib/egress-filter.js +89 -8
- package/lib/email-client/base-client.js +72 -82
- package/lib/email-client/gmail-client.js +3 -3
- package/lib/email-client/imap/listing-diff.js +3 -3
- package/lib/email-client/imap/mailbox.js +5 -69
- package/lib/email-client/imap-client.js +3 -2
- package/lib/email-client/message-builder.js +13 -13
- package/lib/email-client/outlook-client.js +1 -1
- package/lib/enum-descriptions.js +130 -0
- package/lib/export.js +1 -1
- package/lib/gateway.js +1 -1
- package/lib/get-raw-email.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-connection.js +2 -2
- package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
- package/lib/imapproxy/imap-server.js +42 -28
- package/lib/imapproxy/upstream-client.js +38 -0
- package/lib/license-beacon.js +1 -1
- package/lib/llm-pre-process.js +1 -1
- package/lib/msgpack.js +62 -0
- package/lib/oauth/decode-jwt-payload.js +39 -0
- package/lib/oauth/outlook-identity.js +61 -0
- package/lib/oauth/retry-setup.js +38 -0
- package/lib/oauth2-apps.js +10 -4
- package/lib/openapi/build-document.js +318 -0
- package/lib/openapi/index.js +95 -0
- package/lib/openapi/joi-schema.js +523 -0
- package/lib/outbox.js +66 -3
- package/lib/pre-process.js +1 -1
- package/lib/read-env-value.js +37 -0
- package/lib/routes-ui.js +5 -1
- package/lib/schemas.js +88 -17
- package/lib/swagger-options.js +173 -0
- package/lib/templates.js +1 -1
- package/lib/tokens.js +70 -6
- package/lib/tools.js +117 -48
- package/lib/totp.js +67 -0
- package/lib/ui-routes/account-routes.js +91 -15
- package/lib/ui-routes/admin-config-routes.js +2 -7
- package/lib/ui-routes/admin-entities-routes.js +3 -0
- package/lib/ui-routes/auth-routes.js +6 -24
- package/lib/ui-routes/dashboard-routes.js +2 -26
- package/lib/ui-routes/reference-routes.js +198 -0
- package/lib/ui-routes/route-helpers.js +39 -0
- package/lib/utils/is-email.js +34 -0
- package/lib/utils/to-camel-case.js +17 -0
- package/lib/webhook-egress.js +37 -0
- package/lib/webhooks.js +1 -1
- package/package.json +27 -31
- package/prepare-bundle-deps.sh +28 -0
- package/release-please-config.json +11 -0
- package/sbom.json +1 -1
- package/server.js +11 -3
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +3 -0
- package/static/css/src/app.tailwind.css +113 -0
- package/static/js/app.js +69 -0
- package/static/js/ee-client.js +238 -8
- package/static/js/reference.js +1021 -0
- package/static/js/ui.js +61 -33
- package/static/licenses.html +658 -1560
- package/translations/README.md +64 -0
- package/translations/de.mo +0 -0
- package/translations/de.po +164 -120
- package/translations/en.po +200 -161
- package/translations/et.mo +0 -0
- package/translations/et.po +163 -120
- package/translations/fr.mo +0 -0
- package/translations/fr.po +163 -120
- package/translations/ja.mo +0 -0
- package/translations/ja.po +163 -120
- package/translations/messages.pot +84 -54
- package/translations/nl.mo +0 -0
- package/translations/nl.po +164 -120
- package/translations/pl.mo +0 -0
- package/translations/pl.po +163 -120
- package/views/account-identity-error.hbs +34 -0
- package/views/accounts/edit.hbs +1 -0
- package/views/accounts/register/imap.hbs +12 -2
- package/views/config/ai.hbs +1 -1
- package/views/config/document-store/chat.hbs +5 -5
- package/views/config/document-store/index.hbs +2 -2
- package/views/config/document-store/pre-processing/index.hbs +1 -1
- package/views/config/email-processing.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -1
- package/views/config/license.hbs +1 -1
- package/views/config/oauth/index.hbs +3 -3
- package/views/config/security.hbs +1 -1
- package/views/config/smtp.hbs +2 -2
- package/views/dashboard.hbs +1 -1
- package/views/layout/app.hbs +43 -8
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/oauth_form.hbs +4 -4
- package/views/partials/reference/anchor-link.hbs +20 -0
- package/views/partials/reference/disclosure.hbs +37 -0
- package/views/partials/reference/nav.hbs +120 -0
- package/views/partials/reference/operation.hbs +127 -0
- package/views/partials/reference/params.hbs +20 -0
- package/views/partials/reference/schema-node.hbs +99 -0
- package/views/partials/reference/schema.hbs +19 -0
- package/views/partials/reference/section-heading.hbs +16 -0
- package/views/partials/reference/token-alert.hbs +49 -0
- package/views/partials/reference/try-field.hbs +31 -0
- package/views/partials/reference/try-it.hbs +78 -0
- package/views/partials/side_menu.hbs +1 -1
- package/views/partials/ui/badge.hbs +4 -2
- package/views/partials/ui/page-header.hbs +1 -1
- package/views/partials/ui/search-input.hbs +31 -0
- package/views/partials/ui/setting-ref.hbs +1 -1
- package/views/partials/ui/stat-card.hbs +4 -2
- package/views/partials/ui/tab.hbs +6 -1
- package/views/partials/ui/tabs.hbs +2 -2
- package/views/reference/index.hbs +76 -0
- package/views/reference/redirect.hbs +49 -0
- package/views/reference/tag.hbs +28 -0
- package/views/reference/token.hbs +49 -0
- package/views/tokens/index.hbs +9 -1
- package/views/webhooks/index.hbs +3 -3
- package/workers/api.js +194 -302
- package/workers/imap.js +1 -1
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +2 -13
- package/views/swagger/index.hbs +0 -82
|
@@ -5,7 +5,7 @@ const crypto = require('crypto');
|
|
|
5
5
|
const logger = require('../logger');
|
|
6
6
|
const settings = require('../settings');
|
|
7
7
|
const { isDocumentStoreEnabled } = require('../document-store');
|
|
8
|
-
const msgpack = require('
|
|
8
|
+
const msgpack = require('../msgpack');
|
|
9
9
|
const { templates } = require('../templates');
|
|
10
10
|
const { Gateway } = require('../gateway');
|
|
11
11
|
const os = require('os');
|
|
@@ -17,11 +17,11 @@ const { addTrackers } = require('../add-trackers');
|
|
|
17
17
|
const { getRawEmail } = require('../get-raw-email');
|
|
18
18
|
const { getTemplate } = require('@postalsys/templates');
|
|
19
19
|
const { deepEqual } = require('assert');
|
|
20
|
-
const { arfDetect } = require('../arf-detect');
|
|
20
|
+
const { arfDetect, camelCaseComplaint } = require('../arf-detect');
|
|
21
21
|
const { createTransaction } = require('../redis-operations');
|
|
22
22
|
const simpleParser = require('mailparser').simpleParser;
|
|
23
23
|
const libmime = require('libmime');
|
|
24
|
-
const { bounceDetect } = require('../bounce-detect');
|
|
24
|
+
const { bounceDetect, applyDeliveryReport } = require('../bounce-detect');
|
|
25
25
|
const ical = require('ical.js');
|
|
26
26
|
const { llmPreProcess } = require('../llm-pre-process');
|
|
27
27
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
@@ -49,7 +49,9 @@ const {
|
|
|
49
49
|
readEnvValue,
|
|
50
50
|
emitChangeEvent,
|
|
51
51
|
filterEmptyObjectValues,
|
|
52
|
-
getDateBuckets
|
|
52
|
+
getDateBuckets,
|
|
53
|
+
resolveCredentials,
|
|
54
|
+
useAuthServerForOAuth2
|
|
53
55
|
} = require('../tools');
|
|
54
56
|
|
|
55
57
|
// Import application constants
|
|
@@ -79,6 +81,25 @@ const MAX_IMAP_AUTH_FAILURE_TIME = getDuration(readEnvValue('EENGINE_MAX_IMAP_AU
|
|
|
79
81
|
// Map to track pending idempotency operations to prevent duplicate processing
|
|
80
82
|
const pendingIdempotencyOperations = new Map();
|
|
81
83
|
|
|
84
|
+
// Failing to reach a remote endpoint is a connection problem, not a rejected credential. Both
|
|
85
|
+
// OAuth2 credential sources (EmailEngine's own token refresh and an external authentication server)
|
|
86
|
+
// use this to avoid reporting an unreachable host as an authentication error, which would webhook
|
|
87
|
+
// and park every account on the instance over a brief outage.
|
|
88
|
+
const TRANSIENT_CONNECT_CODES = new Set([
|
|
89
|
+
'ENOTFOUND',
|
|
90
|
+
'ETIMEDOUT',
|
|
91
|
+
'ECONNREFUSED',
|
|
92
|
+
'ECONNRESET',
|
|
93
|
+
'EAI_AGAIN',
|
|
94
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
95
|
+
'UND_ERR_SOCKET',
|
|
96
|
+
'UND_ERR_HEADERS_TIMEOUT'
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
function isTransientNetworkError(err) {
|
|
100
|
+
return !!err && TRANSIENT_CONNECT_CODES.has(err.code);
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
/**
|
|
83
104
|
* Check if an error is a transient error that should be retried
|
|
84
105
|
* @param {Error} err - The error to check
|
|
@@ -558,6 +579,50 @@ class BaseClient {
|
|
|
558
579
|
throw error;
|
|
559
580
|
}
|
|
560
581
|
|
|
582
|
+
// An external authentication server owns this account's tokens, so EmailEngine must ask for
|
|
583
|
+
// one instead of renewing from a stored refresh token (it has none). The app is still
|
|
584
|
+
// resolved above, because the caller needs it for the provider's host and port.
|
|
585
|
+
if (await useAuthServerForOAuth2(accountData.oauth2, ctx.logger, { account: accountObject.account, target })) {
|
|
586
|
+
try {
|
|
587
|
+
let authData = await resolveCredentials(accountObject.account, target);
|
|
588
|
+
// The auth server owns the credentials, but a shared mailbox is still addressed by
|
|
589
|
+
// the configured delegatedUser - same precedence as the stored-token path above.
|
|
590
|
+
return {
|
|
591
|
+
oauth2User: accountData.oauth2.auth.delegatedUser || authData.user,
|
|
592
|
+
accessToken: authData.accessToken,
|
|
593
|
+
oauth2App
|
|
594
|
+
};
|
|
595
|
+
} catch (err) {
|
|
596
|
+
// A transient failure to reach the auth server is a connection problem, not a
|
|
597
|
+
// rejected credential. Reporting it as an authentication error would webhook every
|
|
598
|
+
// account on the instance and park them in an error state over a brief blip.
|
|
599
|
+
if (isTransientNetworkError(err)) {
|
|
600
|
+
ctx.logger.error({
|
|
601
|
+
msg: 'Network error while resolving credentials from the authentication server',
|
|
602
|
+
account: accountObject.account,
|
|
603
|
+
target,
|
|
604
|
+
code: err.code,
|
|
605
|
+
err
|
|
606
|
+
});
|
|
607
|
+
throw err;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
err.authenticationFailed = true;
|
|
611
|
+
await ctx.notify(false, AUTH_ERROR_NOTIFY, {
|
|
612
|
+
response: err.message,
|
|
613
|
+
serverResponseCode: 'HTTPRequestError'
|
|
614
|
+
});
|
|
615
|
+
ctx.logger.error({
|
|
616
|
+
msg: 'Failed to resolve OAuth2 credentials from the authentication server',
|
|
617
|
+
account: accountObject.account,
|
|
618
|
+
target,
|
|
619
|
+
err
|
|
620
|
+
});
|
|
621
|
+
ctx.state = AUTH_ERROR_NOTIFY;
|
|
622
|
+
throw err;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
561
626
|
// Check if token needs refresh (with 30 second buffer)
|
|
562
627
|
if (!accountData.oauth2.accessToken || !accountData.oauth2.expires || accountData.oauth2.expires < new Date(now + 30 * 1000)) {
|
|
563
628
|
// renew access token
|
|
@@ -569,17 +634,7 @@ class BaseClient {
|
|
|
569
634
|
accessToken = accountData.oauth2.accessToken;
|
|
570
635
|
} catch (err) {
|
|
571
636
|
// Transient network errors are not authentication failures
|
|
572
|
-
|
|
573
|
-
err.code === 'ENOTFOUND' ||
|
|
574
|
-
err.code === 'ETIMEDOUT' ||
|
|
575
|
-
err.code === 'ECONNREFUSED' ||
|
|
576
|
-
err.code === 'ECONNRESET' ||
|
|
577
|
-
err.code === 'EAI_AGAIN' ||
|
|
578
|
-
err.code === 'UND_ERR_CONNECT_TIMEOUT' ||
|
|
579
|
-
err.code === 'UND_ERR_SOCKET' ||
|
|
580
|
-
err.code === 'UND_ERR_HEADERS_TIMEOUT';
|
|
581
|
-
|
|
582
|
-
if (isNetworkError) {
|
|
637
|
+
if (isTransientNetworkError(err)) {
|
|
583
638
|
ctx.logger.error({
|
|
584
639
|
msg: 'Network error during OAuth2 token refresh',
|
|
585
640
|
account: accountObject.account,
|
|
@@ -2403,17 +2458,7 @@ class BaseClient {
|
|
|
2403
2458
|
|
|
2404
2459
|
if (report && report.arf && report.arf['original-rcpt-to'] && report.arf['original-rcpt-to'].length) {
|
|
2405
2460
|
// can send report
|
|
2406
|
-
let complaint =
|
|
2407
|
-
|
|
2408
|
-
// Convert headers to camelCase
|
|
2409
|
-
for (let subKey of ['arf', 'headers']) {
|
|
2410
|
-
for (let key of Object.keys(report[subKey])) {
|
|
2411
|
-
if (!complaint[subKey]) {
|
|
2412
|
-
complaint[subKey] = {};
|
|
2413
|
-
}
|
|
2414
|
-
complaint[subKey][key.replace(/-(.)/g, (o, c) => c.toUpperCase())] = report[subKey][key];
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2461
|
+
let complaint = camelCaseComplaint(report);
|
|
2417
2462
|
|
|
2418
2463
|
complaintNotifyInfo = Object.assign({ complaintMessage: messageData.id }, complaint);
|
|
2419
2464
|
|
|
@@ -2443,62 +2488,7 @@ class BaseClient {
|
|
|
2443
2488
|
let parsed = await simpleParser(raw, { keepDeliveryStatus: true });
|
|
2444
2489
|
if (parsed) {
|
|
2445
2490
|
content = { parsed };
|
|
2446
|
-
|
|
2447
|
-
// Extract delivery status attachment
|
|
2448
|
-
let deliveryStatus = parsed.attachments.find(attachment => attachment.contentType === 'message/delivery-status');
|
|
2449
|
-
if (deliveryStatus) {
|
|
2450
|
-
let deliveryEntries = libmime.decodeHeaders((deliveryStatus.content || '').toString().trim());
|
|
2451
|
-
let structured = {};
|
|
2452
|
-
|
|
2453
|
-
// Parse delivery status fields
|
|
2454
|
-
for (let key of Object.keys(deliveryEntries)) {
|
|
2455
|
-
if (!key) {
|
|
2456
|
-
continue;
|
|
2457
|
-
}
|
|
2458
|
-
let displayKey = key.replace(/-(.)/g, (m, c) => c.toUpperCase());
|
|
2459
|
-
let value = deliveryEntries[key].at(-1);
|
|
2460
|
-
if (typeof value === 'string') {
|
|
2461
|
-
// Parse structured fields
|
|
2462
|
-
let m = value.match(/^([^\s;]+);/);
|
|
2463
|
-
if (m) {
|
|
2464
|
-
value = {
|
|
2465
|
-
label: m[1],
|
|
2466
|
-
value: value.substring(m[0].length).trim()
|
|
2467
|
-
};
|
|
2468
|
-
} else {
|
|
2469
|
-
switch (key) {
|
|
2470
|
-
case 'arrival-date': {
|
|
2471
|
-
value.trim();
|
|
2472
|
-
let date = new Date(value);
|
|
2473
|
-
if (date.toString() !== 'Invalid Date') {
|
|
2474
|
-
value = date.toISOString();
|
|
2475
|
-
}
|
|
2476
|
-
structured[displayKey] = value;
|
|
2477
|
-
break;
|
|
2478
|
-
}
|
|
2479
|
-
default:
|
|
2480
|
-
structured[displayKey] = value.trim();
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
} else {
|
|
2484
|
-
// ???
|
|
2485
|
-
structured[displayKey] = value;
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
// Check if this is a delivery or delay notification
|
|
2490
|
-
if (/^delivered|^delayed/i.test(structured.action)) {
|
|
2491
|
-
this.logger.debug({
|
|
2492
|
-
msg: 'Detected delivery report',
|
|
2493
|
-
id: messageData.id,
|
|
2494
|
-
uid: messageData.uid,
|
|
2495
|
-
messageId: messageData.messageId,
|
|
2496
|
-
report: structured
|
|
2497
|
-
});
|
|
2498
|
-
|
|
2499
|
-
messageData.deliveryReport = structured;
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2491
|
+
applyDeliveryReport(parsed, messageData, this.logger);
|
|
2502
2492
|
}
|
|
2503
2493
|
} catch (err) {
|
|
2504
2494
|
this.logger.error({
|
|
@@ -4,13 +4,13 @@ const { Account } = require('../account');
|
|
|
4
4
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
5
5
|
const { checkAccountScopes, isSendOnlyByScopes } = require('../oauth/scope-checker');
|
|
6
6
|
const getSecret = require('../get-secret');
|
|
7
|
-
const msgpack = require('
|
|
7
|
+
const msgpack = require('../msgpack');
|
|
8
8
|
const addressparser = require('nodemailer/lib/addressparser');
|
|
9
9
|
const libmime = require('libmime');
|
|
10
10
|
const he = require('he');
|
|
11
11
|
const { BaseClient, metricsMeta } = require('./base-client');
|
|
12
12
|
const { messageWebSafeHtml } = require('../web-safe-html');
|
|
13
|
-
const { emitChangeEvent } = require('../tools');
|
|
13
|
+
const { emitChangeEvent, toCamelCase } = require('../tools');
|
|
14
14
|
const { Gateway } = require('../gateway');
|
|
15
15
|
|
|
16
16
|
const {
|
|
@@ -2292,7 +2292,7 @@ class GmailClient extends BaseClient {
|
|
|
2292
2292
|
for (let header of messageData.payload.headers.filter(header => header.name.toLowerCase() === key)) {
|
|
2293
2293
|
let parsed = addressparser(header.value, { flatten: true });
|
|
2294
2294
|
|
|
2295
|
-
let envelopekey = key.toLowerCase()
|
|
2295
|
+
let envelopekey = toCamelCase(key.toLowerCase());
|
|
2296
2296
|
|
|
2297
2297
|
envelope[envelopekey] = [].concat(envelope[envelopekey] || []).concat(parsed || []);
|
|
2298
2298
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// Folder paths are compared through normalizePath(), which case-folds INBOX so a server that
|
|
13
13
|
// reports "Inbox" one pass and "INBOX" the next does not look like a delete plus an add.
|
|
14
14
|
|
|
15
|
-
const msgpack = require('
|
|
15
|
+
const msgpack = require('../../msgpack');
|
|
16
16
|
const { normalizePath } = require('../../tools');
|
|
17
17
|
const { STORED_MAILBOX_FIELDS } = require('../../consts');
|
|
18
18
|
|
|
@@ -26,8 +26,8 @@ const COMPARED_MAILBOX_FIELDS = STORED_MAILBOX_FIELDS.filter(field => field !==
|
|
|
26
26
|
* value is unusable. Callers drop a false entry rather than failing: a single corrupt value must
|
|
27
27
|
* not take down the sync (or the mailboxes API response) for every other folder in the account.
|
|
28
28
|
*
|
|
29
|
-
* The shape check is not redundant with the try/catch.
|
|
30
|
-
* parse at all - a corrupt buffer whose first byte
|
|
29
|
+
* The shape check is not redundant with the try/catch. The msgpack decoder only throws on input
|
|
30
|
+
* it can not parse at all - a corrupt buffer whose first byte is a valid type marker decodes to
|
|
31
31
|
* a plain number or string instead. Such an entry has no `path`, so downstream it would register
|
|
32
32
|
* as a phantom mailbox keyed `undefined` and (via Object.assign onto a primitive) surface as a
|
|
33
33
|
* boxed Number in the mailboxes API response.
|
|
@@ -11,12 +11,12 @@ const {
|
|
|
11
11
|
mailboxPathHash,
|
|
12
12
|
getMailboxStatusKey
|
|
13
13
|
} = require('../../tools');
|
|
14
|
-
const msgpack = require('
|
|
14
|
+
const msgpack = require('../../msgpack');
|
|
15
15
|
const he = require('he');
|
|
16
16
|
const libmime = require('libmime');
|
|
17
17
|
const settings = require('../../settings');
|
|
18
|
-
const { bounceDetect } = require('../../bounce-detect');
|
|
19
|
-
const { arfDetect } = require('../../arf-detect');
|
|
18
|
+
const { bounceDetect, applyDeliveryReport } = require('../../bounce-detect');
|
|
19
|
+
const { arfDetect, camelCaseComplaint } = require('../../arf-detect');
|
|
20
20
|
const appendList = require('../../append-list');
|
|
21
21
|
const { messageWebSafeHtml } = require('../../web-safe-html');
|
|
22
22
|
const simpleParser = require('mailparser').simpleParser;
|
|
@@ -1086,16 +1086,7 @@ class Mailbox {
|
|
|
1086
1086
|
|
|
1087
1087
|
if (report && report.arf && report.arf['original-rcpt-to'] && report.arf['original-rcpt-to'].length) {
|
|
1088
1088
|
// Valid complaint found - prepare notification data
|
|
1089
|
-
let complaint =
|
|
1090
|
-
for (let subKey of ['arf', 'headers']) {
|
|
1091
|
-
for (let key of Object.keys(report[subKey])) {
|
|
1092
|
-
if (!complaint[subKey]) {
|
|
1093
|
-
complaint[subKey] = {};
|
|
1094
|
-
}
|
|
1095
|
-
// Convert kebab-case to camelCase
|
|
1096
|
-
complaint[subKey][key.replace(/-(.)/g, (o, c) => c.toUpperCase())] = report[subKey][key];
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1089
|
+
let complaint = camelCaseComplaint(report);
|
|
1099
1090
|
|
|
1100
1091
|
complaintNotifyInfo = Object.assign({ complaintMessage: messageInfo.id }, complaint);
|
|
1101
1092
|
|
|
@@ -1128,62 +1119,7 @@ class Mailbox {
|
|
|
1128
1119
|
let parsed = await simpleParser(sourceStream, { keepDeliveryStatus: true });
|
|
1129
1120
|
if (parsed) {
|
|
1130
1121
|
content = { parsed };
|
|
1131
|
-
|
|
1132
|
-
// Extract delivery status information
|
|
1133
|
-
let deliveryStatus = parsed.attachments.find(attachment => attachment.contentType === 'message/delivery-status');
|
|
1134
|
-
if (deliveryStatus) {
|
|
1135
|
-
let deliveryEntries = libmime.decodeHeaders((deliveryStatus.content || '').toString().trim());
|
|
1136
|
-
let structured = {};
|
|
1137
|
-
|
|
1138
|
-
// Parse delivery status headers
|
|
1139
|
-
for (let key of Object.keys(deliveryEntries)) {
|
|
1140
|
-
if (!key) {
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
let displayKey = key.replace(/-(.)/g, (m, c) => c.toUpperCase());
|
|
1144
|
-
let value = deliveryEntries[key].at(-1);
|
|
1145
|
-
if (typeof value === 'string') {
|
|
1146
|
-
// Parse structured values like "rfc822;example.com"
|
|
1147
|
-
let m = value.match(/^([^\s;]+);/);
|
|
1148
|
-
if (m) {
|
|
1149
|
-
value = {
|
|
1150
|
-
label: m[1],
|
|
1151
|
-
value: value.substring(m[0].length).trim()
|
|
1152
|
-
};
|
|
1153
|
-
} else {
|
|
1154
|
-
switch (key) {
|
|
1155
|
-
case 'arrival-date': {
|
|
1156
|
-
value.trim();
|
|
1157
|
-
let date = new Date(value);
|
|
1158
|
-
if (date.toString() !== 'Invalid Date') {
|
|
1159
|
-
value = date.toISOString();
|
|
1160
|
-
}
|
|
1161
|
-
structured[displayKey] = value;
|
|
1162
|
-
break;
|
|
1163
|
-
}
|
|
1164
|
-
default:
|
|
1165
|
-
structured[displayKey] = value.trim();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
} else {
|
|
1169
|
-
// ???
|
|
1170
|
-
structured[displayKey] = value;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
// Only consider as delivery report if action indicates delivery or delay
|
|
1175
|
-
if (/^delivered|^delayed/i.test(structured.action)) {
|
|
1176
|
-
this.logger.debug({
|
|
1177
|
-
msg: 'Detected delivery report',
|
|
1178
|
-
id: messageInfo.id,
|
|
1179
|
-
uid: messageInfo.uid,
|
|
1180
|
-
messageId: messageInfo.messageId,
|
|
1181
|
-
report: structured
|
|
1182
|
-
});
|
|
1183
|
-
|
|
1184
|
-
messageInfo.deliveryReport = structured;
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1122
|
+
applyDeliveryReport(parsed, messageInfo, this.logger);
|
|
1187
1123
|
}
|
|
1188
1124
|
} catch (err) {
|
|
1189
1125
|
this.logger.error({
|
|
@@ -6,7 +6,7 @@ const { Mailbox } = require('./imap/mailbox');
|
|
|
6
6
|
const logger = require('../logger');
|
|
7
7
|
const packageData = require('../../package.json');
|
|
8
8
|
const { backOff } = require('exponential-backoff');
|
|
9
|
-
const msgpack = require('
|
|
9
|
+
const msgpack = require('../msgpack');
|
|
10
10
|
|
|
11
11
|
const { oauth2ProviderData } = require('../oauth2-apps');
|
|
12
12
|
const { BaseClient } = require('./base-client');
|
|
@@ -20,6 +20,7 @@ const { ReconnectBackoff } = require('./reconnect-backoff');
|
|
|
20
20
|
const {
|
|
21
21
|
normalizePath,
|
|
22
22
|
resolveCredentials,
|
|
23
|
+
useAuthServerForConnection,
|
|
23
24
|
emitChangeEvent,
|
|
24
25
|
getByteSize,
|
|
25
26
|
getBoolean,
|
|
@@ -1387,7 +1388,7 @@ class IMAPClient extends BaseClient {
|
|
|
1387
1388
|
}
|
|
1388
1389
|
|
|
1389
1390
|
// If authentication server is set then it overrides authentication data
|
|
1390
|
-
if (imapConnectionConfig.
|
|
1391
|
+
if (await useAuthServerForConnection(imapConnectionConfig, ctx.logger, { account: this.account, target: 'imap' })) {
|
|
1391
1392
|
try {
|
|
1392
1393
|
imapConnectionConfig.auth = await resolveCredentials(this.account, 'imap');
|
|
1393
1394
|
} catch (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { Gateway } = require('../gateway');
|
|
4
4
|
const { oauth2ProviderData } = require('../oauth2-apps');
|
|
5
|
-
const { resolveCredentials } = require('../tools');
|
|
5
|
+
const { resolveCredentials, useAuthServerForConnection } = require('../tools');
|
|
6
6
|
const { getLocalAddress } = require('../utils/network');
|
|
7
7
|
const settings = require('../settings');
|
|
8
8
|
const { TLS_DEFAULTS } = require('../consts');
|
|
@@ -133,20 +133,20 @@ class SmtpConfigBuilder {
|
|
|
133
133
|
* @returns {Promise<Object|null>} Resolved auth credentials
|
|
134
134
|
*/
|
|
135
135
|
async resolveAuthServer(smtpConnectionConfig) {
|
|
136
|
-
if (
|
|
137
|
-
|
|
136
|
+
if (await useAuthServerForConnection(smtpConnectionConfig, this.logger, { account: this.account, target: 'smtp' })) {
|
|
137
|
+
try {
|
|
138
|
+
return await resolveCredentials(this.account, 'smtp');
|
|
139
|
+
} catch (err) {
|
|
140
|
+
err.authenticationFailed = true;
|
|
141
|
+
this.logger.error({
|
|
142
|
+
account: this.account,
|
|
143
|
+
err
|
|
144
|
+
});
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
138
147
|
}
|
|
139
148
|
|
|
140
|
-
|
|
141
|
-
return await resolveCredentials(this.account, 'smtp');
|
|
142
|
-
} catch (err) {
|
|
143
|
-
err.authenticationFailed = true;
|
|
144
|
-
this.logger.error({
|
|
145
|
-
account: this.account,
|
|
146
|
-
err
|
|
147
|
-
});
|
|
148
|
-
throw err;
|
|
149
|
-
}
|
|
149
|
+
return smtpConnectionConfig.auth;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
/**
|
|
@@ -6,7 +6,7 @@ const { checkAccountScopes } = require('../oauth/scope-checker');
|
|
|
6
6
|
const settings = require('../settings');
|
|
7
7
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
8
8
|
const getSecret = require('../get-secret');
|
|
9
|
-
const msgpack = require('
|
|
9
|
+
const msgpack = require('../msgpack');
|
|
10
10
|
const he = require('he');
|
|
11
11
|
const { emitChangeEvent, prepareUrl } = require('../tools');
|
|
12
12
|
const { messageWebSafeHtml } = require('../web-safe-html');
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { ADDRESS_STRATEGIES } = require('./address-strategies');
|
|
4
|
+
|
|
5
|
+
// Per-value documentation for the enums whose values are not self-explanatory. Attached to
|
|
6
|
+
// the joi schemas below with `.meta({ enumDescriptions })`, which the OpenAPI generator emits
|
|
7
|
+
// as `x-meta.enumDescriptions` alongside the `enum` array - so the meaning of each value
|
|
8
|
+
// reaches /swagger.json and every consumer of it, not just the admin API reference.
|
|
9
|
+
//
|
|
10
|
+
// Only enums whose values carry real semantics are listed. Ones that already spell their
|
|
11
|
+
// values out in their own description (imapIndexer, textType, action) are left alone.
|
|
12
|
+
const ENUM_DESCRIPTIONS = {
|
|
13
|
+
// derived, so adding a strategy cannot leave the API reference behind
|
|
14
|
+
addressStrategy: Object.fromEntries(ADDRESS_STRATEGIES.map(entry => [entry.key, entry.description])),
|
|
15
|
+
|
|
16
|
+
accountState: {
|
|
17
|
+
init: 'The account was just registered and has not connected yet',
|
|
18
|
+
connecting: 'Connecting to the mail server or authorizing with the provider',
|
|
19
|
+
syncing: 'Connected and performing the initial or a periodic mailbox sync',
|
|
20
|
+
connected: 'Connected and watching for changes. This is the healthy steady state',
|
|
21
|
+
disconnected: 'The connection dropped and EmailEngine is retrying with backoff',
|
|
22
|
+
paused: 'Syncing was paused through the API. No connection is maintained',
|
|
23
|
+
authenticationError: 'The credentials were rejected. Requires re-authentication before syncing resumes',
|
|
24
|
+
connectError: 'The server could not be reached or the TLS handshake failed. Retried with backoff',
|
|
25
|
+
unset: 'No IMAP or OAuth2 configuration is set, so the account is not synced'
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
outboxStatus: {
|
|
29
|
+
queued: 'Accepted and waiting for a delivery attempt',
|
|
30
|
+
processing: 'A submit worker has picked the message up',
|
|
31
|
+
'smtp-starting': 'Opening the SMTP connection to the destination',
|
|
32
|
+
'smtp-completed': 'The SMTP transaction finished and the message was handed over',
|
|
33
|
+
submitted: 'Delivered to the receiving server. Later bounces arrive as webhooks',
|
|
34
|
+
error: 'Delivery failed. See the error field for the reason and whether it will be retried'
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
outboxSource: {
|
|
38
|
+
smtp: 'Submitted through the built-in SMTP server',
|
|
39
|
+
api: 'Submitted through the REST API',
|
|
40
|
+
test: 'Generated by a deliverability test',
|
|
41
|
+
ui: 'Sent from the admin interface'
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
exportStatus: {
|
|
45
|
+
queued: 'Accepted and waiting for an export worker',
|
|
46
|
+
processing: 'Currently reading messages from the account',
|
|
47
|
+
completed: 'Finished. The download endpoint now serves the archive',
|
|
48
|
+
failed: 'Stopped on an error. See the error field',
|
|
49
|
+
cancelled: 'Deleted through the API before it finished'
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
exportPhase: {
|
|
53
|
+
indexing: 'Listing the folders and counting the messages to export',
|
|
54
|
+
exporting: 'Writing messages to the export file',
|
|
55
|
+
complete: 'All messages have been written'
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
messageCategory: {
|
|
59
|
+
primary: 'The Primary inbox tab',
|
|
60
|
+
social: 'The Social tab (notifications from social networks)',
|
|
61
|
+
promotions: 'The Promotions tab (marketing mail)',
|
|
62
|
+
updates: 'The Updates tab (receipts, confirmations, statements)',
|
|
63
|
+
forums: 'The Forums tab (mailing lists and discussion groups)'
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
oauth2Provider: {
|
|
67
|
+
gmail: 'Gmail and Google Workspace, using a user-consented OAuth2 flow',
|
|
68
|
+
gmailService: 'Google Workspace using a service account, with no per-user consent screen',
|
|
69
|
+
outlook: 'Outlook and Microsoft 365, using a user-consented OAuth2 flow',
|
|
70
|
+
outlookService: 'Microsoft 365 using application permissions, with no per-user consent screen',
|
|
71
|
+
mailRu: 'Mail.ru'
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
azureCloud: {
|
|
75
|
+
global: 'The worldwide Azure cloud, used by most tenants',
|
|
76
|
+
'gcc-high': 'US Government Community Cloud High',
|
|
77
|
+
dod: 'US Department of Defense cloud',
|
|
78
|
+
china: 'Azure operated by 21Vianet in China'
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
appBaseScopes: {
|
|
82
|
+
imap: 'Access mailboxes over IMAP and SMTP using OAuth2 credentials',
|
|
83
|
+
api: 'Access mailboxes through the provider API (Gmail API or MS Graph)',
|
|
84
|
+
pubsub: 'Receive Gmail push notifications through Google Pub/Sub'
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
tokenScope: {
|
|
88
|
+
api: 'Call the REST API',
|
|
89
|
+
smtp: 'Authenticate against the built-in SMTP submission server',
|
|
90
|
+
'imap-proxy': 'Authenticate against the built-in IMAP proxy'
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
queueId: {
|
|
94
|
+
notify: 'Webhook delivery queue',
|
|
95
|
+
submit: 'Outbound email delivery queue',
|
|
96
|
+
documents: 'Document Store indexing queue (deprecated feature)'
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
pubsubState: {
|
|
100
|
+
creating: 'The subscription is being created',
|
|
101
|
+
created: 'Active and delivering notifications',
|
|
102
|
+
renewing: 'Being renewed before it expires',
|
|
103
|
+
error: 'Creation or renewal failed. See the error field'
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
dsnNotify: {
|
|
107
|
+
never: 'Never send a delivery status notification',
|
|
108
|
+
success: 'Notify when the message is delivered',
|
|
109
|
+
failure: 'Notify when the message cannot be delivered',
|
|
110
|
+
delay: 'Notify when the message is delayed'
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
messageUploadDisposition: {
|
|
114
|
+
inline: 'Rendered inside the message body, referenced by a cid: URL',
|
|
115
|
+
attachment: 'Offered as a downloadable file'
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
mailboxSpecialUse: {
|
|
119
|
+
'\\All': 'Contains every message in the account (Gmail "All Mail")',
|
|
120
|
+
'\\Archive': 'Archived messages',
|
|
121
|
+
'\\Drafts': 'Unsent drafts',
|
|
122
|
+
'\\Flagged': 'Messages the user flagged or starred',
|
|
123
|
+
'\\Junk': 'Spam',
|
|
124
|
+
'\\Sent': 'Sent messages',
|
|
125
|
+
'\\Trash': 'Deleted messages awaiting purge',
|
|
126
|
+
'\\Inbox': 'The inbox'
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
module.exports = { ENUM_DESCRIPTIONS };
|
package/lib/export.js
CHANGED
|
@@ -4,7 +4,7 @@ const os = require('os');
|
|
|
4
4
|
const crypto = require('crypto');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const pathlib = require('path');
|
|
7
|
-
const msgpack = require('
|
|
7
|
+
const msgpack = require('./msgpack');
|
|
8
8
|
const { redis, exportQueue } = require('./db');
|
|
9
9
|
const settings = require('./settings');
|
|
10
10
|
const logger = require('./logger');
|
package/lib/gateway.js
CHANGED
package/lib/get-raw-email.js
CHANGED
|
@@ -10,7 +10,7 @@ const { randomUUID: uuid } = require('crypto');
|
|
|
10
10
|
const os = require('os');
|
|
11
11
|
const libmime = require('libmime');
|
|
12
12
|
const { getBoolean, genBaseBoundary } = require('./tools');
|
|
13
|
-
const msgpack = require('
|
|
13
|
+
const msgpack = require('./msgpack');
|
|
14
14
|
const crypto = require('crypto');
|
|
15
15
|
const simpleParser = require('mailparser').simpleParser;
|
|
16
16
|
|
|
@@ -8,7 +8,7 @@ const search = require('./search');
|
|
|
8
8
|
const dns = require('dns');
|
|
9
9
|
const crypto = require('crypto');
|
|
10
10
|
const os = require('os');
|
|
11
|
-
const
|
|
11
|
+
const { base32Encode } = require('../../../base32');
|
|
12
12
|
const EventEmitter = require('events').EventEmitter;
|
|
13
13
|
const packageInfo = require('../../../../package');
|
|
14
14
|
|
|
@@ -33,7 +33,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
33
33
|
|
|
34
34
|
options = options || {};
|
|
35
35
|
// Random session ID, used for logging
|
|
36
|
-
this.id = options.id ||
|
|
36
|
+
this.id = options.id || base32Encode(crypto.randomBytes(10)).toLowerCase();
|
|
37
37
|
|
|
38
38
|
this.ignore = options.ignore;
|
|
39
39
|
|
|
@@ -8,7 +8,7 @@ const tlsOptions = require('./tls-options');
|
|
|
8
8
|
const EventEmitter = require('events').EventEmitter;
|
|
9
9
|
const shared = require('nodemailer/lib/shared');
|
|
10
10
|
const punycode = require('punycode.js');
|
|
11
|
-
const
|
|
11
|
+
const { base32Encode } = require('../../../base32');
|
|
12
12
|
|
|
13
13
|
const CLOSE_TIMEOUT = 1 * 1000; // how much to wait until pending connections are terminated
|
|
14
14
|
|
|
@@ -208,7 +208,7 @@ class IMAPServer extends EventEmitter {
|
|
|
208
208
|
|
|
209
209
|
_handleProxy(socket, callback) {
|
|
210
210
|
let socketOptions = {
|
|
211
|
-
id:
|
|
211
|
+
id: base32Encode(crypto.randomBytes(10)).toLowerCase()
|
|
212
212
|
};
|
|
213
213
|
|
|
214
214
|
if (
|