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/lib/otp.js ADDED
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ // One-time passcodes from the OTP-Token header (draft-goto-otp-token), see "One-time passcodes"
4
+ // in CLAUDE.md. mailparser applies the draft's parsing rules; the header itself is not
5
+ // authenticated, so the code is reported together with whether the receiving server vouches for
6
+ // its origin.
7
+
8
+ const { parseOtpToken } = require('mailparser');
9
+ const { parseAuthenticationResults, isTrustedAuthservId } = require('@postalsys/email-ai-tools/lib/authentication.js');
10
+ const { authenticationTrust } = require('./llm-pre-process');
11
+ const { getRegistrableDomain } = require('./utils/public-suffix');
12
+
13
+ // What the fetch paths ask for besides the configured headers when messageNew carries otp: the
14
+ // header itself, and what authenticationTrust() reads (Received for a Microsoft mailbox)
15
+ const OTP_FETCH_HEADERS = ['otp-token', 'authentication-results', 'received'];
16
+
17
+ /**
18
+ * Tells whether the receiving server recorded a passing DKIM signature aligned with the origin:
19
+ * from the same organizational domain, the way DMARC's relaxed alignment compares domains. Only
20
+ * the topmost Authentication-Results header counts, written by a server authenticationTrust() names
21
+ *
22
+ * @param {string} origin - The origin the code is bound to, as parseOtpToken() returns it
23
+ * @param {Object} headers - The message headers, lower-case names to value lists
24
+ * @param {string|null} provider - As summaryProvider() names it
25
+ * @returns {boolean}
26
+ */
27
+ function isAuthenticatedOrigin(origin, headers, provider) {
28
+ const trust = authenticationTrust(provider, headers);
29
+ const parsed = parseAuthenticationResults([].concat(headers['authentication-results'] || [])[0]);
30
+ if (!parsed || !parsed.dkimDomains.length || !isTrustedAuthservId(parsed.authservId, trust.trustedAuthservIds, trust.acceptUnnamedAuthentication)) {
31
+ return false;
32
+ }
33
+
34
+ // an IP address, a loopback name or a public suffix has no organizational domain to match
35
+ const originDomain = getRegistrableDomain(new URL(origin).hostname);
36
+ return !!originDomain && parsed.dkimDomains.some(domain => getRegistrableDomain(domain) === originDomain);
37
+ }
38
+
39
+ /**
40
+ * The one-time passcode of a message, from its OTP-Token header
41
+ *
42
+ * @param {Object} [headers] - The message headers, lower-case names to value lists
43
+ * @param {string|null} provider - As summaryProvider() names it, decides which Authentication-Results header counts
44
+ * @returns {{code: string, origin: string, authenticated: boolean}|undefined}
45
+ */
46
+ function getMessageOtp(headers, provider) {
47
+ const otp = headers && headers['otp-token'] && parseOtpToken([].concat(headers['otp-token']));
48
+ if (!otp) {
49
+ return undefined;
50
+ }
51
+
52
+ return { code: otp.code, origin: otp.origin, authenticated: isAuthenticatedOrigin(otp.origin, headers, provider) };
53
+ }
54
+
55
+ /**
56
+ * Tells whether the notifyHeaders setting asks for the OTP-Token header, the only case the
57
+ * messageNew payload carries the otp field
58
+ *
59
+ * @param {string[]} [notifyHeaders] - The notifyHeaders setting
60
+ * @returns {boolean}
61
+ */
62
+ function notifyHeadersIncludeOtp(notifyHeaders) {
63
+ return [].concat(notifyHeaders || []).some(header => header === '*' || String(header).toLowerCase() === 'otp-token');
64
+ }
65
+
66
+ module.exports = { getMessageOtp, notifyHeadersIncludeOtp, OTP_FETCH_HEADERS };
package/lib/schemas.js CHANGED
@@ -213,7 +213,9 @@ const settingsSchema = {
213
213
 
214
214
  notifyHeaders: Joi.array()
215
215
  .items(Joi.string().max(256).example('List-ID').label('NotifyHeaderEntry'))
216
- .description('Email headers to include in webhook payloads for additional context')
216
+ .description(
217
+ 'Email headers to include in webhook payloads for additional context. Listing OTP-Token also adds the otp field (the one-time passcode) to messageNew payloads'
218
+ )
217
219
  .label('NotifyHeaders'),
218
220
 
219
221
  /* ────────────── URLs ────────────── */
@@ -698,7 +700,7 @@ const settingsSchema = {
698
700
  imapClientSupportUrl: Joi.string()
699
701
  .allow('')
700
702
  .uri({ scheme: ['http', 'https', 'mailto'], allowRelative: false })
701
- .example('https://github.com/postalsys/emailengine/issues')
703
+ .example('https://emailengine.app/support')
702
704
  .description('Support URL advertised via IMAP ID extension'),
703
705
 
704
706
  /* ────────────── Export ────────────── */
@@ -1299,6 +1301,42 @@ const messageEntrySchema = Joi.object({
1299
1301
  isAutoReply: Joi.boolean().example(false).description('Whether this message appears to be an automatic reply (out of office, vacation responder, etc.)')
1300
1302
  }).label('MessageListEntry');
1301
1303
 
1304
+ // One-time passcode of the OTP-Token header (draft-goto-otp-token). Experimental: the draft is a
1305
+ // work in progress, the field follows it
1306
+ const messageOtpSchema = Joi.object({
1307
+ code: Joi.string().example('123456').description('The passcode'),
1308
+ origin: Joi.string().example('https://example.com').description('The origin the passcode is bound to'),
1309
+ authenticated: Joi.boolean()
1310
+ .example(true)
1311
+ .description(
1312
+ "Whether the receiving server vouches for the origin: its Authentication-Results header records a passing DKIM signature from the origin's organizational domain. Only Gmail and Microsoft 365 mailboxes can report true, for other servers this is always false"
1313
+ )
1314
+ })
1315
+ .description(
1316
+ 'One-time passcode from the OTP-Token header (draft-goto-otp-token), present when the message carries exactly one valid header. Experimental, follows the Internet-Draft. The header is not authenticated by itself, so name the origin to a user only when authenticated is true'
1317
+ )
1318
+ .label('MessageOtp');
1319
+
1320
+ // Optional one-time passcode for the OTP-Token header of an outgoing message
1321
+ const submitOtpSchema = Joi.object({
1322
+ code: Joi.string()
1323
+ .pattern(/^[\x20-\x7e]+$/, 'printable ASCII')
1324
+ .max(256)
1325
+ .required()
1326
+ .example('123456')
1327
+ .description('The passcode, printable ASCII. It should also appear in the message body'),
1328
+ origin: Joi.string()
1329
+ .uri({ scheme: ['https', 'http'], allowRelative: false })
1330
+ .max(2048)
1331
+ .required()
1332
+ .example('https://example.com')
1333
+ .description('The site the passcode is for, https (or http on a loopback host). A full URL is reduced to its origin')
1334
+ })
1335
+ .description(
1336
+ 'Adds an OTP-Token header (draft-goto-otp-token) so that mail clients and browsers can offer the passcode. Experimental, follows the Internet-Draft. Cannot be combined with useStructuredFormat'
1337
+ )
1338
+ .label('SubmitOtp');
1339
+
1302
1340
  const messageDetailsSchema = Joi.object({
1303
1341
  id: Joi.string().example('AAAAAgAACrI').description('EmailEngine message identifier').label('MessageEntryId'),
1304
1342
  uid: Joi.number().integer().example(12345).description('IMAP UID (unique identifier within the mailbox). IMAP accounts only').label('MessageUid'),
@@ -1366,6 +1404,7 @@ const messageDetailsSchema = Joi.object({
1366
1404
  'Whether this message is a bounce (a delivery failure report). Checked for messages in the Inbox only; a delivery or delay notification is not one'
1367
1405
  ),
1368
1406
  relatedMessageId: Joi.string().example('<original@example.com>').description('Message-ID of the message that bounced. Set together with isBounce'),
1407
+ otp: messageOtpSchema,
1369
1408
 
1370
1409
  preview: Joi.string()
1371
1410
  .example('Hello, here is the report you asked for')
@@ -2885,8 +2924,29 @@ function apiResponses(description, ...statusCodes) {
2885
2924
  return Object.assign({ 200: { description } }, errorResponses(...statusCodes));
2886
2925
  }
2887
2926
 
2927
+ // What DELETE /v1/account/{account} reports about revoking the OAuth2 grant, present only when
2928
+ // revoke was requested. Also the `info.revocation` of a revoke=required refusal
2929
+ const accountRevocationSchema = Joi.object({
2930
+ attempted: Joi.boolean().example(true).description('Whether the provider was asked to revoke the grant'),
2931
+ revoked: Joi.boolean().example(true).description('Whether the provider confirmed the revocation'),
2932
+ status: Joi.number().integer().example(200).description('HTTP status of the provider response, when one arrived'),
2933
+ reason: Joi.string()
2934
+ .valid('NotOAuth2', 'NoToken', 'AppNotFound', 'AppError', 'ServiceAccount', 'Unsupported', 'TokenInvalid', 'ProviderRefused', 'RequestFailed')
2935
+ .example('ProviderRefused')
2936
+ .label('AccountRevocationReason')
2937
+ .description(
2938
+ 'Why the grant was not revoked. NotOAuth2: not an OAuth2 account. NoToken: no stored token to revoke with. AppNotFound / AppError: the OAuth2 application is missing or could not be loaded. ServiceAccount: a Workspace service account, which has no per-user grant. Unsupported: the provider offers no revocation endpoint (Microsoft). TokenInvalid: the provider reports the token as already revoked or expired. ProviderRefused: the provider answered with an error. RequestFailed: no answer from the provider'
2939
+ ),
2940
+ error: Joi.string().example('invalid_request').description('OAuth2 error code the provider returned, or the network error code')
2941
+ })
2942
+ .description('Outcome of the OAuth2 grant revocation, included when revoke was requested')
2943
+ .label('AccountRevocation');
2944
+
2888
2945
  module.exports = {
2889
2946
  requireTlsSchema,
2947
+ messageOtpSchema,
2948
+ submitOtpSchema,
2949
+ accountRevocationSchema,
2890
2950
  apiBoolean,
2891
2951
  formBoolean,
2892
2952
  MAX_MESSAGE_ATTACHMENTS,
@@ -32,8 +32,8 @@ module.exports = {
32
32
 
33
33
  contact: {
34
34
  name: 'EmailEngine Support',
35
- url: 'https://learn.emailengine.app/docs/support',
36
- email: 'support@emailengine.app'
35
+ url: 'https://emailengine.app/support',
36
+ email: 'support@postalsys.com'
37
37
  },
38
38
 
39
39
  license: {
package/lib/webhooks.js CHANGED
@@ -12,6 +12,7 @@ const { buildRetentionPolicy } = require('./queue-retention');
12
12
  const { getFailedJobRetention } = require('./env-setting-overrides');
13
13
  const { isDeliverableRoute, defaultRouteTakes, webhookRetryPolicy } = require('./webhook-routing');
14
14
  const { withinNotifyAttachmentSize } = require('./notify-attachments');
15
+ const { notifyHeadersIncludeOtp } = require('./otp');
15
16
 
16
17
  // Every setting pushToQueue() decides by, read in one round trip per event
17
18
  const QUEUE_SETTINGS = ['webhooksEnabled', 'queueKeep', 'webhookEvents', 'inboxNewOnly', 'webhooksDeliveryAttempts', 'webhooksRetryDelay'];
@@ -650,6 +651,10 @@ class WebhooksHandler {
650
651
  }
651
652
  }
652
653
 
654
+ if (data.otp && !notifyHeadersIncludeOtp(notifyHeaders)) {
655
+ delete data.otp;
656
+ }
657
+
653
658
  // remove attachment contents
654
659
  if (data.attachments) {
655
660
  for (let attachment of data.attachments) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.86.0",
3
+ "version": "2.87.0",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -50,32 +50,33 @@
50
50
  "url": "git+https://github.com/postalsys/emailengine.git"
51
51
  },
52
52
  "bugs": {
53
- "url": "https://github.com/postalsys/emailengine/issues"
53
+ "url": "https://emailengine.app/support",
54
+ "email": "support@postalsys.com"
54
55
  },
55
56
  "homepage": "https://emailengine.app/",
56
57
  "dependencies": {
57
58
  "@hapi/accept": "6.0.3",
58
- "@hapi/bell": "13.2.0",
59
+ "@hapi/bell": "13.2.1",
59
60
  "@hapi/boom": "10.0.1",
60
61
  "@hapi/cookie": "12.0.1",
61
62
  "@hapi/crumb": "9.0.1",
62
- "@hapi/hapi": "21.4.11",
63
+ "@hapi/hapi": "21.4.12",
63
64
  "@hapi/inert": "7.1.3",
64
65
  "@hapi/vision": "7.0.3",
65
66
  "@msgpack/msgpack": "3.1.3",
66
67
  "@postalsys/bounce-classifier": "3.1.0",
67
- "@postalsys/certs": "2.0.2",
68
- "@postalsys/email-ai-tools": "2.3.2",
68
+ "@postalsys/certs": "2.0.3",
69
+ "@postalsys/email-ai-tools": "2.4.0",
69
70
  "@postalsys/email-content": "0.1.18",
70
71
  "@postalsys/email-text-tools": "2.6.1",
71
72
  "@postalsys/gettext": "4.3.0",
72
73
  "@postalsys/joi-messages": "1.4.1",
73
74
  "@postalsys/templates": "2.1.1",
74
- "@sentry/node-core": "10.76.2",
75
+ "@sentry/node-core": "10.78.0",
75
76
  "@simplewebauthn/server": "14.0.3",
76
77
  "@zone-eu/mailsplit": "5.4.29",
77
78
  "@zone-eu/wild-config": "1.7.10",
78
- "bullmq": "6.4.0",
79
+ "bullmq": "6.5.1",
79
80
  "dotenv": "18.0.9",
80
81
  "fast-xml-parser": "5.11.2",
81
82
  "handlebars": "4.7.10",
@@ -83,33 +84,33 @@
83
84
  "html-to-text": "10.0.1",
84
85
  "ical.js": "2.2.1",
85
86
  "iconv-lite": "0.7.3",
86
- "imapflow": "2.9.1",
87
+ "imapflow": "2.10.0",
87
88
  "ioredfour": "2.2.0",
88
89
  "ioredis": "6.0.0",
89
90
  "ipaddr.js": "2.5.0",
90
- "joi": "18.3.0",
91
+ "joi": "18.3.1",
91
92
  "libbase64": "1.4.1",
92
93
  "libmime": "5.6.3",
93
94
  "libqp": "3.0.1",
94
- "mailparser": "3.12.4",
95
+ "mailparser": "3.14.1",
95
96
  "marked": "15.0.12",
96
97
  "minimist": "1.2.8",
97
- "nodemailer": "10.2.1",
98
+ "nodemailer": "10.3.1",
98
99
  "pino": "10.3.1",
99
100
  "prom-client": "15.1.3",
100
101
  "pubface": "1.2.0",
101
102
  "punycode.js": "2.3.1",
102
103
  "qrcode-generator": "2.0.4",
103
- "smtp-server": "3.21.1",
104
+ "smtp-server": "3.21.3",
104
105
  "socks": "2.8.10",
105
106
  "undici": "7.30.1"
106
107
  },
107
108
  "devDependencies": {
108
109
  "@eslint/js": "10.0.1",
109
- "@iconify-json/tabler": "1.2.42",
110
+ "@iconify-json/tabler": "1.2.43",
110
111
  "@iconify/tailwind4": "1.2.3",
111
112
  "@playwright/test": "1.63.0",
112
- "@postalsys/ee-client": "1.8.2",
113
+ "@postalsys/ee-client": "1.10.0",
113
114
  "@simplewebauthn/browser": "14.0.0",
114
115
  "@tailwindcss/cli": "4.3.3",
115
116
  "ace-builds": "1.45.2",