emailengine-app 2.86.0 → 2.87.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +23 -0
- package/DOCKER_DEPLOYMENT.md +2 -1
- package/Dockerfile +2 -2
- package/README.md +4 -0
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +2 -2
- package/lib/account.js +92 -31
- package/lib/api-routes/account-routes.js +14 -7
- package/lib/api-routes/submit-routes.js +21 -2
- package/lib/email-client/base-client.js +4 -2
- package/lib/email-client/gmail-client.js +8 -0
- package/lib/email-client/imap/mailbox.js +8 -1
- package/lib/email-client/outlook-client.js +6 -0
- package/lib/field-usage.js +1 -1
- package/lib/get-raw-email.js +10 -1
- package/lib/oauth/gmail.js +54 -29
- package/lib/otp.js +66 -0
- package/lib/schemas.js +62 -2
- package/lib/swagger-options.js +2 -2
- package/lib/webhooks.js +5 -0
- package/package.json +16 -15
- package/sbom.json +466 -466
- package/static/css/flyonui.css +1 -1
- package/static/js/ee-client.js +650 -196
- package/static/licenses.html +38 -38
- package/translations/messages.pot +5 -5
- package/views/layout/app.hbs +9 -6
- package/views/legal.hbs +8 -0
- package/workers/api.js +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.87.0](https://github.com/postalsys/emailengine/compare/v2.86.0...v2.87.0) (2026-10-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* send and read one-time passcodes through the OTP-Token header ([ad2f388](https://github.com/postalsys/emailengine/commit/ad2f388e7fb5532bbd581f5c37c0f5c65525cc96))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* bump bullmq to 6.5.0 and @sentry/node-core to 10.77.1 ([250ec90](https://github.com/postalsys/emailengine/commit/250ec9060e1c392977961f6617e884071e426f86))
|
|
14
|
+
* bump nodemailer to 10.3.0, mailparser to 3.13.0 and other dependencies ([ad88bc7](https://github.com/postalsys/emailengine/commit/ad88bc79f5f1c4958ffb3012b09ce7f7f533824b))
|
|
15
|
+
* let the AI summary trust Google's authentication header on Gmail API accounts ([78038c5](https://github.com/postalsys/emailengine/commit/78038c5d7828050fd1c94af8d268e7c50081d8df))
|
|
16
|
+
* move the Docker image to Node 24.22.2 for the Brotli decoder fix (CVE-2026-111497) ([b6efd8e](https://github.com/postalsys/emailengine/commit/b6efd8e4dc81199cf427185c17e0ffb0933f08be))
|
|
17
|
+
* point support links at emailengine.app/support and support@postalsys.com ([795b217](https://github.com/postalsys/emailengine/commit/795b217458cf379699f68e333935ae8066310c1b))
|
|
18
|
+
* report the OAuth2 revocation outcome on account delete, and add revoke=required ([cc5908d](https://github.com/postalsys/emailengine/commit/cc5908de9e286ade29e1ad50a835d81f144c827c))
|
|
19
|
+
* separate the admin footer links into a labelled link list ([65aa96d](https://github.com/postalsys/emailengine/commit/65aa96d1b4ca540b670ae5c11ca441afa09b67e7))
|
|
20
|
+
* update @postalsys/certs to 2.0.3 and smtp-server to 3.21.2 ([d4a1946](https://github.com/postalsys/emailengine/commit/d4a194607a083a47fcc7b9ca772fa52c5d0b67d6))
|
|
21
|
+
* update bullmq to 6.4.2 ([4af5825](https://github.com/postalsys/emailengine/commit/4af582514507306dd7b677ad7d3ca4fe3f557e1c))
|
|
22
|
+
* update ee-client to 1.10.0 ([6595d46](https://github.com/postalsys/emailengine/commit/6595d46f23dd7cfd7e388641f763d1310c6a3883))
|
|
23
|
+
* update imapflow to 2.10.0 ([06928a5](https://github.com/postalsys/emailengine/commit/06928a507fb52696ecae1204e0641a24b43f9359))
|
|
24
|
+
* update nodemailer to 10.3.1, mailparser to 3.14.1, ee-client to 1.9.0 and email-ai-tools to 2.4.0 ([8aeafb4](https://github.com/postalsys/emailengine/commit/8aeafb498f663fc749e13da7f1f497a7d577b9ba))
|
|
25
|
+
|
|
3
26
|
## [2.86.0](https://github.com/postalsys/emailengine/compare/v2.85.0...v2.86.0) (2026-10-22)
|
|
4
27
|
|
|
5
28
|
|
package/DOCKER_DEPLOYMENT.md
CHANGED
|
@@ -492,6 +492,7 @@ docker-compose restart
|
|
|
492
492
|
|
|
493
493
|
## Support
|
|
494
494
|
|
|
495
|
+
- Support: https://emailengine.app/support or support@postalsys.com
|
|
495
496
|
- Documentation: https://learn.emailengine.app/
|
|
496
497
|
- API Reference: https://learn.emailengine.app/docs/api/emailengine-api
|
|
497
|
-
-
|
|
498
|
+
- Bug reports: https://github.com/postalsys/emailengine/issues
|
package/Dockerfile
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# here; the runtime stage below copies out only the finished tree, so npm and its dependencies never
|
|
12
12
|
# reach the published image. npm accounted for 38 of the 59 HIGH/CRITICAL findings in the old image
|
|
13
13
|
# (a vendored tar, pacote, sigstore, minimatch) and nothing at runtime ever invokes it.
|
|
14
|
-
FROM node:24-alpine@sha256:
|
|
14
|
+
FROM node:24-alpine@sha256:8a32c8cf649a49915a66e81e7a609223c708d0adabf288ee3f4077d765542f85 AS builder
|
|
15
15
|
|
|
16
16
|
ARG BUILDPLATFORM
|
|
17
17
|
ARG TARGETPLATFORM
|
|
@@ -74,7 +74,7 @@ RUN : "${EE_COMMIT_HASH:?EE_COMMIT_HASH build arg is required, e.g. --build-arg
|
|
|
74
74
|
&& rm -f update-info.sh
|
|
75
75
|
|
|
76
76
|
# Runtime stage.
|
|
77
|
-
FROM node:24-alpine@sha256:
|
|
77
|
+
FROM node:24-alpine@sha256:8a32c8cf649a49915a66e81e7a609223c708d0adabf288ee3f4077d765542f85
|
|
78
78
|
|
|
79
79
|
# `apk upgrade` patches the Alpine packages that the base image itself lags on - at the time of
|
|
80
80
|
# writing node:24-alpine still carries an openssl below 3.5.8-r0. dumb-init reaps zombies as PID 1.
|
package/README.md
CHANGED
|
@@ -169,6 +169,10 @@ To log raw IMAP traffic for every account instead, start EmailEngine with `--log
|
|
|
169
169
|
|
|
170
170
|
For detailed security and data compliance information, refer to [this guide](https://learn.emailengine.app/docs/deployment/compliance).
|
|
171
171
|
|
|
172
|
+
## Support
|
|
173
|
+
|
|
174
|
+
See [emailengine.app/support](https://emailengine.app/support) for support options, or email [support@postalsys.com](mailto:support@postalsys.com). GitHub issues are for reproducible bugs only and are not actively monitored.
|
|
175
|
+
|
|
172
176
|
## Licensing
|
|
173
177
|
|
|
174
178
|
EmailEngine is licensed under the commercial [EmailEngine License](./LICENSE_EMAILENGINE.txt).
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Please pull this list from, and only from https://publicsuffix.org/list/public_suffix_list.dat,
|
|
6
6
|
// rather than any other VCS sites. Pulling from any other URL is not guaranteed to be supported.
|
|
7
7
|
|
|
8
|
-
// VERSION: 2026-10-
|
|
9
|
-
// COMMIT:
|
|
8
|
+
// VERSION: 2026-10-28_13-15-55_UTC
|
|
9
|
+
// COMMIT: 9dfbe81931367b3f0af21035c36ae7eeb830dd88
|
|
10
10
|
|
|
11
11
|
// Instructions on pulling and using this list can be found at https://publicsuffix.org/list/.
|
|
12
12
|
|
package/lib/account.js
CHANGED
|
@@ -54,6 +54,25 @@ const ACCOUNT_UPDATE_LOCK_WAIT = 5 * 1000;
|
|
|
54
54
|
// re-encrypts exactly this list.
|
|
55
55
|
const ENCRYPTED_ACCOUNT_FIELDS = ['webhooks', 'webhooksCustomHeaders', 'proxy'];
|
|
56
56
|
|
|
57
|
+
// Revocation outcomes that leave no grant EmailEngine could revoke, so revoke: 'required' lets the
|
|
58
|
+
// deletion go ahead: not an OAuth2 account, a Workspace service account, or a token the provider
|
|
59
|
+
// already considers revoked or expired
|
|
60
|
+
const NO_GRANT_REASONS = new Set(['NotOAuth2', 'ServiceAccount', 'TokenInvalid']);
|
|
61
|
+
|
|
62
|
+
function grantRemains(revocation) {
|
|
63
|
+
return !revocation.revoked && !NO_GRANT_REASONS.has(revocation.reason);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The error a deletion with revoke: 'required' fails with. 502 when the provider was asked and did
|
|
67
|
+
// not confirm, which a retry can fix; 409 when there was nothing it could be asked with
|
|
68
|
+
function revocationNotConfirmed(revocation) {
|
|
69
|
+
let err = new Error('The OAuth2 grant was not revoked, so the account was not deleted');
|
|
70
|
+
err.code = 'RevocationNotConfirmed';
|
|
71
|
+
err.statusCode = revocation.attempted ? 502 : 409;
|
|
72
|
+
err.info = { revocation };
|
|
73
|
+
return err;
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
/**
|
|
58
77
|
* The encrypted credential fields of an unserialized account, as [holder, key] pairs: a credential
|
|
59
78
|
* is under `auth` when the configuration has one, otherwise on the configuration itself
|
|
@@ -1703,32 +1722,33 @@ class Account {
|
|
|
1703
1722
|
|
|
1704
1723
|
let accountData = await this.loadAccountData(this.account);
|
|
1705
1724
|
|
|
1725
|
+
// revoke: 'required' keeps the account unless the grant is gone. A grant that cannot even be
|
|
1726
|
+
// attempted is refused before anything is torn down
|
|
1727
|
+
let required = opts.revoke === 'required';
|
|
1728
|
+
let grant = opts.revoke ? await this.findRevocableGrant(accountData) : null;
|
|
1729
|
+
let revocation = grant?.reason ? { attempted: false, revoked: false, reason: grant.reason } : undefined;
|
|
1730
|
+
if (required && revocation && grantRemains(revocation)) {
|
|
1731
|
+
throw revocationNotConfirmed(revocation);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1706
1734
|
// First, while the record and its token still exist: the worker's own teardown after the
|
|
1707
1735
|
// unlink below has no token left, so the Graph subscription and the Gmail watch used to
|
|
1708
1736
|
// outlive the account. Ahead of the revoke for the same reason
|
|
1709
1737
|
await this.releaseRemoteResources();
|
|
1710
1738
|
|
|
1711
|
-
if (
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
});
|
|
1725
|
-
if (oauthClient && typeof oauthClient.revokeToken === 'function') {
|
|
1726
|
-
await oauthClient.revokeToken(token);
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
} catch (err) {
|
|
1730
|
-
this.logger.warn({ msg: 'Failed to revoke OAuth2 grant before account delete', account: this.account, err });
|
|
1731
|
-
}
|
|
1739
|
+
if (grant) {
|
|
1740
|
+
if (!revocation) {
|
|
1741
|
+
revocation = Object.assign({ attempted: true }, await grant.client.revokeToken(grant.token));
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
this.logger[revocation.revoked ? 'info' : 'warn']({ msg: 'OAuth2 grant revocation before account delete', account: this.account, revocation });
|
|
1745
|
+
|
|
1746
|
+
if (required && grantRemains(revocation)) {
|
|
1747
|
+
// The teardown above stopped the Gmail watch of an account that now stays. A
|
|
1748
|
+
// reconnect sets it up again; not awaited, the refusal does not depend on it and
|
|
1749
|
+
// notifyWorker() logs its own failure
|
|
1750
|
+
this.notifyWorker('reconnect');
|
|
1751
|
+
throw revocationNotConfirmed(revocation);
|
|
1732
1752
|
}
|
|
1733
1753
|
}
|
|
1734
1754
|
|
|
@@ -1801,19 +1821,60 @@ class Account {
|
|
|
1801
1821
|
this.logger.error({ msg: 'Failed to delete the log keys of a deleted account', account: this.account, err });
|
|
1802
1822
|
}
|
|
1803
1823
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
deleted: false
|
|
1808
|
-
};
|
|
1824
|
+
let deleted = !!(result && result[1] && result[1][1]);
|
|
1825
|
+
if (deleted) {
|
|
1826
|
+
await this.notifyWorker('delete');
|
|
1809
1827
|
}
|
|
1810
1828
|
|
|
1811
|
-
|
|
1829
|
+
let response = { account: this.account, deleted };
|
|
1830
|
+
if (revocation) {
|
|
1831
|
+
// Only when revoke was requested, so a plain delete answers exactly as it always has
|
|
1832
|
+
response.revocation = revocation;
|
|
1833
|
+
}
|
|
1834
|
+
return response;
|
|
1835
|
+
}
|
|
1812
1836
|
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1837
|
+
/**
|
|
1838
|
+
* Finds the grant a deletion with `revoke` should revoke.
|
|
1839
|
+
*
|
|
1840
|
+
* @returns {Promise<{client: Object, token: string}|{reason: string}>} The client and token to
|
|
1841
|
+
* revoke with, or the reason there is nothing EmailEngine can revoke
|
|
1842
|
+
*/
|
|
1843
|
+
async findRevocableGrant(accountData) {
|
|
1844
|
+
if (!accountData.oauth2?.provider) {
|
|
1845
|
+
return { reason: 'NotOAuth2' };
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// Prefer refresh token over access token: revoking either invalidates the grant per Google's docs,
|
|
1849
|
+
// but the stored access token may be expired (a 400 from the provider would leave the grant intact),
|
|
1850
|
+
// while the refresh token is long-lived.
|
|
1851
|
+
let token = accountData.oauth2.refreshToken || accountData.oauth2.accessToken;
|
|
1852
|
+
if (!token) {
|
|
1853
|
+
return { reason: 'NoToken' };
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
try {
|
|
1857
|
+
let oauth2App = await oauth2Apps.get(accountData.oauth2.provider);
|
|
1858
|
+
if (!oauth2App) {
|
|
1859
|
+
return { reason: 'AppNotFound' };
|
|
1860
|
+
}
|
|
1861
|
+
// Workspace service accounts have no per-user grant to revoke
|
|
1862
|
+
if (oauth2App.provider === 'gmailService') {
|
|
1863
|
+
return { reason: 'ServiceAccount' };
|
|
1864
|
+
}
|
|
1865
|
+
let client = await oauth2Apps.getClient(accountData.oauth2.provider, {
|
|
1866
|
+
logger: this.logger,
|
|
1867
|
+
route: await this.getHttpRoute(accountData)
|
|
1868
|
+
});
|
|
1869
|
+
// Only GmailOauth implements it. Microsoft offers no endpoint that revokes one grant
|
|
1870
|
+
if (typeof client?.revokeToken !== 'function') {
|
|
1871
|
+
return { reason: 'Unsupported' };
|
|
1872
|
+
}
|
|
1873
|
+
return { client, token };
|
|
1874
|
+
} catch (err) {
|
|
1875
|
+
this.logger.warn({ msg: 'Failed to load the OAuth2 application to revoke a grant', account: this.account, err });
|
|
1876
|
+
return { reason: 'AppError' };
|
|
1877
|
+
}
|
|
1817
1878
|
}
|
|
1818
1879
|
|
|
1819
1880
|
// Creates the consumer side of a cross-thread download stream, with a guard listener:
|
|
@@ -43,7 +43,8 @@ const {
|
|
|
43
43
|
apiBoolean,
|
|
44
44
|
mailboxAddressSchema,
|
|
45
45
|
accountProxySchema,
|
|
46
|
-
verifyResultSchema
|
|
46
|
+
verifyResultSchema,
|
|
47
|
+
accountRevocationSchema
|
|
47
48
|
} = require('../schemas');
|
|
48
49
|
|
|
49
50
|
const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES, MCP_MAX_PAGE_SIZE, OUTLOOK_SYNC_MAX_LOOKBACK } = require('../consts');
|
|
@@ -850,7 +851,9 @@ function registerDeleteAccount(server, args) {
|
|
|
850
851
|
account: request.params.account,
|
|
851
852
|
call,
|
|
852
853
|
secret: await getSecret(),
|
|
853
|
-
timeout: request.headers['x-ee-timeout']
|
|
854
|
+
timeout: request.headers['x-ee-timeout'],
|
|
855
|
+
// The revocation outcome is logged with this request's id and token
|
|
856
|
+
logger: request.logger
|
|
854
857
|
});
|
|
855
858
|
|
|
856
859
|
try {
|
|
@@ -862,7 +865,7 @@ function registerDeleteAccount(server, args) {
|
|
|
862
865
|
options: {
|
|
863
866
|
description: 'Remove account',
|
|
864
867
|
notes: [
|
|
865
|
-
"Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed.",
|
|
868
|
+
"Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed; the response then reports the outcome under `revocation`. Pass revoke=required to delete the account only when the grant is gone: when the provider does not confirm the revocation the request fails with code RevocationNotConfirmed (502 when the provider was asked, 409 when it could not be) and the account and its credentials are kept, so the request can be retried.",
|
|
866
869
|
BEHAVIOR.DELETION_SCOPE
|
|
867
870
|
],
|
|
868
871
|
|
|
@@ -873,7 +876,7 @@ function registerDeleteAccount(server, args) {
|
|
|
873
876
|
name: 'delete_account',
|
|
874
877
|
title: 'Delete account',
|
|
875
878
|
description:
|
|
876
|
-
'Remove an account from this instance, with its synced index and the tokens bound to it. The mailbox at the provider is untouched. Set revoke to true to also revoke the OAuth2 grant at the provider. Confirm with the user before calling this.'
|
|
879
|
+
'Remove an account from this instance, with its synced index and the tokens bound to it. The mailbox at the provider is untouched. Set revoke to true to also revoke the OAuth2 grant at the provider, or to "required" to keep the account unless the provider confirms the revocation. Confirm with the user before calling this.'
|
|
877
880
|
},
|
|
878
881
|
openapi: {
|
|
879
882
|
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
@@ -909,9 +912,12 @@ function registerDeleteAccount(server, args) {
|
|
|
909
912
|
}),
|
|
910
913
|
|
|
911
914
|
query: Joi.object({
|
|
912
|
-
revoke:
|
|
915
|
+
revoke: Joi.alternatives()
|
|
916
|
+
.try(apiBoolean(), Joi.string().valid('required'))
|
|
913
917
|
.default(false)
|
|
914
|
-
.description(
|
|
918
|
+
.description(
|
|
919
|
+
'Revoke the upstream OAuth2 grant at the provider before deleting the account. `true` deletes the account whatever the outcome, `required` keeps it unless the grant is gone'
|
|
920
|
+
)
|
|
915
921
|
.meta({ usage: FIELD_USAGE.revokeGrant })
|
|
916
922
|
})
|
|
917
923
|
},
|
|
@@ -919,7 +925,8 @@ function registerDeleteAccount(server, args) {
|
|
|
919
925
|
response: {
|
|
920
926
|
schema: Joi.object({
|
|
921
927
|
account: accountIdSchema.required(),
|
|
922
|
-
deleted: apiBoolean().default(true).description('Was the account deleted')
|
|
928
|
+
deleted: apiBoolean().default(true).description('Was the account deleted'),
|
|
929
|
+
revocation: accountRevocationSchema
|
|
923
930
|
}).label('DeleteAccountResponse'),
|
|
924
931
|
failAction: 'log'
|
|
925
932
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Joi = require('joi');
|
|
4
|
+
const Boom = require('@hapi/boom');
|
|
4
5
|
const { redis } = require('../db');
|
|
5
6
|
const { Account } = require('../account');
|
|
6
7
|
const getSecret = require('../get-secret');
|
|
@@ -27,7 +28,8 @@ const {
|
|
|
27
28
|
apiResponses,
|
|
28
29
|
ENUM_DESCRIPTIONS,
|
|
29
30
|
MAX_MESSAGE_ATTACHMENTS,
|
|
30
|
-
apiBoolean
|
|
31
|
+
apiBoolean,
|
|
32
|
+
submitOtpSchema
|
|
31
33
|
} = require('../schemas');
|
|
32
34
|
|
|
33
35
|
// Schema fragments shared between the message submit and the draft submit routes. Joi schemas
|
|
@@ -96,6 +98,18 @@ const idempotencyResponseSchema = Joi.object({
|
|
|
96
98
|
.description('Idempotency info, present when an Idempotency-Key header was used')
|
|
97
99
|
.label('ResponseIdempotency');
|
|
98
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Refuses an otp with useStructuredFormat, whose JSON Graph send would drop the OTP-Token header
|
|
103
|
+
*
|
|
104
|
+
* @param {Object} request - the Hapi request
|
|
105
|
+
*/
|
|
106
|
+
function assertOtpFormat(request) {
|
|
107
|
+
const payload = request.payload || {};
|
|
108
|
+
if (request.query.useStructuredFormat && (payload.otp || (payload.mailMerge || []).some(entry => entry && entry.otp))) {
|
|
109
|
+
throw Boom.badRequest('A one-time passcode (otp) can not be sent with useStructuredFormat');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
99
113
|
function buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE) {
|
|
100
114
|
return Joi.object({
|
|
101
115
|
reference: messageReferenceSchema,
|
|
@@ -203,7 +217,8 @@ function buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE) {
|
|
|
203
217
|
sendAt: Joi.date()
|
|
204
218
|
.iso()
|
|
205
219
|
.example('2021-07-08T07:06:34.336Z')
|
|
206
|
-
.description('Send message at specified time. Overrides message level `sendAt` value.')
|
|
220
|
+
.description('Send message at specified time. Overrides message level `sendAt` value.'),
|
|
221
|
+
otp: submitOtpSchema.description('One-time passcode for this recipient. Overrides message level `otp` value.').label('MailMergeOtp')
|
|
207
222
|
}).label('MailMergeListEntry')
|
|
208
223
|
)
|
|
209
224
|
.min(1)
|
|
@@ -252,6 +267,8 @@ function buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE) {
|
|
|
252
267
|
'X-My-Custom-Header': 'Custom header value'
|
|
253
268
|
}),
|
|
254
269
|
|
|
270
|
+
otp: submitOtpSchema,
|
|
271
|
+
|
|
255
272
|
trackingEnabled: Joi.boolean().example(false).description('Should EmailEngine track clicks and opens for this message').meta({ swaggerHidden: true }),
|
|
256
273
|
|
|
257
274
|
trackOpens: Joi.boolean().example(false).description('Should EmailEngine track opens for this message'),
|
|
@@ -418,6 +435,7 @@ function registerSubmitMessage(server, args) {
|
|
|
418
435
|
|
|
419
436
|
try {
|
|
420
437
|
assertNoNetworkOverride(request);
|
|
438
|
+
assertOtpFormat(request);
|
|
421
439
|
|
|
422
440
|
return await accountObject.queueMessage(request.payload, {
|
|
423
441
|
source: 'api',
|
|
@@ -710,3 +728,4 @@ async function init(args) {
|
|
|
710
728
|
}
|
|
711
729
|
|
|
712
730
|
module.exports = init;
|
|
731
|
+
module.exports.assertOtpFormat = assertOtpFormat;
|
|
@@ -26,6 +26,7 @@ const { bounceDetect, applyDeliveryReport, PARSER_OPTIONS: DSN_PARSER_OPTIONS }
|
|
|
26
26
|
const { collectCalendarEvents } = require('../calendar-event');
|
|
27
27
|
const { llmPreProcess, summaryFetchHeaders, summaryProvider } = require('../llm-pre-process');
|
|
28
28
|
const { notificationHeaderFields, narrowHeaders } = require('../utils/header-map');
|
|
29
|
+
const { notifyHeadersIncludeOtp, OTP_FETCH_HEADERS } = require('../otp');
|
|
29
30
|
const { mapConcurrent } = require('../utils/map-concurrent');
|
|
30
31
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
31
32
|
const { Account } = require('../account');
|
|
@@ -1836,7 +1837,7 @@ class BaseClient {
|
|
|
1836
1837
|
messageCopy.to = [mailMergeEntry.to];
|
|
1837
1838
|
|
|
1838
1839
|
// Apply recipient-specific overrides
|
|
1839
|
-
for (let key of ['messageId', 'sendAt']) {
|
|
1840
|
+
for (let key of ['messageId', 'sendAt', 'otp']) {
|
|
1840
1841
|
if (mailMergeEntry[key]) {
|
|
1841
1842
|
messageCopy[key] = mailMergeEntry[key];
|
|
1842
1843
|
}
|
|
@@ -3012,7 +3013,8 @@ class BaseClient {
|
|
|
3012
3013
|
// while summaries are on. Skipped when the setting already asks for every header
|
|
3013
3014
|
if (messageFetchOptions.headers !== true) {
|
|
3014
3015
|
const summaryHeaders = (await llmPreProcess.getPreProcessHandler()) ? summaryFetchHeaders(this.summaryProvider()) : [];
|
|
3015
|
-
|
|
3016
|
+
const otpHeaders = notifyHeadersIncludeOtp(notifyHeaders) ? OTP_FETCH_HEADERS : [];
|
|
3017
|
+
messageFetchOptions.fetchHeaders = notificationHeaderFields(messageFetchOptions.headers, summaryHeaders.concat(otpHeaders));
|
|
3016
3018
|
}
|
|
3017
3019
|
|
|
3018
3020
|
return messageFetchOptions;
|
|
@@ -40,6 +40,7 @@ function isGmailNotFound(err) {
|
|
|
40
40
|
}
|
|
41
41
|
const { buildSendRequest, buildDraftSendRequest } = require('./gmail/send-request');
|
|
42
42
|
const { pushHeaderValue } = require('../utils/header-map');
|
|
43
|
+
const { getMessageOtp } = require('../otp');
|
|
43
44
|
|
|
44
45
|
const MAX_GMAIL_BATCH_SIZE = 50;
|
|
45
46
|
|
|
@@ -285,6 +286,8 @@ class PageCursor {
|
|
|
285
286
|
class GmailClient extends BaseClient {
|
|
286
287
|
constructor(account, options) {
|
|
287
288
|
super(account, options);
|
|
289
|
+
// what the AI summary's and the OTP-Token's authentication trust rule key on, see summaryProvider()
|
|
290
|
+
this.type = 'gmail';
|
|
288
291
|
|
|
289
292
|
// A failed init() is scheduled again by the worker, see BaseClient.scheduleInitRetry()
|
|
290
293
|
this.retriesInit = true;
|
|
@@ -2733,6 +2736,11 @@ class GmailClient extends BaseClient {
|
|
|
2733
2736
|
result.isAutoReply = true;
|
|
2734
2737
|
}
|
|
2735
2738
|
|
|
2739
|
+
const otp = getMessageOtp(result.headers, this.summaryProvider());
|
|
2740
|
+
if (otp) {
|
|
2741
|
+
result.otp = otp;
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2736
2744
|
// Set special-use based on labels
|
|
2737
2745
|
for (let specialUseTag of ['\\Junk', '\\Sent', '\\Trash', '\\Inbox', '\\Drafts']) {
|
|
2738
2746
|
if (result.labels && result.labels.includes(specialUseTag)) {
|
|
@@ -30,6 +30,7 @@ const { collectCalendarEvents } = require('../../calendar-event');
|
|
|
30
30
|
const { parseAddressHeader: parseMailboxes } = require('mailparser');
|
|
31
31
|
const { llmPreProcess, summaryFetchHeaders, summaryProvider } = require('../../llm-pre-process');
|
|
32
32
|
const { notificationHeaderFields, narrowHeaders } = require('../../utils/header-map');
|
|
33
|
+
const { getMessageOtp, notifyHeadersIncludeOtp, OTP_FETCH_HEADERS } = require('../../otp');
|
|
33
34
|
const { isFailedDelivery } = require('../base-client');
|
|
34
35
|
|
|
35
36
|
const {
|
|
@@ -2010,6 +2011,11 @@ class Mailbox {
|
|
|
2010
2011
|
result.isAutoReply = true;
|
|
2011
2012
|
}
|
|
2012
2013
|
|
|
2014
|
+
const otp = extended && getMessageOtp(headers, summaryProvider(this.connection));
|
|
2015
|
+
if (otp) {
|
|
2016
|
+
result.otp = otp;
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2013
2019
|
return result;
|
|
2014
2020
|
}
|
|
2015
2021
|
|
|
@@ -2232,7 +2238,8 @@ class Mailbox {
|
|
|
2232
2238
|
(this.isAllMail || this.listingEntry.specialUse === '\\Inbox') && (await llmPreProcess.getPreProcessHandler())
|
|
2233
2239
|
? summaryFetchHeaders(summaryProvider(this.connection))
|
|
2234
2240
|
: [];
|
|
2235
|
-
|
|
2241
|
+
const otpHeaders = notifyHeadersIncludeOtp(notifyHeaders) ? OTP_FETCH_HEADERS : [];
|
|
2242
|
+
messageFetchOptions.fetchHeaders = notificationHeaderFields(messageFetchOptions.headers, summaryHeaders.concat(otpHeaders));
|
|
2236
2243
|
}
|
|
2237
2244
|
|
|
2238
2245
|
// Gmail categories of the messages this pass announces, looked up together
|
|
@@ -22,6 +22,7 @@ const { detectMimeType, detectExtension } = require('nodemailer/lib/mime-funcs/m
|
|
|
22
22
|
const graphApi = require('./outlook/graph-api');
|
|
23
23
|
const { buildRawSendMailRequest, buildStructuredSendMailRequest, buildDraftSendRequest } = require('./outlook/send-request');
|
|
24
24
|
const { pushHeaderValue } = require('../utils/header-map');
|
|
25
|
+
const { getMessageOtp } = require('../otp');
|
|
25
26
|
|
|
26
27
|
const {
|
|
27
28
|
REDIS_PREFIX,
|
|
@@ -4119,6 +4120,11 @@ class OutlookClient extends BaseClient {
|
|
|
4119
4120
|
message.isAutoReply = true;
|
|
4120
4121
|
}
|
|
4121
4122
|
|
|
4123
|
+
const otp = getMessageOtp(message.headers, this.summaryProvider());
|
|
4124
|
+
if (otp) {
|
|
4125
|
+
message.otp = otp;
|
|
4126
|
+
}
|
|
4127
|
+
|
|
4122
4128
|
// Process attachments
|
|
4123
4129
|
if (messageData.attachments?.length) {
|
|
4124
4130
|
let cidReferences = collectCidReferences(message.text.html);
|
package/lib/field-usage.js
CHANGED
|
@@ -122,7 +122,7 @@ const FIELD_USAGE = {
|
|
|
122
122
|
|
|
123
123
|
revokeGrant:
|
|
124
124
|
'Set this when deleting an account should also cut EmailEngine off at the provider, for example because a user asked for their data to be disconnected rather than just removed here.\n\n' +
|
|
125
|
-
'It currently works for individual Gmail OAuth2 grants. Gmail Workspace service-account integrations, Outlook and non-OAuth2 accounts ignore it.
|
|
125
|
+
'It currently works for individual Gmail OAuth2 grants. Gmail Workspace service-account integrations, Outlook and non-OAuth2 accounts ignore it. The response reports the outcome under `revocation`. With `true` a failed revocation never blocks the deletion; use `required` when the account must stay until the grant is gone, so a failure can be retried without reading the token out of EmailEngine.',
|
|
126
126
|
|
|
127
127
|
webSafeHtml:
|
|
128
128
|
'Turn this on when you are rendering the message in your own UI and want EmailEngine to do the sanitising. It is a shorthand that overrides `textType`, `preProcessHtml` and `embedAttachedImages`.\n\n' +
|
package/lib/get-raw-email.js
CHANGED
|
@@ -401,7 +401,16 @@ async function getRawEmail(data, licenseInfo, options) {
|
|
|
401
401
|
|
|
402
402
|
const mail = new MailComposer(mailComposerOptions);
|
|
403
403
|
|
|
404
|
-
|
|
404
|
+
let compiled;
|
|
405
|
+
try {
|
|
406
|
+
compiled = mail.compile();
|
|
407
|
+
} catch (err) {
|
|
408
|
+
// an otp value the schema let through but the OTP-Token header can not carry
|
|
409
|
+
if (err.code === 'EOTP') {
|
|
410
|
+
err.statusCode = 400;
|
|
411
|
+
}
|
|
412
|
+
throw err;
|
|
413
|
+
}
|
|
405
414
|
// do not strip Bcc header from the message (will be removed later)
|
|
406
415
|
compiled.keepBcc = true;
|
|
407
416
|
|
package/lib/oauth/gmail.js
CHANGED
|
@@ -877,6 +877,14 @@ class GmailOauth {
|
|
|
877
877
|
};
|
|
878
878
|
}
|
|
879
879
|
|
|
880
|
+
/**
|
|
881
|
+
* Asks Google to revoke a grant. Never throws: the outcome is returned for the caller to act on.
|
|
882
|
+
*
|
|
883
|
+
* @param {string} token Refresh or access token of the grant
|
|
884
|
+
* @returns {Promise<{revoked: boolean, status?: number, reason?: string, error?: string}>}
|
|
885
|
+
* `reason` is TokenInvalid when Google no longer knows the token (already revoked or expired),
|
|
886
|
+
* ProviderRefused for any other refusal and RequestFailed when no answer arrived
|
|
887
|
+
*/
|
|
880
888
|
async revokeToken(token) {
|
|
881
889
|
const fetchOpts = {
|
|
882
890
|
method: 'post',
|
|
@@ -887,41 +895,58 @@ class GmailOauth {
|
|
|
887
895
|
body: new URLSearchParams({ token }).toString()
|
|
888
896
|
};
|
|
889
897
|
|
|
898
|
+
let res;
|
|
890
899
|
try {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
let responseText;
|
|
894
|
-
try {
|
|
895
|
-
responseText = await res.text();
|
|
896
|
-
} catch (err) {
|
|
897
|
-
// ignore
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
if (this.logger) {
|
|
901
|
-
this.logger.info({
|
|
902
|
-
msg: 'OAuth2 token revocation request',
|
|
903
|
-
action: 'oauth2Fetch',
|
|
904
|
-
fn: 'revokeToken',
|
|
905
|
-
url: this.revokeUrl,
|
|
906
|
-
success: !!res.ok,
|
|
907
|
-
status: res.status
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
if (!res.ok) {
|
|
912
|
-
if (this.logger) {
|
|
913
|
-
this.logger.warn({
|
|
914
|
-
msg: 'OAuth2 token revocation failed',
|
|
915
|
-
status: res.status,
|
|
916
|
-
response: responseText
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
}
|
|
900
|
+
res = await fetchCmd(this.revokeUrl, Object.assign(fetchOpts, { dispatcher: httpAgent.forRoute(this.route).retry }));
|
|
920
901
|
} catch (err) {
|
|
921
902
|
if (this.logger) {
|
|
922
903
|
this.logger.warn({ msg: 'OAuth2 token revocation error', err });
|
|
923
904
|
}
|
|
905
|
+
// The low-level code (ECONNREFUSED, UND_ERR_CONNECT_TIMEOUT) says more than fetch's own "fetch failed"
|
|
906
|
+
return { revoked: false, reason: 'RequestFailed', error: err.cause?.code || err.code || err.message };
|
|
924
907
|
}
|
|
908
|
+
|
|
909
|
+
let responseText;
|
|
910
|
+
try {
|
|
911
|
+
responseText = await res.text();
|
|
912
|
+
} catch (err) {
|
|
913
|
+
// ignore
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (this.logger) {
|
|
917
|
+
this.logger.info({
|
|
918
|
+
msg: 'OAuth2 token revocation request',
|
|
919
|
+
action: 'oauth2Fetch',
|
|
920
|
+
fn: 'revokeToken',
|
|
921
|
+
url: this.revokeUrl,
|
|
922
|
+
success: !!res.ok,
|
|
923
|
+
status: res.status
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (res.ok) {
|
|
928
|
+
return { revoked: true, status: res.status };
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (this.logger) {
|
|
932
|
+
this.logger.warn({
|
|
933
|
+
msg: 'OAuth2 token revocation failed',
|
|
934
|
+
status: res.status,
|
|
935
|
+
response: responseText
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// Only the OAuth2 error code, never the response body: it is the part a caller can act on
|
|
940
|
+
let error;
|
|
941
|
+
try {
|
|
942
|
+
error = JSON.parse(responseText).error;
|
|
943
|
+
} catch (err) {
|
|
944
|
+
// not a JSON error response
|
|
945
|
+
}
|
|
946
|
+
return Object.assign(
|
|
947
|
+
{ revoked: false, status: res.status, reason: error === 'invalid_token' ? 'TokenInvalid' : 'ProviderRefused' },
|
|
948
|
+
typeof error === 'string' ? { error } : {}
|
|
949
|
+
);
|
|
925
950
|
}
|
|
926
951
|
}
|
|
927
952
|
|