emailengine-app 2.81.2 → 2.82.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/.ncurc.js +12 -11
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +27 -0
- package/Dockerfile +2 -0
- package/bin/emailengine.js +28 -18
- package/config/default.toml +0 -5
- package/config/test.toml +0 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +70 -42
- package/getswagger.sh +0 -4
- package/lib/account/account-state.js +2 -110
- package/lib/account/expected-identity.js +1 -1
- package/lib/account-assignment.js +138 -1
- package/lib/account.js +254 -859
- package/lib/api-reference/index.js +2 -3
- package/lib/api-reference/schema-tree.js +53 -3
- package/lib/api-routes/account-routes.js +18 -29
- package/lib/api-routes/blocklist-routes.js +2 -2
- package/lib/api-routes/bull-board-routes.js +1 -6
- package/lib/api-routes/export-routes.js +2 -22
- package/lib/api-routes/gateway-routes.js +5 -14
- package/lib/api-routes/index.js +1 -13
- package/lib/api-routes/mailbox-routes.js +2 -7
- package/lib/api-routes/mcp-oauth-routes.js +2 -1
- package/lib/api-routes/mcp-routes.js +7 -7
- package/lib/api-routes/message-routes.js +40 -235
- package/lib/api-routes/mint-bounds.js +110 -0
- package/lib/api-routes/oauth2-app-routes.js +23 -32
- package/lib/api-routes/operation-impact.js +1 -1
- package/lib/api-routes/outbox-routes.js +2 -2
- package/lib/api-routes/permission-map.js +1 -7
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/api-routes/settings-routes.js +19 -19
- package/lib/api-routes/stats-routes.js +1 -1
- package/lib/api-routes/submit-routes.js +17 -18
- package/lib/api-routes/template-routes.js +4 -9
- package/lib/api-routes/token-routes.js +27 -5
- package/lib/api-token-scheme.js +71 -0
- package/lib/arf-detect.js +33 -6
- package/lib/auth-token.js +44 -24
- package/lib/autodetect-imap-settings.js +163 -123
- package/lib/bounce-detect.js +25 -16
- package/lib/calendar-event.js +78 -0
- package/lib/consts.js +42 -5
- package/lib/create-imap-client.js +24 -0
- package/lib/db.js +76 -11
- package/lib/delivery-error.js +2 -1
- package/lib/egress-fetch.js +54 -3
- package/lib/egress-filter.js +11 -0
- package/lib/email-client/api-retry.js +147 -0
- package/lib/email-client/base-client.js +377 -523
- package/lib/email-client/gmail/gmail-api.js +38 -125
- package/lib/email-client/gmail/send-request.js +1 -1
- package/lib/email-client/gmail-client.js +76 -50
- package/lib/email-client/imap/mailbox.js +158 -324
- package/lib/email-client/imap/stale-view.js +109 -0
- package/lib/email-client/imap/subconnection.js +46 -9
- package/lib/email-client/imap/sync-operations.js +5 -37
- package/lib/email-client/imap-client.js +188 -64
- package/lib/email-client/message-builder.js +9 -14
- package/lib/email-client/notification-handler.js +5 -219
- package/lib/email-client/outlook/graph-api.js +147 -126
- package/lib/email-client/outlook/send-request.js +10 -4
- package/lib/email-client/outlook-client.js +194 -397
- package/lib/email-client/smtp-pool-manager.js +3 -2
- package/lib/encrypt.js +184 -19
- package/lib/enum-descriptions.js +1 -2
- package/lib/export.js +133 -39
- package/lib/gateway.js +20 -6
- package/lib/get-raw-email.js +26 -44
- package/lib/handlebars-helpers.js +31 -10
- package/lib/imap-proxy-auth.js +13 -29
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
- package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
- package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
- package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
- package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
- package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
- package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
- package/lib/imapproxy/imap-server.js +17 -177
- package/lib/imapproxy/proxy-handoff.js +235 -0
- package/lib/imapproxy/response-error.js +33 -0
- package/lib/imapproxy/upstream-client.js +2 -2
- package/lib/license-beacon.js +3 -9
- package/lib/llm-pre-process.js +182 -43
- package/lib/logger.js +1 -1
- package/lib/lua/ee-export-queue-add.lua +39 -0
- package/lib/lua/ee-get-idempotency.lua +15 -3
- package/lib/lua/ee-release-attempts.lua +23 -0
- package/lib/lua/ee-reserve-attempts.lua +42 -0
- package/lib/lua/h-set-bigger.lua +12 -2
- package/lib/lua/s-list-accounts.lua +6 -3
- package/lib/mcp/index.js +1 -2
- package/lib/mcp/listen.js +221 -18
- package/lib/mcp/oauth.js +44 -5
- package/lib/mcp/resources.js +8 -2
- package/lib/mcp/tools.js +13 -0
- package/lib/message-port-stream.js +64 -6
- package/lib/oauth/external-account-signer.js +16 -13
- package/lib/oauth/gmail.js +22 -20
- package/lib/oauth/outlook.js +19 -16
- package/lib/oauth/pubsub/google.js +38 -2
- package/lib/oauth/scope-checker.js +4 -7
- package/lib/oauth/verify-app.js +2 -2
- package/lib/oauth2-apps.js +139 -44
- package/lib/openapi/build-document.js +1 -1
- package/lib/openapi/joi-schema.js +78 -9
- package/lib/parse-message.js +21 -0
- package/lib/payload-examples-webhooks.json +4 -7
- package/lib/pbkdf2-phc.js +101 -0
- package/lib/privileged-settings.js +0 -14
- package/lib/rate-limit.js +54 -15
- package/lib/redis-scan-delete.js +56 -29
- package/lib/redis-url.js +3 -1
- package/lib/respawn-backoff.js +5 -4
- package/lib/response-stream.js +25 -4
- package/lib/rewrite-text-nodes.js +27 -40
- package/lib/routes-ui.js +0 -5
- package/lib/schemas.js +122 -242
- package/lib/sentry.js +21 -5
- package/lib/settings.js +58 -59
- package/lib/smtp-auth.js +6 -2
- package/lib/smtp-message-processor.js +28 -7
- package/lib/sso.js +7 -3
- package/lib/stream-encrypt.js +14 -13
- package/lib/swagger-options.js +3 -1
- package/lib/tls/provision.js +69 -3
- package/lib/tls/store.js +14 -1
- package/lib/tools.js +113 -52
- package/lib/totp.js +16 -1
- package/lib/ui-routes/account-routes.js +27 -63
- package/lib/ui-routes/admin-config-routes.js +111 -134
- package/lib/ui-routes/admin-entities-routes.js +101 -191
- package/lib/ui-routes/ai-options.js +104 -0
- package/lib/ui-routes/auth-routes.js +98 -18
- package/lib/ui-routes/export-routes.js +3 -23
- package/lib/ui-routes/internals-routes.js +12 -9
- package/lib/ui-routes/network-config-routes.js +8 -18
- package/lib/ui-routes/oauth-config-routes.js +80 -214
- package/lib/ui-routes/route-helpers.js +40 -44
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/utils/decode-headers.js +32 -5
- package/lib/utils/header-map.js +62 -1
- package/lib/utils/network.js +2 -0
- package/lib/web-safe-html.js +77 -4
- package/lib/webhook-request.js +9 -1
- package/lib/webhook-routing.js +27 -1
- package/lib/webhooks.js +120 -43
- package/lib/worker-rpc-error.js +43 -2
- package/list-generate.js +13 -2
- package/package.json +33 -41
- package/sbom.json +1 -1
- package/scripts/refresh-test-tokens.js +42 -14
- package/server.js +317 -289
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +7 -8
- package/static/js/ee-client.js +145 -70
- package/static/js/ui.js +350 -154
- package/static/licenses.html +434 -1835
- package/translations/messages.pot +97 -97
- package/views/accounts/browse.hbs +10 -4
- package/views/config/ai.hbs +49 -41
- package/views/config/oauth/app.hbs +2 -1
- package/views/dashboard.hbs +18 -16
- package/views/layout/app.hbs +0 -22
- package/views/layout/login.hbs +2 -1
- package/views/partials/filter_editor_js.hbs +4 -3
- package/views/partials/side_menu.hbs +0 -4
- package/views/partials/ui/account-picker.hbs +6 -32
- package/views/partials/ui/model-picker.hbs +31 -0
- package/views/partials/ui/pagination.hbs +6 -1
- package/views/partials/ui/picker.hbs +47 -0
- package/views/unsubscribe.hbs +1 -1
- package/workers/api.js +20 -20
- package/workers/export.js +55 -60
- package/workers/imap.js +126 -46
- package/workers/submit.js +3 -1
- package/workers/webhooks.js +46 -27
- package/.githooks/pre-commit +0 -80
- package/.github/CODE_OF_CONDUCT.md +0 -76
- package/.github/contributing.md +0 -17
- package/.github/dependabot.yml +0 -22
- package/.github/docker-smoke-test.sh +0 -61
- package/.github/workflows/deploy.yml +0 -215
- package/.github/workflows/e2e.yml +0 -55
- package/.github/workflows/release.yaml +0 -217
- package/.github/workflows/test.yml +0 -307
- package/lib/api-routes/chat-routes.js +0 -535
- package/lib/document-store.js +0 -75
- package/lib/es.js +0 -757
- package/lib/generate-text-preview.js +0 -61
- package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
- package/lib/pre-process.js +0 -196
- package/lib/threads.js +0 -155
- package/lib/ui-routes/document-store-routes.js +0 -806
- package/playwright.config.js +0 -47
- package/views/config/document-store/chat.hbs +0 -286
- package/views/config/document-store/index.hbs +0 -146
- package/views/config/document-store/mappings/index.hbs +0 -108
- package/views/config/document-store/mappings/new.hbs +0 -68
- package/views/config/document-store/pre-processing/index.hbs +0 -103
- package/views/partials/document_store_header.hbs +0 -30
- package/workers/documents.js +0 -1128
|
@@ -4,7 +4,6 @@ const { threadId: workerThreadId } = require('worker_threads');
|
|
|
4
4
|
const crypto = require('crypto');
|
|
5
5
|
const logger = require('../logger');
|
|
6
6
|
const settings = require('../settings');
|
|
7
|
-
const { isDocumentStoreEnabled } = require('../document-store');
|
|
8
7
|
const msgpack = require('../msgpack');
|
|
9
8
|
const { templates } = require('../templates');
|
|
10
9
|
const { Gateway } = require('../gateway');
|
|
@@ -21,11 +20,12 @@ const { arfDetect, camelCaseComplaint, FEEDBACK_REPORT_TYPE, ORIGINAL_MESSAGE_TY
|
|
|
21
20
|
const { createTransaction } = require('../redis-operations');
|
|
22
21
|
const { ACCOUNT_STATES } = require('../account/account-state');
|
|
23
22
|
const { credentialErrorStatus, isTransientCredentialError, resolveAuthServerCredentials } = require('./credential-errors');
|
|
24
|
-
const
|
|
23
|
+
const { parseMessage } = require('../parse-message');
|
|
25
24
|
const libmime = require('libmime');
|
|
26
|
-
const { bounceDetect, applyDeliveryReport } = require('../bounce-detect');
|
|
27
|
-
const
|
|
28
|
-
const { llmPreProcess } = require('../llm-pre-process');
|
|
25
|
+
const { bounceDetect, applyDeliveryReport, PARSER_OPTIONS: DSN_PARSER_OPTIONS } = require('../bounce-detect');
|
|
26
|
+
const { parseCalendarEvent, sortCalendarAttachments, CALENDAR_CONTENT_TYPES } = require('../calendar-event');
|
|
27
|
+
const { llmPreProcess, summaryFetchHeaders, summaryProvider } = require('../llm-pre-process');
|
|
28
|
+
const { notificationHeaderFields, narrowHeaders } = require('../utils/header-map');
|
|
29
29
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
30
30
|
const { Account } = require('../account');
|
|
31
31
|
const { removeBcc } = require('../get-raw-email');
|
|
@@ -54,7 +54,7 @@ const {
|
|
|
54
54
|
getDateBuckets,
|
|
55
55
|
useAuthServerForOAuth2,
|
|
56
56
|
collectCidReferences,
|
|
57
|
-
|
|
57
|
+
embedCidImages
|
|
58
58
|
} = require('../tools');
|
|
59
59
|
|
|
60
60
|
// Import application constants
|
|
@@ -164,6 +164,74 @@ function applyReferenceRecipients(data, referencedMessage) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// Message-ids kept in an outgoing References header besides the thread root, so a long thread
|
|
168
|
+
// does not grow the header without bound
|
|
169
|
+
const MAX_REFERENCES_TAIL = 20;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Builds the References header of a reply or forward (RFC 5322 3.6.4): the parent's References,
|
|
173
|
+
* or its In-Reply-To when it has none, followed by the parent's own Message-ID last. JWZ-style
|
|
174
|
+
* threading reads the last entry as the direct parent, so the order carries meaning. A repeated
|
|
175
|
+
* id keeps its last position, and a long chain is cut to the thread root plus the most recent
|
|
176
|
+
* MAX_REFERENCES_TAIL entries
|
|
177
|
+
* @param {Object} referencedMessage - The message being replied to or forwarded
|
|
178
|
+
* @returns {string[]} Message-ids in angle brackets, in header order
|
|
179
|
+
*/
|
|
180
|
+
function buildReferences(referencedMessage) {
|
|
181
|
+
const split = value =>
|
|
182
|
+
[]
|
|
183
|
+
.concat(value || [])
|
|
184
|
+
.flatMap(line => (typeof line === 'string' ? line.split(/\s+/) : []))
|
|
185
|
+
.map(ref => ref.trim())
|
|
186
|
+
.filter(ref => ref)
|
|
187
|
+
.map(ref => {
|
|
188
|
+
// Ensure proper Message-ID format
|
|
189
|
+
if (!/^</.test(ref)) {
|
|
190
|
+
ref = '<' + ref;
|
|
191
|
+
}
|
|
192
|
+
if (!/>$/.test(ref)) {
|
|
193
|
+
ref = ref + '>';
|
|
194
|
+
}
|
|
195
|
+
return ref;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
let chain = split(referencedMessage.headers && referencedMessage.headers.references);
|
|
199
|
+
if (!chain.length) {
|
|
200
|
+
chain = split(referencedMessage.inReplyTo);
|
|
201
|
+
}
|
|
202
|
+
chain = chain.concat(split(referencedMessage.messageId));
|
|
203
|
+
|
|
204
|
+
// Walked from the end, so the last occurrence of a repeated id is the one kept, and pushed
|
|
205
|
+
// then reversed once: the sender controls the length of this header, and an unshift per
|
|
206
|
+
// entry made the dedupe quadratic
|
|
207
|
+
let seen = new Set();
|
|
208
|
+
let references = [];
|
|
209
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
210
|
+
if (!seen.has(chain[i])) {
|
|
211
|
+
seen.add(chain[i]);
|
|
212
|
+
references.push(chain[i]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
references.reverse();
|
|
216
|
+
|
|
217
|
+
if (references.length > MAX_REFERENCES_TAIL + 1) {
|
|
218
|
+
references = [references[0]].concat(references.slice(-MAX_REFERENCES_TAIL));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return references;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Whether a parsed bounce reports a failed delivery. A DSN also reports delivered, delayed,
|
|
226
|
+
* relayed and expanded recipients, and none of those is a bounce to store or to fire emailBounce
|
|
227
|
+
* for; a delayed DSN that landed in Junk used to reach the bounce path with its action set
|
|
228
|
+
* @param {Object} bounce - Result of bounceDetect()
|
|
229
|
+
* @returns {boolean}
|
|
230
|
+
*/
|
|
231
|
+
function isFailedDelivery(bounce) {
|
|
232
|
+
return !!bounce && typeof bounce.action === 'string' && bounce.action.trim().toLowerCase() === 'failed' && !!bounce.recipient && !!bounce.messageId;
|
|
233
|
+
}
|
|
234
|
+
|
|
167
235
|
// Finds the attachments of a referenced message whose content id the given HTML links to
|
|
168
236
|
function findReferencedCidAttachments(html, attachments) {
|
|
169
237
|
let cidAttachments = [];
|
|
@@ -340,8 +408,6 @@ class BaseClient {
|
|
|
340
408
|
// Message queue connections
|
|
341
409
|
this.notifyQueue = this.options.notifyQueue;
|
|
342
410
|
this.submitQueue = this.options.submitQueue;
|
|
343
|
-
this.documentsQueue = this.options.documentsQueue;
|
|
344
|
-
this.flowProducer = this.options.flowProducer;
|
|
345
411
|
|
|
346
412
|
// Inter-process communication handler
|
|
347
413
|
this.call = this.options.call;
|
|
@@ -377,9 +443,7 @@ class BaseClient {
|
|
|
377
443
|
// Initialize notification handler for webhook and event delivery
|
|
378
444
|
this.notificationHandler = new NotificationHandler({
|
|
379
445
|
account: this.account,
|
|
380
|
-
logger: this.logger
|
|
381
|
-
flowProducer: this.flowProducer,
|
|
382
|
-
documentsQueue: this.documentsQueue
|
|
446
|
+
logger: this.logger
|
|
383
447
|
});
|
|
384
448
|
}
|
|
385
449
|
|
|
@@ -409,10 +473,6 @@ class BaseClient {
|
|
|
409
473
|
return null;
|
|
410
474
|
}
|
|
411
475
|
|
|
412
|
-
async subconnections() {
|
|
413
|
-
return [];
|
|
414
|
-
}
|
|
415
|
-
|
|
416
476
|
async getQuota() {
|
|
417
477
|
return false;
|
|
418
478
|
}
|
|
@@ -687,13 +747,13 @@ class BaseClient {
|
|
|
687
747
|
return;
|
|
688
748
|
}
|
|
689
749
|
|
|
690
|
-
let parsed = await
|
|
750
|
+
let parsed = await parseMessage(content, DSN_PARSER_OPTIONS);
|
|
691
751
|
if (applyDeliveryReport(parsed, logContext, this.logger)) {
|
|
692
752
|
return;
|
|
693
753
|
}
|
|
694
754
|
|
|
695
755
|
let bounce = await bounceDetect({ parsed });
|
|
696
|
-
if (bounce
|
|
756
|
+
if (isFailedDelivery(bounce)) {
|
|
697
757
|
messageData.isBounce = true;
|
|
698
758
|
messageData.relatedMessageId = bounce.messageId;
|
|
699
759
|
}
|
|
@@ -1263,7 +1323,7 @@ class BaseClient {
|
|
|
1263
1323
|
* @param {Object} data - Event data payload
|
|
1264
1324
|
* @param {Object} extraOpts - Additional options
|
|
1265
1325
|
*/
|
|
1266
|
-
async notify(mailbox, event, data
|
|
1326
|
+
async notify(mailbox, event, data) {
|
|
1267
1327
|
// Handle error state tracking for connection/auth errors
|
|
1268
1328
|
// This is BaseClient-specific logic that must run before notification
|
|
1269
1329
|
switch (event) {
|
|
@@ -1279,8 +1339,8 @@ class BaseClient {
|
|
|
1279
1339
|
}
|
|
1280
1340
|
}
|
|
1281
1341
|
|
|
1282
|
-
// Delegate to notification handler for webhook
|
|
1283
|
-
await this.notificationHandler.notify(mailbox, event, data
|
|
1342
|
+
// Delegate to notification handler for webhook delivery
|
|
1343
|
+
await this.notificationHandler.notify(mailbox, event, data);
|
|
1284
1344
|
}
|
|
1285
1345
|
|
|
1286
1346
|
/**
|
|
@@ -1412,47 +1472,42 @@ class BaseClient {
|
|
|
1412
1472
|
* @returns {Object} Final delegated account data
|
|
1413
1473
|
*/
|
|
1414
1474
|
async getDelegatedAccount(accountData) {
|
|
1415
|
-
let redirect = 0;
|
|
1416
1475
|
let providerAccountData = accountData;
|
|
1417
|
-
let
|
|
1418
|
-
|
|
1419
|
-
|
|
1476
|
+
let seenAccounts = new Set([accountData.account]);
|
|
1477
|
+
const hopsAllowed = 20;
|
|
1478
|
+
|
|
1479
|
+
// Follow delegation chain. Each hop is built from the account the previous hop resolved
|
|
1480
|
+
// to - building it from the original account reloaded the first hop on every pass, so a
|
|
1481
|
+
// valid A->B->C chain was reported as a loop
|
|
1482
|
+
for (let hop = 0; hop < hopsAllowed; hop++) {
|
|
1483
|
+
const nextAccount = providerAccountData.oauth2.auth.delegatedAccount;
|
|
1484
|
+
|
|
1485
|
+
// Detect delegation loops
|
|
1486
|
+
if (seenAccounts.has(nextAccount)) {
|
|
1487
|
+
throw new Error('Delegation looping detected');
|
|
1488
|
+
}
|
|
1489
|
+
seenAccounts.add(nextAccount);
|
|
1420
1490
|
|
|
1421
|
-
// Follow delegation chain
|
|
1422
|
-
while (redirect++ < hopsAllowed) {
|
|
1423
1491
|
// Load delegated account if not cached
|
|
1424
|
-
if (!this.delegatedAccountObject || this.delegatedAccountObject.account !==
|
|
1492
|
+
if (!this.delegatedAccountObject || this.delegatedAccountObject.account !== nextAccount) {
|
|
1425
1493
|
this.delegatedAccountObject = new Account({
|
|
1426
|
-
account:
|
|
1494
|
+
account: nextAccount,
|
|
1427
1495
|
redis: this.accountObject.redis,
|
|
1428
1496
|
call: this.accountObject.call,
|
|
1429
1497
|
secret: this.accountObject.secret,
|
|
1430
1498
|
timeout: this.accountObject.timeout
|
|
1431
1499
|
});
|
|
1432
1500
|
}
|
|
1433
|
-
delegatedAccountData = await this.delegatedAccountObject.loadAccountData();
|
|
1501
|
+
const delegatedAccountData = await this.delegatedAccountObject.loadAccountData();
|
|
1434
1502
|
|
|
1435
1503
|
// Check if this account also delegates to another
|
|
1436
|
-
if (delegatedAccountData.oauth2
|
|
1437
|
-
|
|
1438
|
-
if (seenAccounts.has(providerAccountData.account)) {
|
|
1439
|
-
// loop detected
|
|
1440
|
-
let error = new Error('Delegation looping detected');
|
|
1441
|
-
throw error;
|
|
1442
|
-
}
|
|
1443
|
-
seenAccounts.add(providerAccountData.account);
|
|
1444
|
-
providerAccountData = delegatedAccountData;
|
|
1445
|
-
continue;
|
|
1504
|
+
if (!(delegatedAccountData.oauth2?.auth?.delegatedUser && delegatedAccountData.oauth2.auth.delegatedAccount)) {
|
|
1505
|
+
return delegatedAccountData;
|
|
1446
1506
|
}
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
if (redirect >= hopsAllowed) {
|
|
1451
|
-
let error = new Error('Too many delegation hops');
|
|
1452
|
-
throw error;
|
|
1507
|
+
providerAccountData = delegatedAccountData;
|
|
1453
1508
|
}
|
|
1454
1509
|
|
|
1455
|
-
|
|
1510
|
+
throw new Error('Too many delegation hops');
|
|
1456
1511
|
}
|
|
1457
1512
|
|
|
1458
1513
|
/**
|
|
@@ -1676,11 +1731,9 @@ class BaseClient {
|
|
|
1676
1731
|
let gatewayObject;
|
|
1677
1732
|
if (data.gateway) {
|
|
1678
1733
|
gatewayObject = new Gateway({ gateway: data.gateway, redis: this.redis, secret: this.secret });
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
this.logger.warn({ msg: 'Failed to load gateway data', messageId: data.messageId, gateway: data.gateway, err });
|
|
1683
|
-
}
|
|
1734
|
+
// The message was asked to go through this gateway, so it must not fall through to
|
|
1735
|
+
// the account's own SMTP server: a missing gateway throws GatewayNotFound (404)
|
|
1736
|
+
gatewayData = await gatewayObject.loadGatewayData();
|
|
1684
1737
|
}
|
|
1685
1738
|
|
|
1686
1739
|
// Verify SMTP capability
|
|
@@ -1863,88 +1916,62 @@ class BaseClient {
|
|
|
1863
1916
|
delete data.tz;
|
|
1864
1917
|
|
|
1865
1918
|
let referencedMessage;
|
|
1866
|
-
let documentStoreUsed = false;
|
|
1867
1919
|
|
|
1868
1920
|
// Resolve reference and update reference/in-reply-to headers
|
|
1869
1921
|
if (data.reference && data.reference.message) {
|
|
1870
|
-
//
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1922
|
+
// Fetch from IMAP/API with retry logic for transient errors
|
|
1923
|
+
let extendedData = data.reference.inline || data.reference.forwardAttachments;
|
|
1924
|
+
|
|
1925
|
+
try {
|
|
1926
|
+
referencedMessage = await retryOnTransientError(
|
|
1927
|
+
async () => {
|
|
1928
|
+
return await this.getMessage(
|
|
1929
|
+
data.reference.message,
|
|
1930
|
+
{
|
|
1931
|
+
fields: !extendedData
|
|
1932
|
+
? {
|
|
1933
|
+
uid: true,
|
|
1934
|
+
flags: true,
|
|
1935
|
+
envelope: true,
|
|
1936
|
+
headers: ['references']
|
|
1937
|
+
}
|
|
1938
|
+
: false,
|
|
1939
|
+
textType: extendedData ? '*' : false
|
|
1940
|
+
},
|
|
1941
|
+
connectionOptions
|
|
1942
|
+
);
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
maxAttempts: 3,
|
|
1946
|
+
baseDelay: 1000,
|
|
1947
|
+
logger: this.logger
|
|
1948
|
+
}
|
|
1949
|
+
);
|
|
1950
|
+
} catch (err) {
|
|
1951
|
+
// Check if this is a transient error that exhausted retries
|
|
1952
|
+
const isTransient = isTransientError(err);
|
|
1953
|
+
|
|
1954
|
+
if (isTransient && data.reference.ignoreMissing) {
|
|
1955
|
+
// Transient error but ignoreMissing is true - log and continue without reference
|
|
1956
|
+
this.logger.warn({
|
|
1957
|
+
msg: 'Failed to fetch referenced message due to transient error, continuing without reference',
|
|
1958
|
+
messageId: data.reference.message,
|
|
1959
|
+
err,
|
|
1960
|
+
statusCode: err.statusCode || (err.oauthRequest && err.oauthRequest.status)
|
|
1876
1961
|
});
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
let error = new Error('
|
|
1882
|
-
error.
|
|
1883
|
-
|
|
1884
|
-
statusCode: err.meta && err.meta.statusCode
|
|
1885
|
-
};
|
|
1886
|
-
error.code = 'ESRequestError';
|
|
1887
|
-
error.statusCode = (err.meta && err.meta.statusCode) || 500;
|
|
1962
|
+
referencedMessage = null;
|
|
1963
|
+
} else if (!isTransient && err.statusCode === 404) {
|
|
1964
|
+
// Permanent 404 error - respect ignoreMissing
|
|
1965
|
+
if (!data.reference.ignoreMissing) {
|
|
1966
|
+
let error = new Error('Referenced message was not found');
|
|
1967
|
+
error.code = 'ReferenceNotFound';
|
|
1968
|
+
error.statusCode = 404;
|
|
1888
1969
|
throw error;
|
|
1889
1970
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
let extendedData = data.reference.inline || data.reference.forwardAttachments;
|
|
1895
|
-
|
|
1896
|
-
try {
|
|
1897
|
-
referencedMessage = await retryOnTransientError(
|
|
1898
|
-
async () => {
|
|
1899
|
-
return await this.getMessage(
|
|
1900
|
-
data.reference.message,
|
|
1901
|
-
{
|
|
1902
|
-
fields: !extendedData
|
|
1903
|
-
? {
|
|
1904
|
-
uid: true,
|
|
1905
|
-
flags: true,
|
|
1906
|
-
envelope: true,
|
|
1907
|
-
headers: ['references']
|
|
1908
|
-
}
|
|
1909
|
-
: false,
|
|
1910
|
-
header: extendedData ? true : false,
|
|
1911
|
-
textType: extendedData ? '*' : false
|
|
1912
|
-
},
|
|
1913
|
-
connectionOptions
|
|
1914
|
-
);
|
|
1915
|
-
},
|
|
1916
|
-
{
|
|
1917
|
-
maxAttempts: 3,
|
|
1918
|
-
baseDelay: 1000,
|
|
1919
|
-
logger: this.logger
|
|
1920
|
-
}
|
|
1921
|
-
);
|
|
1922
|
-
} catch (err) {
|
|
1923
|
-
// Check if this is a transient error that exhausted retries
|
|
1924
|
-
const isTransient = isTransientError(err);
|
|
1925
|
-
|
|
1926
|
-
if (isTransient && data.reference.ignoreMissing) {
|
|
1927
|
-
// Transient error but ignoreMissing is true - log and continue without reference
|
|
1928
|
-
this.logger.warn({
|
|
1929
|
-
msg: 'Failed to fetch referenced message due to transient error, continuing without reference',
|
|
1930
|
-
messageId: data.reference.message,
|
|
1931
|
-
err,
|
|
1932
|
-
statusCode: err.statusCode || (err.oauthRequest && err.oauthRequest.status)
|
|
1933
|
-
});
|
|
1934
|
-
referencedMessage = null;
|
|
1935
|
-
} else if (!isTransient && err.statusCode === 404) {
|
|
1936
|
-
// Permanent 404 error - respect ignoreMissing
|
|
1937
|
-
if (!data.reference.ignoreMissing) {
|
|
1938
|
-
let error = new Error('Referenced message was not found');
|
|
1939
|
-
error.code = 'ReferenceNotFound';
|
|
1940
|
-
error.statusCode = 404;
|
|
1941
|
-
throw error;
|
|
1942
|
-
}
|
|
1943
|
-
referencedMessage = null;
|
|
1944
|
-
} else {
|
|
1945
|
-
// Either transient error with ignoreMissing=false, or other permanent error
|
|
1946
|
-
throw err;
|
|
1947
|
-
}
|
|
1971
|
+
referencedMessage = null;
|
|
1972
|
+
} else {
|
|
1973
|
+
// Either transient error with ignoreMissing=false, or other permanent error
|
|
1974
|
+
throw err;
|
|
1948
1975
|
}
|
|
1949
1976
|
}
|
|
1950
1977
|
|
|
@@ -1965,25 +1992,7 @@ class BaseClient {
|
|
|
1965
1992
|
}
|
|
1966
1993
|
|
|
1967
1994
|
// Build references header chain
|
|
1968
|
-
let references =
|
|
1969
|
-
.concat(referencedMessage.messageId || [])
|
|
1970
|
-
.concat(referencedMessage.inReplyTo || [])
|
|
1971
|
-
.concat((referencedMessage.headers && referencedMessage.headers.references) || [])
|
|
1972
|
-
.flatMap(line => line.split(/\s+/))
|
|
1973
|
-
.map(ref => ref.trim())
|
|
1974
|
-
.filter(ref => ref)
|
|
1975
|
-
.map(ref => {
|
|
1976
|
-
// Ensure proper Message-ID format
|
|
1977
|
-
if (!/^</.test(ref)) {
|
|
1978
|
-
ref = '<' + ref;
|
|
1979
|
-
}
|
|
1980
|
-
if (!/>$/.test(ref)) {
|
|
1981
|
-
ref = ref + '>';
|
|
1982
|
-
}
|
|
1983
|
-
return ref;
|
|
1984
|
-
});
|
|
1985
|
-
|
|
1986
|
-
references = Array.from(new Set(references));
|
|
1995
|
+
let references = buildReferences(referencedMessage);
|
|
1987
1996
|
if (references.length) {
|
|
1988
1997
|
if (!data.headers) {
|
|
1989
1998
|
data.headers = {};
|
|
@@ -2158,7 +2167,7 @@ class BaseClient {
|
|
|
2158
2167
|
// Generate raw MIME message
|
|
2159
2168
|
let { raw, emailObject, messageId } = await getRawEmail(data, null, options);
|
|
2160
2169
|
|
|
2161
|
-
return { raw, emailObject, messageId,
|
|
2170
|
+
return { raw, emailObject, messageId, referencedMessage };
|
|
2162
2171
|
}
|
|
2163
2172
|
|
|
2164
2173
|
/**
|
|
@@ -2300,90 +2309,64 @@ class BaseClient {
|
|
|
2300
2309
|
}
|
|
2301
2310
|
|
|
2302
2311
|
let referencedMessage;
|
|
2303
|
-
let documentStoreUsed = false;
|
|
2304
2312
|
|
|
2305
2313
|
// Resolve reference and update reference/in-reply-to headers
|
|
2306
2314
|
if (data.reference && data.reference.message) {
|
|
2307
|
-
//
|
|
2308
|
-
|
|
2309
|
-
try {
|
|
2310
|
-
referencedMessage = await this.accountObject.getMessage(data.reference.message, {
|
|
2311
|
-
documentStore: true,
|
|
2312
|
-
textType: '*'
|
|
2313
|
-
});
|
|
2314
|
-
} catch (err) {
|
|
2315
|
-
if (err.meta && err.meta.statusCode === 404) {
|
|
2316
|
-
// not found
|
|
2317
|
-
} else {
|
|
2318
|
-
let error = new Error('ElasticSearch request failed');
|
|
2319
|
-
error.info = {
|
|
2320
|
-
response: (err.meta && err.meta.body) || err.message,
|
|
2321
|
-
statusCode: err.meta && err.meta.statusCode
|
|
2322
|
-
};
|
|
2323
|
-
error.code = 'ESRequestError';
|
|
2324
|
-
error.statusCode = (err.meta && err.meta.statusCode) || 500;
|
|
2325
|
-
throw error;
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
documentStoreUsed = true;
|
|
2329
|
-
} else {
|
|
2330
|
-
// Fetch from IMAP/API with retry logic for transient errors
|
|
2331
|
-
this.checkIMAPConnection(connectionOptions);
|
|
2315
|
+
// Fetch from IMAP/API with retry logic for transient errors
|
|
2316
|
+
this.checkIMAPConnection(connectionOptions);
|
|
2332
2317
|
|
|
2333
|
-
|
|
2318
|
+
let extendedData = data.reference.inline || data.reference.forwardAttachments;
|
|
2334
2319
|
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
throw error;
|
|
2381
|
-
}
|
|
2382
|
-
referencedMessage = null;
|
|
2383
|
-
} else {
|
|
2384
|
-
// Either transient error with ignoreMissing=false, or other permanent error
|
|
2385
|
-
throw err;
|
|
2320
|
+
try {
|
|
2321
|
+
referencedMessage = await retryOnTransientError(
|
|
2322
|
+
async () => {
|
|
2323
|
+
return await this.getMessage(
|
|
2324
|
+
data.reference.message,
|
|
2325
|
+
{
|
|
2326
|
+
fields: !extendedData
|
|
2327
|
+
? {
|
|
2328
|
+
uid: true,
|
|
2329
|
+
flags: true,
|
|
2330
|
+
envelope: true,
|
|
2331
|
+
headers: ['references']
|
|
2332
|
+
}
|
|
2333
|
+
: false,
|
|
2334
|
+
textType: extendedData ? '*' : false
|
|
2335
|
+
},
|
|
2336
|
+
connectionOptions
|
|
2337
|
+
);
|
|
2338
|
+
},
|
|
2339
|
+
{
|
|
2340
|
+
maxAttempts: 3,
|
|
2341
|
+
baseDelay: 1000,
|
|
2342
|
+
logger: this.logger
|
|
2343
|
+
}
|
|
2344
|
+
);
|
|
2345
|
+
} catch (err) {
|
|
2346
|
+
// Check if this is a transient error that exhausted retries
|
|
2347
|
+
const isTransient = isTransientError(err);
|
|
2348
|
+
|
|
2349
|
+
if (isTransient && data.reference.ignoreMissing) {
|
|
2350
|
+
// Transient error but ignoreMissing is true - log and continue without reference
|
|
2351
|
+
this.logger.warn({
|
|
2352
|
+
msg: 'Failed to fetch referenced message due to transient error, continuing without reference',
|
|
2353
|
+
messageId: data.reference.message,
|
|
2354
|
+
err,
|
|
2355
|
+
statusCode: err.statusCode || (err.oauthRequest && err.oauthRequest.status)
|
|
2356
|
+
});
|
|
2357
|
+
referencedMessage = null;
|
|
2358
|
+
} else if (!isTransient && err.statusCode === 404) {
|
|
2359
|
+
// Permanent 404 error - respect ignoreMissing
|
|
2360
|
+
if (!data.reference.ignoreMissing) {
|
|
2361
|
+
let error = new Error('Referenced message was not found');
|
|
2362
|
+
error.code = 'ReferenceNotFound';
|
|
2363
|
+
error.statusCode = 404;
|
|
2364
|
+
throw error;
|
|
2386
2365
|
}
|
|
2366
|
+
referencedMessage = null;
|
|
2367
|
+
} else {
|
|
2368
|
+
// Either transient error with ignoreMissing=false, or other permanent error
|
|
2369
|
+
throw err;
|
|
2387
2370
|
}
|
|
2388
2371
|
}
|
|
2389
2372
|
|
|
@@ -2404,25 +2387,7 @@ class BaseClient {
|
|
|
2404
2387
|
}
|
|
2405
2388
|
|
|
2406
2389
|
// Build references header chain
|
|
2407
|
-
let references =
|
|
2408
|
-
.concat(referencedMessage.messageId || [])
|
|
2409
|
-
.concat(referencedMessage.inReplyTo || [])
|
|
2410
|
-
.concat((referencedMessage.headers && referencedMessage.headers.references) || [])
|
|
2411
|
-
.flatMap(line => line.split(/\s+/))
|
|
2412
|
-
.map(ref => ref.trim())
|
|
2413
|
-
.filter(ref => ref)
|
|
2414
|
-
.map(ref => {
|
|
2415
|
-
// Ensure proper Message-ID format
|
|
2416
|
-
if (!/^</.test(ref)) {
|
|
2417
|
-
ref = '<' + ref;
|
|
2418
|
-
}
|
|
2419
|
-
if (!/>$/.test(ref)) {
|
|
2420
|
-
ref = ref + '>';
|
|
2421
|
-
}
|
|
2422
|
-
return ref;
|
|
2423
|
-
});
|
|
2424
|
-
|
|
2425
|
-
references = Array.from(new Set(references));
|
|
2390
|
+
let references = buildReferences(referencedMessage);
|
|
2426
2391
|
if (references.length) {
|
|
2427
2392
|
if (!data.headers) {
|
|
2428
2393
|
data.headers = {};
|
|
@@ -2611,7 +2576,6 @@ class BaseClient {
|
|
|
2611
2576
|
response.reference = {};
|
|
2612
2577
|
if (data.reference.message) {
|
|
2613
2578
|
response.reference.message = data.reference.message;
|
|
2614
|
-
response.reference.documentStore = documentStoreUsed;
|
|
2615
2579
|
response.reference.success = referencedMessage ? true : false;
|
|
2616
2580
|
if (!referencedMessage) {
|
|
2617
2581
|
response.reference.error = 'Referenced message was not found';
|
|
@@ -2631,11 +2595,9 @@ class BaseClient {
|
|
|
2631
2595
|
let gatewayData;
|
|
2632
2596
|
if (gateway) {
|
|
2633
2597
|
let gatewayObject = new Gateway({ gateway, redis: this.redis, secret: this.secret });
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
this.logger.warn({ msg: 'Failed to load gateway data', envelope, messageId, gateway, err });
|
|
2638
|
-
}
|
|
2598
|
+
// never fall through to the account's own SMTP server when a gateway was requested:
|
|
2599
|
+
// a missing gateway throws GatewayNotFound (404)
|
|
2600
|
+
gatewayData = await gatewayObject.loadGatewayData();
|
|
2639
2601
|
}
|
|
2640
2602
|
|
|
2641
2603
|
// Verify SMTP capability
|
|
@@ -2682,7 +2644,6 @@ class BaseClient {
|
|
|
2682
2644
|
response.reference = {};
|
|
2683
2645
|
if (data.reference.message) {
|
|
2684
2646
|
response.reference.message = data.reference.message;
|
|
2685
|
-
response.reference.documentStore = documentStoreUsed;
|
|
2686
2647
|
response.reference.success = referencedMessage ? true : false;
|
|
2687
2648
|
if (!referencedMessage) {
|
|
2688
2649
|
response.reference.error = 'Referenced message was not found';
|
|
@@ -2856,11 +2817,9 @@ class BaseClient {
|
|
|
2856
2817
|
let gatewayData;
|
|
2857
2818
|
if (gateway) {
|
|
2858
2819
|
let gatewayObject = new Gateway({ gateway, redis: this.redis, secret: this.secret });
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
this.logger.warn({ msg: 'Failed to load gateway data', envelope, messageId, gateway, err });
|
|
2863
|
-
}
|
|
2820
|
+
// never fall through to the account's own SMTP server when a gateway was requested:
|
|
2821
|
+
// a missing gateway throws GatewayNotFound (404)
|
|
2822
|
+
gatewayData = await gatewayObject.loadGatewayData();
|
|
2864
2823
|
}
|
|
2865
2824
|
|
|
2866
2825
|
// Verify SMTP capability
|
|
@@ -2990,6 +2949,12 @@ class BaseClient {
|
|
|
2990
2949
|
* Gets message fetch options based on settings
|
|
2991
2950
|
* @returns {Object} Fetch options for IMAP message retrieval
|
|
2992
2951
|
*/
|
|
2952
|
+
// The provider behind this client, for the AI summary's authentication trust rule: the Gmail
|
|
2953
|
+
// and Outlook API clients each set their type, and nothing else is reachable through an API
|
|
2954
|
+
summaryProvider() {
|
|
2955
|
+
return summaryProvider({ isGmail: this.type === 'gmail', isOutlook: this.type === 'outlook' });
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2993
2958
|
async getMessageFetchOptions() {
|
|
2994
2959
|
let messageFetchOptions = {};
|
|
2995
2960
|
|
|
@@ -3010,24 +2975,11 @@ class BaseClient {
|
|
|
3010
2975
|
messageFetchOptions.headers = notifyHeaders.includes('*') ? true : notifyHeaders.length ? notifyHeaders : false;
|
|
3011
2976
|
}
|
|
3012
2977
|
|
|
3013
|
-
//
|
|
2978
|
+
// Also request the headers this path needs for its own processing, and the summary's
|
|
2979
|
+
// while summaries are on. Skipped when the setting already asks for every header
|
|
3014
2980
|
if (messageFetchOptions.headers !== true) {
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
// Headers for auto-reply detection
|
|
3018
|
-
fetchHeaders.add('x-autoreply');
|
|
3019
|
-
fetchHeaders.add('x-autorespond');
|
|
3020
|
-
fetchHeaders.add('auto-submitted');
|
|
3021
|
-
fetchHeaders.add('precedence');
|
|
3022
|
-
|
|
3023
|
-
// Headers for threading
|
|
3024
|
-
fetchHeaders.add('in-reply-to');
|
|
3025
|
-
fetchHeaders.add('references');
|
|
3026
|
-
|
|
3027
|
-
// Content type for detecting multipart/report
|
|
3028
|
-
fetchHeaders.add('content-type');
|
|
3029
|
-
|
|
3030
|
-
messageFetchOptions.fetchHeaders = Array.from(fetchHeaders);
|
|
2981
|
+
const summaryHeaders = (await llmPreProcess.getPreProcessHandler()) ? summaryFetchHeaders(this.summaryProvider()) : [];
|
|
2982
|
+
messageFetchOptions.fetchHeaders = notificationHeaderFields(messageFetchOptions.headers, summaryHeaders);
|
|
3031
2983
|
}
|
|
3032
2984
|
|
|
3033
2985
|
return messageFetchOptions;
|
|
@@ -3094,7 +3046,7 @@ class BaseClient {
|
|
|
3094
3046
|
try {
|
|
3095
3047
|
let raw = await this.getRawMessage(messageData.id);
|
|
3096
3048
|
|
|
3097
|
-
let parsed = await
|
|
3049
|
+
let parsed = await parseMessage(raw, DSN_PARSER_OPTIONS);
|
|
3098
3050
|
if (parsed) {
|
|
3099
3051
|
content = { parsed };
|
|
3100
3052
|
applyDeliveryReport(parsed, messageData, this.logger);
|
|
@@ -3152,7 +3104,7 @@ class BaseClient {
|
|
|
3152
3104
|
}
|
|
3153
3105
|
}
|
|
3154
3106
|
|
|
3155
|
-
if (bounce
|
|
3107
|
+
if (isFailedDelivery(bounce)) {
|
|
3156
3108
|
bounceNotifyInfo = Object.assign({ bounceMessage: messageData.id }, bounce);
|
|
3157
3109
|
|
|
3158
3110
|
messageData.isBounce = true;
|
|
@@ -3222,22 +3174,9 @@ class BaseClient {
|
|
|
3222
3174
|
if (notifyCalendarEvents && messageData.attachments && messageData.attachments.length) {
|
|
3223
3175
|
let calendarEventMap = new Map();
|
|
3224
3176
|
|
|
3225
|
-
//
|
|
3226
|
-
let sortCalendarAttachments = (a, b) => {
|
|
3227
|
-
if (a.contentType !== b.contentType) {
|
|
3228
|
-
if (a.contentType === 'text/calendar') {
|
|
3229
|
-
return -1;
|
|
3230
|
-
}
|
|
3231
|
-
if (b.contentType === 'text/calendar') {
|
|
3232
|
-
return 1;
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
return a.contentType.localeCompare(b.contentType);
|
|
3236
|
-
};
|
|
3237
|
-
|
|
3238
|
-
// Process calendar attachments
|
|
3177
|
+
// Process calendar attachments, text/calendar before application/ics
|
|
3239
3178
|
for (let attachment of [...messageData.attachments].sort(sortCalendarAttachments)) {
|
|
3240
|
-
if (
|
|
3179
|
+
if (CALENDAR_CONTENT_TYPES.includes(attachment.contentType)) {
|
|
3241
3180
|
if (!attachment.content) {
|
|
3242
3181
|
try {
|
|
3243
3182
|
let calendarBuf = (await this.getAttachment(attachment.id))?.data;
|
|
@@ -3249,33 +3188,15 @@ class BaseClient {
|
|
|
3249
3188
|
if (attachment.content) {
|
|
3250
3189
|
let contentBuf = Buffer.from(attachment.content, 'base64');
|
|
3251
3190
|
try {
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
const comp = new ical.Component(jcalData);
|
|
3256
|
-
if (!comp) {
|
|
3257
|
-
continue;
|
|
3258
|
-
}
|
|
3259
|
-
|
|
3260
|
-
const vevent = comp.getFirstSubcomponent('vevent');
|
|
3261
|
-
if (!vevent) {
|
|
3262
|
-
continue;
|
|
3263
|
-
}
|
|
3264
|
-
|
|
3265
|
-
// Extract method (REQUEST, CANCEL, etc.)
|
|
3266
|
-
let eventMethodProp = comp.getFirstProperty('method');
|
|
3267
|
-
let eventMethodValue = eventMethodProp ? eventMethodProp.getFirstValue() : null;
|
|
3268
|
-
|
|
3269
|
-
const event = new ical.Event(vevent);
|
|
3270
|
-
|
|
3271
|
-
if (!event || !event.uid) {
|
|
3191
|
+
const event = parseCalendarEvent(contentBuf);
|
|
3192
|
+
if (!event) {
|
|
3272
3193
|
continue;
|
|
3273
3194
|
}
|
|
3274
3195
|
|
|
3275
3196
|
// Skip if we already processed this event
|
|
3276
|
-
if (calendarEventMap.has(event.
|
|
3197
|
+
if (calendarEventMap.has(event.eventId)) {
|
|
3277
3198
|
if (attachment.filename) {
|
|
3278
|
-
let existingEntry = calendarEventMap.get(event.
|
|
3199
|
+
let existingEntry = calendarEventMap.get(event.eventId);
|
|
3279
3200
|
if (!existingEntry.filename) {
|
|
3280
3201
|
// inject filename
|
|
3281
3202
|
existingEntry.filename = attachment.filename;
|
|
@@ -3284,31 +3205,20 @@ class BaseClient {
|
|
|
3284
3205
|
continue;
|
|
3285
3206
|
}
|
|
3286
3207
|
|
|
3287
|
-
// Extract timezone information
|
|
3288
|
-
let timezone;
|
|
3289
|
-
const vtz = comp.getFirstSubcomponent('vtimezone');
|
|
3290
|
-
if (vtz) {
|
|
3291
|
-
const tz = new ical.Timezone(vtz);
|
|
3292
|
-
timezone = tz && tz.tzid;
|
|
3293
|
-
}
|
|
3294
|
-
|
|
3295
|
-
let startDate = event.startDate && event.startDate.toJSDate();
|
|
3296
|
-
let endDate = event.endDate && event.endDate.toJSDate();
|
|
3297
|
-
|
|
3298
3208
|
// Store calendar event data
|
|
3299
3209
|
calendarEventMap.set(
|
|
3300
|
-
event.
|
|
3210
|
+
event.eventId,
|
|
3301
3211
|
filterEmptyObjectValues({
|
|
3302
|
-
eventId: event.
|
|
3212
|
+
eventId: event.eventId,
|
|
3303
3213
|
attachment: attachment.id,
|
|
3304
|
-
method: attachment.method ||
|
|
3214
|
+
method: attachment.method || event.method || null,
|
|
3305
3215
|
|
|
3306
|
-
summary: event.summary
|
|
3307
|
-
description: event.description
|
|
3308
|
-
timezone: timezone
|
|
3309
|
-
startDate: startDate
|
|
3310
|
-
endDate: endDate
|
|
3311
|
-
organizer: event.organizer
|
|
3216
|
+
summary: event.summary,
|
|
3217
|
+
description: event.description,
|
|
3218
|
+
timezone: event.timezone,
|
|
3219
|
+
startDate: event.startDate,
|
|
3220
|
+
endDate: event.endDate,
|
|
3221
|
+
organizer: event.organizer,
|
|
3312
3222
|
|
|
3313
3223
|
filename: attachment.filename,
|
|
3314
3224
|
contentType: attachment.contentType,
|
|
@@ -3346,96 +3256,19 @@ class BaseClient {
|
|
|
3346
3256
|
}
|
|
3347
3257
|
}
|
|
3348
3258
|
|
|
3349
|
-
// Process with AI features for inbox messages
|
|
3350
|
-
|
|
3259
|
+
// Process with AI features for inbox messages. A message with no text part has no text
|
|
3260
|
+
// object at all, and nothing to summarize
|
|
3261
|
+
if (messageData.messageSpecialUse === '\\Inbox' && (messageData.text?.plain || messageData.text?.html)) {
|
|
3351
3262
|
let llmMessageData = Object.assign({ account: this.account }, messageData);
|
|
3352
3263
|
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
cmd: 'generateSummary',
|
|
3362
|
-
data: {
|
|
3363
|
-
message: {
|
|
3364
|
-
headers: Object.keys(messageData.headers || {}).map(key => ({ key, value: [].concat(messageData.headers[key] || []) })),
|
|
3365
|
-
attachments: messageData.attachments,
|
|
3366
|
-
from: messageData.from,
|
|
3367
|
-
subject: messageData.subject,
|
|
3368
|
-
text: messageData.text.plain,
|
|
3369
|
-
html: messageData.text.html
|
|
3370
|
-
},
|
|
3371
|
-
account: this.account
|
|
3372
|
-
},
|
|
3373
|
-
timeout: 2 * 60 * 1000
|
|
3374
|
-
});
|
|
3375
|
-
|
|
3376
|
-
if (messageData.summary) {
|
|
3377
|
-
// Clean up summary output
|
|
3378
|
-
for (let key of Object.keys(messageData.summary)) {
|
|
3379
|
-
// remove meta keys from output
|
|
3380
|
-
if (key.charAt(0) === '_' || messageData.summary[key] === '') {
|
|
3381
|
-
delete messageData.summary[key];
|
|
3382
|
-
}
|
|
3383
|
-
if (key === 'riskAssessment') {
|
|
3384
|
-
messageData.riskAssessment = messageData.summary.riskAssessment;
|
|
3385
|
-
delete messageData.summary.riskAssessment;
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
this.logger.trace({ msg: 'Fetched summary from OpenAI', summary: messageData.summary });
|
|
3390
|
-
}
|
|
3391
|
-
|
|
3392
|
-
await this.redis.del(`${REDIS_PREFIX}:openai:error`);
|
|
3393
|
-
} catch (err) {
|
|
3394
|
-
// Track OpenAI errors
|
|
3395
|
-
await this.redis.set(
|
|
3396
|
-
`${REDIS_PREFIX}:openai:error`,
|
|
3397
|
-
JSON.stringify({
|
|
3398
|
-
message: err.message,
|
|
3399
|
-
code: err.code,
|
|
3400
|
-
statusCode: err.statusCode,
|
|
3401
|
-
created: Date.now()
|
|
3402
|
-
})
|
|
3403
|
-
);
|
|
3404
|
-
this.logger.error({ msg: 'Failed to fetch summary from OpenAI', err });
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
|
|
3408
|
-
// Generate embeddings for semantic search
|
|
3409
|
-
if (canUseLLM.generateEmbeddings) {
|
|
3410
|
-
try {
|
|
3411
|
-
messageData.embeddings = await this.call({
|
|
3412
|
-
cmd: 'generateEmbeddings',
|
|
3413
|
-
data: {
|
|
3414
|
-
message: {
|
|
3415
|
-
headers: Object.keys(messageData.headers || {}).map(key => ({ key, value: [].concat(messageData.headers[key] || []) })),
|
|
3416
|
-
attachments: messageData.attachments,
|
|
3417
|
-
from: messageData.from,
|
|
3418
|
-
subject: messageData.subject,
|
|
3419
|
-
text: messageData.text.plain,
|
|
3420
|
-
html: messageData.text.html
|
|
3421
|
-
},
|
|
3422
|
-
account: this.account
|
|
3423
|
-
},
|
|
3424
|
-
timeout: 2 * 60 * 1000
|
|
3425
|
-
});
|
|
3426
|
-
} catch (err) {
|
|
3427
|
-
await this.redis.set(
|
|
3428
|
-
`${REDIS_PREFIX}:openai:error`,
|
|
3429
|
-
JSON.stringify({
|
|
3430
|
-
message: err.message,
|
|
3431
|
-
code: err.code,
|
|
3432
|
-
statusCode: err.statusCode,
|
|
3433
|
-
time: Date.now()
|
|
3434
|
-
})
|
|
3435
|
-
);
|
|
3436
|
-
this.logger.error({ msg: 'Failed to fetch embeddings from OpenAI', err });
|
|
3437
|
-
}
|
|
3438
|
-
}
|
|
3264
|
+
if (await llmPreProcess.run(llmMessageData)) {
|
|
3265
|
+
await llmPreProcess.summarize(messageData, {
|
|
3266
|
+
call: this.call,
|
|
3267
|
+
redis: this.redis,
|
|
3268
|
+
account: this.account,
|
|
3269
|
+
provider: this.summaryProvider(),
|
|
3270
|
+
logger: this.logger
|
|
3271
|
+
});
|
|
3439
3272
|
}
|
|
3440
3273
|
}
|
|
3441
3274
|
|
|
@@ -3454,11 +3287,14 @@ class BaseClient {
|
|
|
3454
3287
|
for (let attachment of messageData.attachments) {
|
|
3455
3288
|
let contentId = attachment.contentId && attachment.contentId.replace(/^<|>$/g, '');
|
|
3456
3289
|
if (contentId && cidReferences.has(contentId)) {
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3290
|
+
// An attachment the earlier inline pass already loaded is embedded as is; the
|
|
3291
|
+
// same size cap applies to anything downloaded here
|
|
3292
|
+
if (!attachment.content && !(attachment.encodedSize && attachment.encodedSize > MAX_INLINE_ATTACHMENT_SIZE)) {
|
|
3293
|
+
try {
|
|
3294
|
+
attachment.content = (await this.getAttachment(attachment.id))?.data?.toString('base64');
|
|
3295
|
+
} catch (err) {
|
|
3296
|
+
this.logger.error({ msg: 'Failed to load attachment content', attachment, err });
|
|
3297
|
+
}
|
|
3462
3298
|
}
|
|
3463
3299
|
|
|
3464
3300
|
attachmentList.set(contentId, {
|
|
@@ -3468,35 +3304,32 @@ class BaseClient {
|
|
|
3468
3304
|
}
|
|
3469
3305
|
}
|
|
3470
3306
|
|
|
3471
|
-
// Replace CID references with data URIs
|
|
3307
|
+
// Replace CID references with data URIs. The web safe copy is what webhooks deliver
|
|
3308
|
+
// in place of the HTML, so it gets the same treatment
|
|
3472
3309
|
if (attachmentList.size) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
let { attachment, content } = attachmentList.get(
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3310
|
+
const embedImages = html =>
|
|
3311
|
+
embedCidImages(html, contentId => {
|
|
3312
|
+
let { attachment, content } = attachmentList.get(contentId) || {};
|
|
3313
|
+
return content && { contentType: attachment.contentType, content };
|
|
3314
|
+
});
|
|
3315
|
+
|
|
3316
|
+
messageData.text.html = embedImages(messageData.text.html);
|
|
3317
|
+
if (messageData.text._generatedHtml) {
|
|
3318
|
+
messageData.text._generatedHtml = embedImages(messageData.text._generatedHtml);
|
|
3319
|
+
}
|
|
3482
3320
|
}
|
|
3483
3321
|
}
|
|
3484
3322
|
|
|
3485
|
-
messageData.text.
|
|
3323
|
+
if (messageData.text._generatedHtml) {
|
|
3324
|
+
messageData.text.webSafe = true;
|
|
3325
|
+
}
|
|
3486
3326
|
}
|
|
3487
3327
|
|
|
3488
|
-
//
|
|
3489
|
-
//
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
if (requestedHeaders.includes(key)) {
|
|
3494
|
-
filteredHeaders[key] = messageData.headers[key];
|
|
3495
|
-
}
|
|
3496
|
-
}
|
|
3497
|
-
messageData.headers = filteredHeaders;
|
|
3498
|
-
} else if (options.headers && requestedHeaders === false) {
|
|
3499
|
-
delete messageData.headers;
|
|
3328
|
+
// Narrow the headers to what the caller asked for. This runs last: the checks and the AI
|
|
3329
|
+
// summary above read headers fetched for them (see notificationHeaderFields()) that the
|
|
3330
|
+
// published payload may not carry
|
|
3331
|
+
if (options.headers) {
|
|
3332
|
+
narrowHeaders(messageData, requestedHeaders);
|
|
3500
3333
|
}
|
|
3501
3334
|
|
|
3502
3335
|
let path = messageData.path || this.path;
|
|
@@ -3613,7 +3446,10 @@ class BaseClient {
|
|
|
3613
3446
|
parsedContentType &&
|
|
3614
3447
|
parsedContentType.value &&
|
|
3615
3448
|
parsedContentType.value.toLowerCase().trim() === 'multipart/report' &&
|
|
3616
|
-
|
|
3449
|
+
// parameter values are case-insensitive for this one (RFC 6522)
|
|
3450
|
+
String(parsedContentType.params['report-type'] || '')
|
|
3451
|
+
.toLowerCase()
|
|
3452
|
+
.trim() === 'delivery-status'
|
|
3617
3453
|
) {
|
|
3618
3454
|
return true;
|
|
3619
3455
|
}
|
|
@@ -3769,6 +3605,10 @@ class BaseClient {
|
|
|
3769
3605
|
// Get SMTP transport from pool
|
|
3770
3606
|
const transporter = getMailTransport(smtpSettings);
|
|
3771
3607
|
|
|
3608
|
+
// Only the send itself is inside this try. Once the server has accepted the message a
|
|
3609
|
+
// failure is a bookkeeping failure: rethrowing it made the submit worker retry (and so
|
|
3610
|
+
// deliver) an already delivered message, and reported a messageDeliveryError for it
|
|
3611
|
+
let info;
|
|
3772
3612
|
try {
|
|
3773
3613
|
// Update job progress
|
|
3774
3614
|
try {
|
|
@@ -3778,104 +3618,116 @@ class BaseClient {
|
|
|
3778
3618
|
}
|
|
3779
3619
|
|
|
3780
3620
|
// Send the message
|
|
3781
|
-
|
|
3621
|
+
info = await transporter.sendMail({
|
|
3782
3622
|
envelope,
|
|
3783
3623
|
messageId,
|
|
3784
3624
|
raw: !hasBcc ? raw : await removeBcc(raw),
|
|
3785
3625
|
dsn: data.dsn || null
|
|
3786
3626
|
});
|
|
3627
|
+
} catch (err) {
|
|
3628
|
+
await this.handleSubmitError(err, {
|
|
3629
|
+
smtpSettings,
|
|
3630
|
+
networkRouting,
|
|
3631
|
+
gatewayData,
|
|
3632
|
+
gatewayObject,
|
|
3633
|
+
data,
|
|
3634
|
+
jobData,
|
|
3635
|
+
queueId,
|
|
3636
|
+
envelope
|
|
3637
|
+
});
|
|
3638
|
+
throw err;
|
|
3639
|
+
}
|
|
3787
3640
|
|
|
3788
|
-
|
|
3789
|
-
|
|
3641
|
+
// Store EHLO response for debugging
|
|
3642
|
+
if (info.ehlo) {
|
|
3643
|
+
try {
|
|
3790
3644
|
await this.redis.hSetExists(this.getAccountKey(), 'smtpServerEhlo', JSON.stringify(info.ehlo));
|
|
3645
|
+
} catch (err) {
|
|
3646
|
+
this.logger.error({ msg: 'Failed to store the SMTP server EHLO response', queueId, messageId, err });
|
|
3791
3647
|
}
|
|
3648
|
+
}
|
|
3792
3649
|
|
|
3793
|
-
|
|
3794
|
-
|
|
3650
|
+
// Handle provider-specific message ID extraction
|
|
3651
|
+
const originalMessageId = ProviderMessageIdHandler.processResponse(info, smtpSettings.host);
|
|
3795
3652
|
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3653
|
+
// Update job progress
|
|
3654
|
+
try {
|
|
3655
|
+
await submitJobEntry.updateProgress({
|
|
3656
|
+
status: 'smtp-completed',
|
|
3657
|
+
response: info.response,
|
|
3658
|
+
messageId: info.messageId,
|
|
3659
|
+
originalMessageId
|
|
3660
|
+
});
|
|
3661
|
+
} catch (err) {
|
|
3662
|
+
// ignore
|
|
3663
|
+
}
|
|
3807
3664
|
|
|
3808
|
-
|
|
3665
|
+
// Send success notification
|
|
3666
|
+
try {
|
|
3809
3667
|
await this.notify(
|
|
3810
3668
|
false,
|
|
3811
3669
|
EMAIL_SENT_NOTIFY,
|
|
3812
3670
|
NotificationBuilder.buildSuccessPayload({ info, originalMessageId, queueId, envelope, networkRouting })
|
|
3813
3671
|
);
|
|
3672
|
+
} catch (err) {
|
|
3673
|
+
this.logger.error({ msg: 'Failed to queue the messageSent notification', queueId, messageId, err });
|
|
3674
|
+
}
|
|
3814
3675
|
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
// Handle sent mail copy to folder
|
|
3823
|
-
const copyDeciderInputs = {
|
|
3824
|
-
accountData,
|
|
3825
|
-
data,
|
|
3826
|
-
isGmail: this.isGmail,
|
|
3827
|
-
isOutlook: this.isOutlook,
|
|
3828
|
-
gatewayData
|
|
3829
|
-
};
|
|
3830
|
-
const shouldCopy = SentMailCopyDecider.shouldCopy(copyDeciderInputs);
|
|
3831
|
-
|
|
3832
|
-
const connectionOptions = { allowSecondary: true };
|
|
3833
|
-
|
|
3834
|
-
const sentCopySucceeded = shouldCopy ? await this.uploadToSentFolder(raw, data, queueId, messageId, connectionOptions) : false;
|
|
3835
|
-
|
|
3836
|
-
// Remove the submitted draft. Delete it permanently when a copy of the message
|
|
3837
|
-
// exists in the Sent Mail folder - either uploaded above, or filed by the provider
|
|
3838
|
-
// itself (Gmail and Outlook store SMTP-sent messages on their own, which is also
|
|
3839
|
-
// why the upload is suppressed for them). Otherwise move the draft to Trash so the
|
|
3840
|
-
// content is not lost
|
|
3841
|
-
if (data.draft) {
|
|
3842
|
-
await this.cleanupSubmittedDraft(data.draft, {
|
|
3843
|
-
permanent: sentCopySucceeded || SentMailCopyDecider.providerSavesSentCopy(copyDeciderInputs),
|
|
3844
|
-
queueId,
|
|
3845
|
-
messageId,
|
|
3846
|
-
connectionOptions
|
|
3847
|
-
});
|
|
3848
|
-
}
|
|
3676
|
+
// Clear cached SMTP error
|
|
3677
|
+
try {
|
|
3678
|
+
await this.redis.hset(this.getAccountKey(), 'smtpStatus', JSON.stringify({ created: Date.now(), status: 'ok', response: info.response }));
|
|
3679
|
+
} catch (err) {
|
|
3680
|
+
// ignore
|
|
3681
|
+
}
|
|
3849
3682
|
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3683
|
+
// Handle sent mail copy to folder
|
|
3684
|
+
const copyDeciderInputs = {
|
|
3685
|
+
accountData,
|
|
3686
|
+
data,
|
|
3687
|
+
isGmail: this.isGmail,
|
|
3688
|
+
isOutlook: this.isOutlook,
|
|
3689
|
+
gatewayData
|
|
3690
|
+
};
|
|
3691
|
+
const shouldCopy = SentMailCopyDecider.shouldCopy(copyDeciderInputs);
|
|
3854
3692
|
|
|
3855
|
-
|
|
3856
|
-
if (data.feedbackKey) {
|
|
3857
|
-
await this.updateFeedbackKey(data.feedbackKey, true);
|
|
3858
|
-
}
|
|
3693
|
+
const connectionOptions = { allowSecondary: true };
|
|
3859
3694
|
|
|
3860
|
-
|
|
3861
|
-
if (gatewayData) {
|
|
3862
|
-
await this.updateGatewayStats(gatewayObject, queueId, messageId, reference);
|
|
3863
|
-
}
|
|
3695
|
+
const sentCopySucceeded = shouldCopy ? await this.uploadToSentFolder(raw, data, queueId, messageId, connectionOptions) : false;
|
|
3864
3696
|
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
jobData,
|
|
3697
|
+
// Remove the submitted draft. Delete it permanently when a copy of the message
|
|
3698
|
+
// exists in the Sent Mail folder - either uploaded above, or filed by the provider
|
|
3699
|
+
// itself (Gmail and Outlook store SMTP-sent messages on their own, which is also
|
|
3700
|
+
// why the upload is suppressed for them). Otherwise move the draft to Trash so the
|
|
3701
|
+
// content is not lost
|
|
3702
|
+
if (data.draft) {
|
|
3703
|
+
await this.cleanupSubmittedDraft(data.draft, {
|
|
3704
|
+
permanent: sentCopySucceeded || SentMailCopyDecider.providerSavesSentCopy(copyDeciderInputs),
|
|
3874
3705
|
queueId,
|
|
3875
|
-
|
|
3706
|
+
messageId,
|
|
3707
|
+
connectionOptions
|
|
3876
3708
|
});
|
|
3877
|
-
throw err;
|
|
3878
3709
|
}
|
|
3710
|
+
|
|
3711
|
+
// Update reference flags if needed
|
|
3712
|
+
if (reference && reference.update) {
|
|
3713
|
+
await this.updateReferenceFlags(reference, queueId, messageId, connectionOptions);
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
// Update feedback key if provided
|
|
3717
|
+
if (data.feedbackKey) {
|
|
3718
|
+
try {
|
|
3719
|
+
await this.updateFeedbackKey(data.feedbackKey, true);
|
|
3720
|
+
} catch (err) {
|
|
3721
|
+
this.logger.error({ msg: 'Failed to update the submission feedback key', queueId, messageId, err });
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3725
|
+
// Update gateway usage stats
|
|
3726
|
+
if (gatewayData) {
|
|
3727
|
+
await this.updateGatewayStats(gatewayObject, queueId, messageId, reference);
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
return { response: info.response, messageId: info.messageId };
|
|
3879
3731
|
}
|
|
3880
3732
|
|
|
3881
3733
|
/**
|
|
@@ -4074,6 +3926,8 @@ module.exports = {
|
|
|
4074
3926
|
BaseClient,
|
|
4075
3927
|
metricsMeta: postMetrics,
|
|
4076
3928
|
applyReferenceRecipients,
|
|
3929
|
+
buildReferences,
|
|
3930
|
+
isFailedDelivery,
|
|
4077
3931
|
markRejectedAccessToken,
|
|
4078
3932
|
renewRejectedAccessToken
|
|
4079
3933
|
};
|