emailengine-app 2.74.2 → 2.76.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/test.yml +0 -10
- package/CHANGELOG.md +40 -0
- package/config/e2e.toml +1 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +94 -18
- package/lib/api-routes/message-routes.js +3 -1
- package/lib/api-routes/route-helpers.js +3 -0
- package/lib/api-routes/submit-routes.js +159 -52
- package/lib/consts.js +6 -0
- package/lib/db.js +4 -1
- package/lib/egress-filter.js +220 -0
- package/lib/email-client/base-client.js +169 -27
- package/lib/email-client/gmail/send-request.js +16 -1
- package/lib/email-client/gmail-client.js +91 -10
- package/lib/email-client/imap/mailbox.js +3 -9
- package/lib/email-client/imap-client.js +103 -1
- package/lib/email-client/message-builder.js +24 -7
- package/lib/email-client/notification-handler.js +11 -12
- package/lib/email-client/outlook/send-request.js +18 -1
- package/lib/email-client/outlook-client.js +81 -9
- package/lib/imapproxy/imap-core/README.md +69 -0
- package/lib/oauth/external-account-config.js +41 -1
- package/lib/oauth/external-account-signer.js +7 -2
- package/lib/oauth/verify-app.js +18 -3
- package/lib/queue-retention.js +56 -0
- package/lib/respawn-backoff.js +95 -0
- package/lib/schemas.js +9 -2
- package/lib/settings.js +4 -1
- package/lib/tools.js +20 -0
- package/lib/ui-routes/admin-config-routes.js +22 -18
- package/lib/utils/network.js +122 -3
- package/lib/web-safe-html.js +401 -0
- package/lib/webhook-request.js +40 -2
- package/lib/webhooks.js +2 -3
- package/package.json +17 -20
- package/playwright.config.js +1 -1
- package/sbom.json +1 -1
- package/server.js +45 -8
- package/static/js/ee-client.js +55 -6
- package/static/js/ui.js +13 -0
- package/static/licenses.html +332 -292
- package/translations/messages.pot +52 -52
- package/views/config/webhooks.hbs +2 -2
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/workers/api.js +32 -17
- package/workers/documents.js +6 -0
- package/workers/export.js +8 -1
- package/workers/imap.js +17 -19
- package/workers/submit.js +10 -0
- package/workers/webhooks.js +23 -2
- package/Gruntfile.js +0 -58
|
@@ -78,11 +78,6 @@ jobs:
|
|
|
78
78
|
with:
|
|
79
79
|
node-version: 24
|
|
80
80
|
cache: npm
|
|
81
|
-
- name: Setup Redis CLI
|
|
82
|
-
uses: shogo82148/actions-setup-redis@v1
|
|
83
|
-
with:
|
|
84
|
-
redis-version: '7.x'
|
|
85
|
-
auto-start: 'false'
|
|
86
81
|
- run: npm install
|
|
87
82
|
- name: Run unit tests
|
|
88
83
|
run: |
|
|
@@ -157,11 +152,6 @@ jobs:
|
|
|
157
152
|
with:
|
|
158
153
|
node-version: 24
|
|
159
154
|
cache: npm
|
|
160
|
-
- name: Setup Redis CLI
|
|
161
|
-
uses: shogo82148/actions-setup-redis@v1
|
|
162
|
-
with:
|
|
163
|
-
redis-version: '7.x'
|
|
164
|
-
auto-start: 'false'
|
|
165
155
|
- run: npm install
|
|
166
156
|
- name: Run integration tests
|
|
167
157
|
run: |
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.76.0](https://github.com/postalsys/emailengine/compare/v2.75.0...v2.76.0) (2026-07-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add an API endpoint for sending stored drafts ([16e759a](https://github.com/postalsys/emailengine/commit/16e759aab429160d312827618841222c7704057d))
|
|
9
|
+
* add EENGINE_UPDATE_CHECK_DISABLED to opt out of the GitHub update check ([e92bfe6](https://github.com/postalsys/emailengine/commit/e92bfe6e9b01ae9abe1cc782b51d39aac94b2341))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **deps:** update dependencies (imapflow 1.6.3) ([7dc423c](https://github.com/postalsys/emailengine/commit/7dc423cafe45206c36b8293f1a57f47f56594dfe))
|
|
15
|
+
* **deps:** update dependencies (imapflow 1.6.5) ([6a350e1](https://github.com/postalsys/emailengine/commit/6a350e1ab7e8b96ae089d0768c2a9300e0a405e0))
|
|
16
|
+
* **imap:** stop re-listing the folders on every connection setup ([6d79eb3](https://github.com/postalsys/emailengine/commit/6d79eb3f67a3d2bb826f43483c4e51d03ea98d8a))
|
|
17
|
+
|
|
18
|
+
## [2.75.0](https://github.com/postalsys/emailengine/compare/v2.74.2...v2.75.0) (2026-07-28)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **web-safe-html:** fold quoted thread history into a collapse marker ([25d45bf](https://github.com/postalsys/emailengine/commit/25d45bf5b8dcc64443272f4b85178ee2c497d79c))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **account:** serialize account updates so a refreshed token is not lost ([e577825](https://github.com/postalsys/emailengine/commit/e5778255710b1be912e6b259073ec963c2da03a2))
|
|
29
|
+
* **api:** match IPv4-mapped peer addresses against the address allowlists ([5acff06](https://github.com/postalsys/emailengine/commit/5acff061b31af6db49ffe9d856a5017bdfcaf4e7))
|
|
30
|
+
* **api:** trust X-Forwarded-For only from declared proxies ([6e93ea7](https://github.com/postalsys/emailengine/commit/6e93ea714cd75aa876f713345d675a5416b36aeb))
|
|
31
|
+
* **api:** warn about a spoofable admin allowlist when the proxy list is empty ([4309abe](https://github.com/postalsys/emailengine/commit/4309abe2d45652699f76b4adc31ff37e79802a53))
|
|
32
|
+
* **deps:** bump imapflow to 1.6.1 to restore IMAP account verification ([c2a5437](https://github.com/postalsys/emailengine/commit/c2a543779b29c369d35bfbbc175810fc1d96f02c))
|
|
33
|
+
* **deps:** update @postalsys/email-ai-tools to 1.13.15 ([89ec145](https://github.com/postalsys/emailengine/commit/89ec145a8f43a29405cf154825601dd8ba10fae6))
|
|
34
|
+
* **deps:** update dependencies ([@bull-board](https://github.com/bull-board) 8.3.2) ([a5644f3](https://github.com/postalsys/emailengine/commit/a5644f34e56128451c642d2034ddf7db0d1cc7a8))
|
|
35
|
+
* **logging:** stop logging decrypted setting values and lower Redis reconnect noise ([5c62ac4](https://github.com/postalsys/emailengine/commit/5c62ac486112688e8a964c66a43eb609abe7c8da))
|
|
36
|
+
* **oauth:** pin external account token_url to Google STS ([27ade81](https://github.com/postalsys/emailengine/commit/27ade8183cd31b503077ebefd5724f2f0620947d))
|
|
37
|
+
* **queue:** retain failed queue entries instead of deleting them on arrival ([e83af35](https://github.com/postalsys/emailengine/commit/e83af359aafc49d584cd0c234e089e9dceb83f3b))
|
|
38
|
+
* **server:** drain workers on shutdown and back off crash-looping respawns ([29b3b5d](https://github.com/postalsys/emailengine/commit/29b3b5d0d7b76793ea2852c9a37a8c622217a6ea))
|
|
39
|
+
* **webhooks:** filter webhook egress and stop following redirects ([e44bed5](https://github.com/postalsys/emailengine/commit/e44bed549848d8eb2b04bb991aa2c6cee0bb47c2))
|
|
40
|
+
* **webhooks:** report the refused redirect status and probe through the delivery path ([9f7c666](https://github.com/postalsys/emailengine/commit/9f7c666f5e2a0bfae069a0c43c33a75d04922747))
|
|
41
|
+
* **webhooks:** stop retrying an endpoint that answers with a redirect ([bbb6055](https://github.com/postalsys/emailengine/commit/bbb605560d31bb494495b46a57cd233a78024d99))
|
|
42
|
+
|
|
3
43
|
## [2.74.2](https://github.com/postalsys/emailengine/compare/v2.74.1...v2.74.2) (2026-07-26)
|
|
4
44
|
|
|
5
45
|
|
package/config/e2e.toml
CHANGED
package/lib/account.js
CHANGED
|
@@ -21,6 +21,7 @@ const { deepStrictEqual, strictEqual } = require('assert');
|
|
|
21
21
|
const { encrypt, decrypt } = require('./encrypt');
|
|
22
22
|
const { oauth2Apps, LEGACY_KEYS, isApiBasedApp } = require('./oauth2-apps');
|
|
23
23
|
const settings = require('./settings');
|
|
24
|
+
const { buildRetentionPolicy } = require('./queue-retention');
|
|
24
25
|
const { isDocumentStoreEnabled, documentStoreFeatureEnabled } = require('./document-store');
|
|
25
26
|
const redisScanDelete = require('./redis-scan-delete');
|
|
26
27
|
const { customAlphabet } = require('nanoid');
|
|
@@ -28,7 +29,7 @@ const Lock = require('ioredfour');
|
|
|
28
29
|
const { redis } = require('./db');
|
|
29
30
|
const nanoid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 16);
|
|
30
31
|
const { REDIS_PREFIX, ACCOUNT_DELETED_NOTIFY } = require('./consts');
|
|
31
|
-
const {
|
|
32
|
+
const { messageWebSafeHtml } = require('./web-safe-html');
|
|
32
33
|
const { checkAccountScopes: checkScopes } = require('./oauth/scope-checker');
|
|
33
34
|
const { ACCOUNT_STATES, ERROR_STATES, calculateEffectiveState, validateAccountState, getDisplayState, formatLastError } = require('./account/account-state');
|
|
34
35
|
const { decodeStoredMailboxEntry } = require('./email-client/imap/listing-diff');
|
|
@@ -40,6 +41,11 @@ const defaultLock = new Lock({
|
|
|
40
41
|
namespace: 'ee'
|
|
41
42
|
});
|
|
42
43
|
|
|
44
|
+
// Serialization window for Account.update(). The critical section is a few Redis round trips, so
|
|
45
|
+
// the TTL only has to cover a stalled writer, and the wait only has to outlast a normal one.
|
|
46
|
+
const ACCOUNT_UPDATE_LOCK_TTL = 10 * 1000;
|
|
47
|
+
const ACCOUNT_UPDATE_LOCK_WAIT = 5 * 1000;
|
|
48
|
+
|
|
43
49
|
class Account {
|
|
44
50
|
constructor(options) {
|
|
45
51
|
this.redis = options.redis;
|
|
@@ -725,11 +731,74 @@ class Account {
|
|
|
725
731
|
return accountData;
|
|
726
732
|
}
|
|
727
733
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
734
|
+
/**
|
|
735
|
+
* Applies an account update, serialized per account.
|
|
736
|
+
*
|
|
737
|
+
* persistUpdate() is a read-modify-write: it loads the stored account, merges partial
|
|
738
|
+
* `imap`/`smtp`/`oauth2` objects into what it read, and writes the result back. Two writers
|
|
739
|
+
* interleaving there silently lose one of the merges - the case that matters is an unattended
|
|
740
|
+
* OAuth2 token refresh landing between an admin update's read and its write, which puts the
|
|
741
|
+
* stale refreshToken back and leaves the account unable to authenticate until someone
|
|
742
|
+
* reauthorizes it by hand. The same check-then-set applies to the OAuth2 user uniqueness
|
|
743
|
+
* check inside. The lock covers that half only; see dispatchPostUpdateCommands().
|
|
744
|
+
*
|
|
745
|
+
* Lock acquisition failing is not treated as an error. The critical section is a handful of
|
|
746
|
+
* Redis round trips, so a timeout here means Redis is already in trouble; refusing the write
|
|
747
|
+
* would take out token refreshes for every account rather than losing a rare merge.
|
|
748
|
+
*
|
|
749
|
+
* @param {Object} accountData - Account fields to write
|
|
750
|
+
* @param {Object} [opts]
|
|
751
|
+
* @param {boolean} [opts.reauthorized] - Marks an update carrying credentials supplied by an
|
|
752
|
+
* external caller, i.e. possible operator re-authorization. Only the public account-update
|
|
753
|
+
* API route sets it; every unattended writer (token renewal, client initialize(),
|
|
754
|
+
* invalidateAccessToken) leaves it false and can therefore never trigger the reconnect gate.
|
|
755
|
+
* @returns {Promise<Object>} `{ account }`
|
|
756
|
+
*/
|
|
732
757
|
async update(accountData, { reauthorized = false } = {}) {
|
|
758
|
+
const lock = this.getLock();
|
|
759
|
+
const lockKey = `account:update:${accountData.account}`;
|
|
760
|
+
let updateLock;
|
|
761
|
+
|
|
762
|
+
let lockErr;
|
|
763
|
+
try {
|
|
764
|
+
updateLock = await lock.waitAcquireLock(lockKey, ACCOUNT_UPDATE_LOCK_TTL, ACCOUNT_UPDATE_LOCK_WAIT);
|
|
765
|
+
} catch (err) {
|
|
766
|
+
lockErr = err;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (!updateLock?.success) {
|
|
770
|
+
this.logger.warn({ msg: 'Failed to get account update lock, proceeding unserialized', account: accountData.account, lockKey, err: lockErr });
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
let oldAccountData;
|
|
774
|
+
try {
|
|
775
|
+
oldAccountData = await this.persistUpdate(accountData);
|
|
776
|
+
} finally {
|
|
777
|
+
if (updateLock?.success) {
|
|
778
|
+
try {
|
|
779
|
+
await lock.releaseLock(updateLock);
|
|
780
|
+
} catch (err) {
|
|
781
|
+
// The lock expires on its own, so a failed release must not mask the result
|
|
782
|
+
this.logger.error({ msg: 'Failed to release account update lock', account: accountData.account, lockKey, err });
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
await this.dispatchPostUpdateCommands(accountData, oldAccountData, reauthorized);
|
|
788
|
+
|
|
789
|
+
return {
|
|
790
|
+
account: this.account
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The read-modify-write half of update(): loads the stored account, merges partial credential
|
|
796
|
+
* objects into it and writes the result back. Runs under the update lock.
|
|
797
|
+
*
|
|
798
|
+
* @param {Object} accountData - Account fields to write
|
|
799
|
+
* @returns {Promise<Object>} The account as it was before the write
|
|
800
|
+
*/
|
|
801
|
+
async persistUpdate(accountData) {
|
|
733
802
|
let oldAccountData = await this.loadAccountData(accountData.account);
|
|
734
803
|
|
|
735
804
|
if (accountData.oauth2?.provider) {
|
|
@@ -822,6 +891,23 @@ class Account {
|
|
|
822
891
|
throw error;
|
|
823
892
|
}
|
|
824
893
|
|
|
894
|
+
return oldAccountData;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Dispatches the reconnect/update commands a persisted change implies.
|
|
899
|
+
*
|
|
900
|
+
* Deliberately runs outside the update lock. These are RPCs into the IMAP worker, and the
|
|
901
|
+
* connection setup they trigger can itself persist an account change (a token renewal during
|
|
902
|
+
* connect), so holding the lock across them would make a writer wait on its own dispatch.
|
|
903
|
+
* Nothing here writes account data; it only compares what was read against what was written.
|
|
904
|
+
*
|
|
905
|
+
* @param {Object} accountData - The fields that were just written
|
|
906
|
+
* @param {Object} oldAccountData - The account as it was before the write
|
|
907
|
+
* @param {boolean} reauthorized - Whether the caller supplied fresh operator credentials
|
|
908
|
+
* @returns {Promise<void>} Resolves once the dispatch has been attempted
|
|
909
|
+
*/
|
|
910
|
+
async dispatchPostUpdateCommands(accountData, oldAccountData, reauthorized) {
|
|
825
911
|
let reconnectRequested = false;
|
|
826
912
|
|
|
827
913
|
if ('imap' in accountData && !reconnectRequested) {
|
|
@@ -915,10 +1001,6 @@ class Account {
|
|
|
915
1001
|
});
|
|
916
1002
|
}
|
|
917
1003
|
}
|
|
918
|
-
|
|
919
|
-
return {
|
|
920
|
-
account: this.account
|
|
921
|
-
};
|
|
922
1004
|
}
|
|
923
1005
|
|
|
924
1006
|
async genId() {
|
|
@@ -1153,7 +1235,7 @@ class Account {
|
|
|
1153
1235
|
// consumed and would pile up in Redis.
|
|
1154
1236
|
if (documentStoreFeatureEnabled) {
|
|
1155
1237
|
try {
|
|
1156
|
-
let queueKeep = (await settings.get('queueKeep'))
|
|
1238
|
+
let queueKeep = (await settings.get('queueKeep')) ?? true;
|
|
1157
1239
|
let serviceUrl = (await settings.get('serviceUrl')) || null;
|
|
1158
1240
|
|
|
1159
1241
|
let payload = {
|
|
@@ -1164,8 +1246,7 @@ class Account {
|
|
|
1164
1246
|
};
|
|
1165
1247
|
|
|
1166
1248
|
await this.documentsQueue.add(ACCOUNT_DELETED_NOTIFY, payload, {
|
|
1167
|
-
|
|
1168
|
-
removeOnFail: queueKeep,
|
|
1249
|
+
...buildRetentionPolicy(queueKeep),
|
|
1169
1250
|
attempts: 10,
|
|
1170
1251
|
backoff: {
|
|
1171
1252
|
type: 'exponential',
|
|
@@ -1691,12 +1772,7 @@ class Account {
|
|
|
1691
1772
|
|
|
1692
1773
|
if (options.preProcessHtml && messageData.text && (messageData.text.html || messageData.text.plain)) {
|
|
1693
1774
|
// If available, use the cached version
|
|
1694
|
-
messageData.text.html =
|
|
1695
|
-
messageData.text._generatedHtml ||
|
|
1696
|
-
mimeHtml({
|
|
1697
|
-
html: messageData.text.html,
|
|
1698
|
-
text: messageData.text.plain
|
|
1699
|
-
});
|
|
1775
|
+
messageData.text.html = messageData.text._generatedHtml || (await messageWebSafeHtml(messageData));
|
|
1700
1776
|
messageData.text.webSafe = true;
|
|
1701
1777
|
messageData.text._cachedWebSafe = !!messageData.text._generatedHtml;
|
|
1702
1778
|
}
|
|
@@ -6,6 +6,7 @@ const getSecret = require('../get-secret');
|
|
|
6
6
|
const settings = require('../settings');
|
|
7
7
|
const Joi = require('joi');
|
|
8
8
|
const { failAction } = require('../tools');
|
|
9
|
+
const { COLLAPSE_CLASS } = require('../consts');
|
|
9
10
|
const { handleError } = require('./route-helpers');
|
|
10
11
|
|
|
11
12
|
const {
|
|
@@ -168,7 +169,8 @@ async function init(args) {
|
|
|
168
169
|
.falsy('N', 'false', 0)
|
|
169
170
|
.default(false)
|
|
170
171
|
.description(
|
|
171
|
-
'Shorthand option to fetch and preprocess HTML and inline images. Overrides `textType`, `preProcessHtml`, and `embedAttachedImages` options.'
|
|
172
|
+
'Shorthand option to fetch and preprocess HTML and inline images. Overrides `textType`, `preProcessHtml`, and `embedAttachedImages` options. ' +
|
|
173
|
+
`Quoted thread history is folded into a single collapsed <details class="${COLLAPSE_CLASS}"> element.`
|
|
172
174
|
)
|
|
173
175
|
.label('WebSafeHtml'),
|
|
174
176
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Boom = require('@hapi/boom');
|
|
4
3
|
const Joi = require('joi');
|
|
5
4
|
const { redis } = require('../db');
|
|
6
5
|
const { Account } = require('../account');
|
|
7
6
|
const getSecret = require('../get-secret');
|
|
8
7
|
const { failAction } = require('../tools');
|
|
8
|
+
const { handleError } = require('./route-helpers');
|
|
9
9
|
const {
|
|
10
10
|
messageReferenceSchema,
|
|
11
11
|
fromAddressSchema,
|
|
@@ -20,6 +20,50 @@ const {
|
|
|
20
20
|
errorResponses
|
|
21
21
|
} = require('../schemas');
|
|
22
22
|
|
|
23
|
+
// Schema fragments shared between the message submit and the draft submit routes. Joi schemas
|
|
24
|
+
// are immutable, so per-route variants are derived with .description()/.label() where needed.
|
|
25
|
+
const submitHeadersSchema = Joi.object({
|
|
26
|
+
'x-ee-timeout': headerTimeoutSchema,
|
|
27
|
+
'idempotency-key': idempotencyKeySchema
|
|
28
|
+
}).unknown();
|
|
29
|
+
|
|
30
|
+
const sendAtSchema = Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Send message at specified time');
|
|
31
|
+
|
|
32
|
+
const deliveryAttemptsSchema = Joi.number().integer().example(10).description('How many delivery attempts to make until message is considered as failed');
|
|
33
|
+
|
|
34
|
+
const gatewaySchema = Joi.string().max(256).example('example').description('Optional SMTP gateway ID for message routing').label('MessageGateway');
|
|
35
|
+
|
|
36
|
+
const dsnSchema = Joi.object({
|
|
37
|
+
id: Joi.string().trim().empty('').max(256).description('The envelope identifier that would be included in the response (ENVID)'),
|
|
38
|
+
return: Joi.string()
|
|
39
|
+
.trim()
|
|
40
|
+
.empty('')
|
|
41
|
+
.valid('headers', 'full')
|
|
42
|
+
.required()
|
|
43
|
+
.description('Specifies if only headers or the entire body of the message should be included in the response (RET)')
|
|
44
|
+
.label('DsnReturn'),
|
|
45
|
+
notify: Joi.array()
|
|
46
|
+
.single()
|
|
47
|
+
.items(Joi.string().valid('never', 'success', 'failure', 'delay').label('NotifyEntry'))
|
|
48
|
+
.description('Defines the conditions under which a DSN response should be sent')
|
|
49
|
+
.label('DsnNotify'),
|
|
50
|
+
recipient: Joi.string().trim().empty('').email().description('The email address the DSN should be sent (ORCPT)')
|
|
51
|
+
}).description('Request DSN notifications');
|
|
52
|
+
|
|
53
|
+
const proxySchema = settingsSchema.proxyUrl.description('Optional proxy URL to use when connecting to the SMTP server');
|
|
54
|
+
|
|
55
|
+
const localAddressSchema = ipSchema.description('Optional local IP address to bind to when connecting to the SMTP server');
|
|
56
|
+
|
|
57
|
+
const idempotencyResponseSchema = Joi.object({
|
|
58
|
+
key: idempotencyKeySchema.example('submit-12345').description('Idempotency key from the request').label('ResponseIdempotencyKey'),
|
|
59
|
+
status: Joi.string()
|
|
60
|
+
.valid('MISS', 'HIT')
|
|
61
|
+
.example('MISS')
|
|
62
|
+
.description('Whether the response was generated now (MISS) or returned from the idempotency cache (HIT)')
|
|
63
|
+
})
|
|
64
|
+
.description('Idempotency info, present when an Idempotency-Key header was used')
|
|
65
|
+
.label('ResponseIdempotency');
|
|
66
|
+
|
|
23
67
|
async function init(args) {
|
|
24
68
|
const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
|
|
25
69
|
|
|
@@ -43,18 +87,7 @@ async function init(args) {
|
|
|
43
87
|
useStructuredFormat: request.query.useStructuredFormat
|
|
44
88
|
});
|
|
45
89
|
} catch (err) {
|
|
46
|
-
|
|
47
|
-
if (Boom.isBoom(err)) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
|
|
51
|
-
if (err.code) {
|
|
52
|
-
error.output.payload.code = err.code;
|
|
53
|
-
}
|
|
54
|
-
if (err.info) {
|
|
55
|
-
error.output.payload.info = err.info;
|
|
56
|
-
}
|
|
57
|
-
throw error;
|
|
90
|
+
handleError(request, err);
|
|
58
91
|
}
|
|
59
92
|
},
|
|
60
93
|
options: {
|
|
@@ -106,10 +139,7 @@ async function init(args) {
|
|
|
106
139
|
)
|
|
107
140
|
}).label('SubmitQuery'),
|
|
108
141
|
|
|
109
|
-
headers:
|
|
110
|
-
'x-ee-timeout': headerTimeoutSchema,
|
|
111
|
-
'idempotency-key': idempotencyKeySchema
|
|
112
|
-
}).unknown(),
|
|
142
|
+
headers: submitHeadersSchema,
|
|
113
143
|
|
|
114
144
|
payload: Joi.object({
|
|
115
145
|
reference: messageReferenceSchema,
|
|
@@ -285,12 +315,9 @@ async function init(args) {
|
|
|
285
315
|
locale: Joi.string().empty('').max(100).example('fr').description('Optional locale').label('MessageLocale'),
|
|
286
316
|
tz: Joi.string().empty('').max(100).example('Europe/Tallinn').description('Optional timezone'),
|
|
287
317
|
|
|
288
|
-
sendAt:
|
|
289
|
-
deliveryAttempts:
|
|
290
|
-
|
|
291
|
-
.example(10)
|
|
292
|
-
.description('How many delivery attempts to make until message is considered as failed'),
|
|
293
|
-
gateway: Joi.string().max(256).example('example').description('Optional SMTP gateway ID for message routing').label('MessageGateway'),
|
|
318
|
+
sendAt: sendAtSchema,
|
|
319
|
+
deliveryAttempts: deliveryAttemptsSchema,
|
|
320
|
+
gateway: gatewaySchema,
|
|
294
321
|
|
|
295
322
|
listId: Joi.string()
|
|
296
323
|
.hostname()
|
|
@@ -305,24 +332,7 @@ async function init(args) {
|
|
|
305
332
|
otherwise: Joi.forbidden()
|
|
306
333
|
}),
|
|
307
334
|
|
|
308
|
-
dsn:
|
|
309
|
-
id: Joi.string().trim().empty('').max(256).description('The envelope identifier that would be included in the response (ENVID)'),
|
|
310
|
-
return: Joi.string()
|
|
311
|
-
.trim()
|
|
312
|
-
.empty('')
|
|
313
|
-
.valid('headers', 'full')
|
|
314
|
-
.required()
|
|
315
|
-
.description('Specifies if only headers or the entire body of the message should be included in the response (RET)')
|
|
316
|
-
.label('DsnReturn'),
|
|
317
|
-
notify: Joi.array()
|
|
318
|
-
.single()
|
|
319
|
-
.items(Joi.string().valid('never', 'success', 'failure', 'delay').label('NotifyEntry'))
|
|
320
|
-
.description('Defines the conditions under which a DSN response should be sent')
|
|
321
|
-
.label('DsnNotify'),
|
|
322
|
-
recipient: Joi.string().trim().empty('').email().description('The email address the DSN should be sent (ORCPT)')
|
|
323
|
-
})
|
|
324
|
-
.description('Request DSN notifications')
|
|
325
|
-
.label('DSN'),
|
|
335
|
+
dsn: dsnSchema.label('DSN'),
|
|
326
336
|
|
|
327
337
|
baseUrl: Joi.string()
|
|
328
338
|
.trim()
|
|
@@ -334,8 +344,8 @@ async function init(args) {
|
|
|
334
344
|
.example('https://customer123.myservice.com')
|
|
335
345
|
.description('Optional base URL for trackers. This URL must point to your EmailEngine instance.'),
|
|
336
346
|
|
|
337
|
-
proxy:
|
|
338
|
-
localAddress:
|
|
347
|
+
proxy: proxySchema,
|
|
348
|
+
localAddress: localAddressSchema,
|
|
339
349
|
|
|
340
350
|
dryRun: Joi.boolean()
|
|
341
351
|
.truthy('Y', 'true', '1')
|
|
@@ -404,15 +414,7 @@ async function init(args) {
|
|
|
404
414
|
.description('Base64 encoded RFC822 email if a preview was requested. Not returned for mail-merge submissions.')
|
|
405
415
|
.label('ResponsePreview'),
|
|
406
416
|
|
|
407
|
-
idempotency:
|
|
408
|
-
key: idempotencyKeySchema.example('submit-12345').description('Idempotency key from the request').label('ResponseIdempotencyKey'),
|
|
409
|
-
status: Joi.string()
|
|
410
|
-
.valid('MISS', 'HIT')
|
|
411
|
-
.example('MISS')
|
|
412
|
-
.description('Whether the response was generated now (MISS) or returned from the idempotency cache (HIT)')
|
|
413
|
-
})
|
|
414
|
-
.description('Idempotency info, present when an Idempotency-Key header was used')
|
|
415
|
-
.label('ResponseIdempotency'),
|
|
417
|
+
idempotency: idempotencyResponseSchema,
|
|
416
418
|
|
|
417
419
|
mailMerge: Joi.array()
|
|
418
420
|
.items(
|
|
@@ -456,6 +458,111 @@ async function init(args) {
|
|
|
456
458
|
}
|
|
457
459
|
}
|
|
458
460
|
});
|
|
461
|
+
|
|
462
|
+
server.route({
|
|
463
|
+
method: 'POST',
|
|
464
|
+
path: '/v1/account/{account}/message/{message}/submit',
|
|
465
|
+
|
|
466
|
+
async handler(request) {
|
|
467
|
+
let accountObject = new Account({
|
|
468
|
+
redis,
|
|
469
|
+
account: request.params.account,
|
|
470
|
+
call,
|
|
471
|
+
secret: await getSecret(),
|
|
472
|
+
timeout: request.headers['x-ee-timeout']
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
try {
|
|
476
|
+
return await accountObject.queueMessage(request.payload || {}, {
|
|
477
|
+
source: 'api',
|
|
478
|
+
idempotencyKey: request.headers['idempotency-key'],
|
|
479
|
+
draft: { message: request.params.message }
|
|
480
|
+
});
|
|
481
|
+
} catch (err) {
|
|
482
|
+
handleError(request, err);
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
options: {
|
|
486
|
+
description: 'Submit a stored draft for delivery',
|
|
487
|
+
notes: 'Sends an existing draft message. The message must be a draft: stored in the Drafts folder or flagged as a draft (IMAP), carrying the DRAFT label (Gmail), or a draft message (MS Graph). Gmail and MS Graph accounts use the native draft-send call of the provider, which also files the message into the Sent Mail folder and removes the draft. For IMAP accounts the draft is downloaded, sent over SMTP, copied to the Sent Mail folder (unless disabled), and then removed from the Drafts folder.',
|
|
488
|
+
tags: ['api', 'Submit'],
|
|
489
|
+
|
|
490
|
+
plugins: {
|
|
491
|
+
'hapi-swagger': {
|
|
492
|
+
responses: errorResponses(400, 401, 403, 404, 429, 500, 503)
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
auth: {
|
|
497
|
+
strategy: 'api-token',
|
|
498
|
+
mode: 'required'
|
|
499
|
+
},
|
|
500
|
+
cors: CORS_CONFIG,
|
|
501
|
+
|
|
502
|
+
validate: {
|
|
503
|
+
options: {
|
|
504
|
+
stripUnknown: false,
|
|
505
|
+
abortEarly: false,
|
|
506
|
+
convert: true
|
|
507
|
+
},
|
|
508
|
+
failAction,
|
|
509
|
+
|
|
510
|
+
params: Joi.object({
|
|
511
|
+
account: accountIdSchema.required(),
|
|
512
|
+
message: Joi.string().max(256).required().example('AAAAAQAACnA').description('Message ID of the draft')
|
|
513
|
+
}),
|
|
514
|
+
|
|
515
|
+
headers: submitHeadersSchema,
|
|
516
|
+
|
|
517
|
+
payload: Joi.object({
|
|
518
|
+
envelope: Joi.object({
|
|
519
|
+
from: Joi.string().email().allow('').example('sender@example.com'),
|
|
520
|
+
to: Joi.array().items(Joi.string().email().required().example('recipient@example.com')).single().label('DraftSmtpEnvelopeTo')
|
|
521
|
+
})
|
|
522
|
+
.description(
|
|
523
|
+
"An optional object specifying the SMTP envelope used during email transmission. If not provided, the envelope is derived from the draft's message headers. Only used when the message is delivered over SMTP."
|
|
524
|
+
)
|
|
525
|
+
.label('DraftSMTPEnvelope'),
|
|
526
|
+
|
|
527
|
+
copy: Joi.boolean()
|
|
528
|
+
.allow(null)
|
|
529
|
+
.example(null)
|
|
530
|
+
.description(
|
|
531
|
+
"If set then either copies the message to the Sent Mail folder or not. If not set then uses the account's default setting. Only applies to SMTP deliveries - Gmail and MS Graph file sent drafts into the Sent Mail folder themselves."
|
|
532
|
+
),
|
|
533
|
+
|
|
534
|
+
sentMailPath: Joi.string()
|
|
535
|
+
.empty('')
|
|
536
|
+
.max(1024)
|
|
537
|
+
.example('Sent Mail')
|
|
538
|
+
.description("Upload sent message to this folder. By default the account's Sent Mail folder is used. Only applies to SMTP deliveries."),
|
|
539
|
+
|
|
540
|
+
sendAt: sendAtSchema,
|
|
541
|
+
deliveryAttempts: deliveryAttemptsSchema,
|
|
542
|
+
gateway: gatewaySchema,
|
|
543
|
+
|
|
544
|
+
dsn: dsnSchema.description('Request DSN notifications. Only used when the message is delivered over SMTP.').label('DraftDSN'),
|
|
545
|
+
|
|
546
|
+
proxy: proxySchema,
|
|
547
|
+
localAddress: localAddressSchema
|
|
548
|
+
})
|
|
549
|
+
.allow(null)
|
|
550
|
+
.label('SubmitDraft')
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
response: {
|
|
554
|
+
schema: Joi.object({
|
|
555
|
+
response: Joi.string().example('Queued for delivery'),
|
|
556
|
+
messageId: Joi.string().example('<a2184d08-a470-fec6-a493-fa211a3756e9@example.com>').description('Message-ID header value'),
|
|
557
|
+
queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for scheduled email'),
|
|
558
|
+
sendAt: Joi.date().example('2021-07-08T07:06:34.336Z').description('Scheduled send time'),
|
|
559
|
+
|
|
560
|
+
idempotency: idempotencyResponseSchema
|
|
561
|
+
}).label('SubmitDraftResponse'),
|
|
562
|
+
failAction: 'log'
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
});
|
|
459
566
|
}
|
|
460
567
|
|
|
461
568
|
module.exports = init;
|
package/lib/consts.js
CHANGED
|
@@ -200,6 +200,12 @@ module.exports = {
|
|
|
200
200
|
|
|
201
201
|
NONCE_BYTES: 16,
|
|
202
202
|
|
|
203
|
+
// Class names on the collapse marker web-safe HTML wraps quoted thread history in. Part of the
|
|
204
|
+
// output contract - consumers select on them to style or hide the block - so they are defined
|
|
205
|
+
// once here and referenced by both the generator (lib/web-safe-html.js) and the API docs.
|
|
206
|
+
COLLAPSE_CLASS: 'ee-collapsed-thread',
|
|
207
|
+
COLLAPSE_TOGGLE_CLASS: 'ee-collapsed-thread-toggle',
|
|
208
|
+
|
|
203
209
|
// We are using a legacy hash function in caching operations
|
|
204
210
|
// This is not insecure but it pops out in security scanners, so we need to mask the name of the hash
|
|
205
211
|
MAILBOX_HASH: Buffer.from('c2hhMQ', 'base64url').toString(),
|
package/lib/db.js
CHANGED
|
@@ -54,7 +54,10 @@ const REDIS_CONF = Object.assign(
|
|
|
54
54
|
return delay;
|
|
55
55
|
},
|
|
56
56
|
reconnectOnError(err) {
|
|
57
|
-
|
|
57
|
+
// Not fatal: this fires on every transient connection error and we always reconnect,
|
|
58
|
+
// so logging it at fatal turned an ordinary Redis failover into a burst of top
|
|
59
|
+
// severity alerts. The retryStrategy above reports the actual retry cadence.
|
|
60
|
+
logger.warn({ msg: 'Redis connection error', isMainThread, threadId, err });
|
|
58
61
|
// always try to reconnect
|
|
59
62
|
return true;
|
|
60
63
|
},
|