emailengine-app 2.79.0 → 2.79.2
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 +79 -0
- package/bin/emailengine.js +8 -1
- package/config/default.toml +6 -0
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +137 -19
- package/lib/api-routes/account-routes.js +13 -1
- package/lib/api-routes/index.js +12 -0
- package/lib/api-routes/mailbox-routes.js +6 -0
- package/lib/api-routes/mcp-oauth-routes.js +259 -0
- package/lib/api-routes/mcp-routes.js +172 -0
- package/lib/api-routes/message-routes.js +125 -4
- package/lib/api-routes/outbox-routes.js +7 -0
- package/lib/api-routes/permission-map.js +101 -1
- package/lib/api-routes/route-helpers.js +87 -4
- package/lib/api-routes/route-metadata.js +24 -4
- package/lib/api-routes/settings-routes.js +37 -14
- package/lib/api-routes/submit-routes.js +41 -0
- package/lib/api-routes/template-routes.js +7 -0
- package/lib/api-routes/token-routes.js +292 -122
- package/lib/arf-detect.js +17 -4
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +36 -1
- package/lib/db.js +6 -0
- package/lib/email-client/base-client.js +102 -117
- package/lib/email-client/gmail-client.js +91 -29
- package/lib/email-client/imap/mailbox.js +175 -101
- package/lib/email-client/imap-client.js +49 -2
- package/lib/email-client/outlook-client.js +20 -24
- package/lib/enum-descriptions.js +2 -1
- package/lib/field-usage.js +17 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/lua/s-list-accounts.lua +5 -2
- package/lib/mcp/index.js +29 -0
- package/lib/mcp/inject.js +70 -0
- package/lib/mcp/json-schema.js +120 -0
- package/lib/mcp/listen.js +171 -0
- package/lib/mcp/oauth.js +324 -0
- package/lib/mcp/protocol.js +489 -0
- package/lib/mcp/resources.js +139 -0
- package/lib/mcp/tools.js +655 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/oauth2-apps.js +84 -15
- package/lib/openapi/build-document.js +5 -1
- package/lib/openapi/index.js +3 -1
- package/lib/response-stream.js +52 -21
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +26 -5
- package/lib/settings.js +23 -9
- package/lib/token-audit-log.js +32 -9
- package/lib/token-permission-view.js +104 -8
- package/lib/tokens.js +194 -68
- package/lib/tools.js +96 -0
- package/lib/ui-routes/account-routes.js +55 -6
- package/lib/ui-routes/admin-config-routes.js +114 -1
- package/lib/ui-routes/admin-entities-routes.js +103 -19
- package/lib/ui-routes/auth-routes.js +13 -0
- package/lib/ui-routes/mcp-consent-routes.js +330 -0
- package/lib/ui-routes/oauth-config-routes.js +7 -7
- package/lib/ui-routes/route-helpers.js +143 -1
- package/lib/ui-routes/suppression-list-routes.js +14 -9
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +9 -1
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +61 -0
- package/lib/webhook-routing.js +6 -2
- package/lib/webhooks.js +31 -8
- package/package.json +9 -8
- package/sbom.json +1 -1
- package/scripts/README.md +25 -0
- package/scripts/build-icon.js +77 -0
- package/server.js +39 -17
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +98 -0
- package/static/emailengine.ico +0 -0
- package/static/js/ui.js +465 -1
- package/static/licenses.html +42 -22
- package/translations/messages.pot +57 -57
- package/views/accounts/account.hbs +8 -8
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +2 -2
- package/views/config/mcp.hbs +361 -0
- package/views/config/oauth/index.hbs +7 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/layout/prompt.hbs +62 -0
- package/views/mcp/authorize.hbs +136 -0
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/head_assets.hbs +3 -3
- package/views/partials/mcp_access_levels.hbs +13 -0
- package/views/partials/mcp_account_limit.hbs +14 -0
- package/views/partials/mcp_tool_count.hbs +19 -0
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/account-picker.hbs +59 -0
- package/views/partials/ui/code-block.hbs +26 -0
- package/views/partials/ui/menu-item.hbs +5 -0
- package/views/partials/ui/radio.hbs +41 -0
- package/views/partials/ui/tab.hbs +15 -10
- package/views/partials/ui/tabs.hbs +8 -5
- package/views/suppression-lists/list.hbs +1 -1
- package/views/templates/index.hbs +2 -2
- package/views/templates/template.hbs +5 -4
- package/views/tokens/index.hbs +30 -4
- package/views/tokens/new.hbs +517 -239
- package/winconf.js +148 -48
- package/workers/api.js +239 -95
- package/workers/imap.js +65 -72
- package/workers/webhooks.js +21 -1
package/workers/imap.js
CHANGED
|
@@ -19,7 +19,7 @@ const { BaseClient } = require('../lib/email-client/base-client');
|
|
|
19
19
|
const { Account } = require('../lib/account');
|
|
20
20
|
const { oauth2Apps, isApiBasedApp } = require('../lib/oauth2-apps');
|
|
21
21
|
const { redis, notifyQueue, submitQueue, documentsQueue, getFlowProducer } = require('../lib/db');
|
|
22
|
-
const {
|
|
22
|
+
const { sendToMessagePort, MessagePortWritable } = require('../lib/message-port-stream');
|
|
23
23
|
const { packRpcError, unpackRpcError } = require('../lib/worker-rpc-error');
|
|
24
24
|
const { getESClient } = require('../lib/document-store');
|
|
25
25
|
const settings = require('../lib/settings');
|
|
@@ -741,89 +741,82 @@ class ConnectionHandler {
|
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
async getRawMessage(message) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
744
|
+
// Built before the fetch rather than after it: the fetch can take minutes, and a consumer
|
|
745
|
+
// whose thread dies in the meantime closes the port with nothing queued, which only reaches
|
|
746
|
+
// a listener that was already attached. See the MessagePortWritable constructor.
|
|
747
|
+
const writable = new MessagePortWritable(message.port);
|
|
748
|
+
try {
|
|
749
|
+
if (!this.accounts.has(message.account)) {
|
|
750
|
+
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
751
|
+
}
|
|
747
752
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
753
|
+
let accountData = this.accounts.get(message.account);
|
|
754
|
+
if (!accountData.connection) {
|
|
755
|
+
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
756
|
+
}
|
|
757
|
+
let source = await accountData.connection.getRawMessage(message.message);
|
|
758
|
+
if (!source) {
|
|
759
|
+
let err = new Error('Requested file not found');
|
|
760
|
+
err.statusCode = 404;
|
|
761
|
+
throw err;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
sendToMessagePort(writable, source, accountData.connection.logger);
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
headers: {
|
|
768
|
+
'content-type': 'message/rfc822',
|
|
769
|
+
'content-disposition': `attachment; filename=message.eml`
|
|
770
|
+
},
|
|
771
|
+
contentType: 'message/rfc822'
|
|
772
|
+
};
|
|
773
|
+
} catch (err) {
|
|
774
|
+
// Nothing to send, so the port goes back untouched - the consumer is about to be handed
|
|
775
|
+
// this error, and a closed port would reach it as a failed transfer instead.
|
|
776
|
+
writable.releaseListeners();
|
|
756
777
|
throw err;
|
|
757
778
|
}
|
|
779
|
+
}
|
|
758
780
|
|
|
759
|
-
|
|
760
|
-
//
|
|
761
|
-
//
|
|
762
|
-
|
|
781
|
+
async getAttachment(message) {
|
|
782
|
+
// Built before the download starts, not after: an attachment is the longest wait on this
|
|
783
|
+
// worker, and a consumer thread that dies during it closes the port with nothing queued -
|
|
784
|
+
// which only a listener attached beforehand ever sees. See the MessagePortWritable
|
|
785
|
+
// constructor.
|
|
786
|
+
const writable = new MessagePortWritable(message.port);
|
|
787
|
+
try {
|
|
788
|
+
if (!this.accounts.has(message.account)) {
|
|
789
|
+
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
790
|
+
}
|
|
763
791
|
|
|
764
|
-
|
|
765
|
-
if (
|
|
766
|
-
|
|
767
|
-
// message) before this runs; ending a destroyed stream would emit an
|
|
768
|
-
// unhandled 'error' and take down the worker. The streaming branch is
|
|
769
|
-
// safe because pipeline() tears down a destroyed destination cleanly.
|
|
770
|
-
if (!stream.destroyed) {
|
|
771
|
-
stream.end(source);
|
|
772
|
-
}
|
|
773
|
-
} else {
|
|
774
|
-
pipeToMessagePort(source, stream, accountData.connection.logger);
|
|
792
|
+
let accountData = this.accounts.get(message.account);
|
|
793
|
+
if (!accountData.connection) {
|
|
794
|
+
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
775
795
|
}
|
|
776
|
-
});
|
|
777
796
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
'
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
};
|
|
785
|
-
}
|
|
797
|
+
let source = await accountData.connection.getAttachment(message.attachment);
|
|
798
|
+
if (!source) {
|
|
799
|
+
let err = new Error('Requested file not found');
|
|
800
|
+
err.statusCode = 404;
|
|
801
|
+
throw err;
|
|
802
|
+
}
|
|
786
803
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
804
|
+
// IMAP resolves an attachment to the download stream itself, Gmail and Graph to a Buffer
|
|
805
|
+
// wrapped alongside the headers.
|
|
806
|
+
let payload = Buffer.isBuffer(source.data) ? source.data : source;
|
|
791
807
|
|
|
792
|
-
|
|
793
|
-
if (!accountData.connection) {
|
|
794
|
-
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
795
|
-
}
|
|
808
|
+
sendToMessagePort(writable, payload, accountData.connection.logger);
|
|
796
809
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
810
|
+
return {
|
|
811
|
+
headers: source.headers,
|
|
812
|
+
contentType: source.contentType
|
|
813
|
+
};
|
|
814
|
+
} catch (err) {
|
|
815
|
+
// Nothing to send, so the port goes back untouched - the consumer is about to be handed
|
|
816
|
+
// this error, and a closed port would reach it as a failed transfer instead.
|
|
817
|
+
writable.releaseListeners();
|
|
801
818
|
throw err;
|
|
802
819
|
}
|
|
803
|
-
|
|
804
|
-
// Build the cross-thread writable only after we know there is content to send.
|
|
805
|
-
// Constructing it earlier leaks the transferred MessagePort (and its message
|
|
806
|
-
// listener) whenever the lookup above throws (e.g. a 404).
|
|
807
|
-
let stream = new MessagePortWritable(message.port);
|
|
808
|
-
|
|
809
|
-
setImmediate(() => {
|
|
810
|
-
if (Buffer.isBuffer(source.data)) {
|
|
811
|
-
// The consumer may have aborted and destroyed the writable (via a cancel
|
|
812
|
-
// message) before this runs; ending a destroyed stream would emit an
|
|
813
|
-
// unhandled 'error' and take down the worker. The streaming branch is
|
|
814
|
-
// safe because pipeline() tears down a destroyed destination cleanly.
|
|
815
|
-
if (!stream.destroyed) {
|
|
816
|
-
stream.end(source.data);
|
|
817
|
-
}
|
|
818
|
-
} else {
|
|
819
|
-
pipeToMessagePort(source, stream, accountData.connection.logger);
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
return {
|
|
824
|
-
headers: source.headers,
|
|
825
|
-
contentType: source.contentType
|
|
826
|
-
};
|
|
827
820
|
}
|
|
828
821
|
|
|
829
822
|
// Shutdown teardown: closes every account connection this worker owns. The main thread owns
|
package/workers/webhooks.js
CHANGED
|
@@ -227,6 +227,15 @@ const notifyWorker = new Worker(
|
|
|
227
227
|
|
|
228
228
|
let webhooksEnabled = await settings.get('webhooksEnabled');
|
|
229
229
|
if (!webhooksEnabled) {
|
|
230
|
+
logger.debug({
|
|
231
|
+
msg: 'Webhooks are disabled',
|
|
232
|
+
action: 'webhook',
|
|
233
|
+
queue: job.queue.name,
|
|
234
|
+
code: 'webhooks_disabled',
|
|
235
|
+
job: job.id,
|
|
236
|
+
event: job.name,
|
|
237
|
+
account: job.data.account
|
|
238
|
+
});
|
|
230
239
|
return;
|
|
231
240
|
}
|
|
232
241
|
|
|
@@ -246,7 +255,18 @@ const notifyWorker = new Worker(
|
|
|
246
255
|
// the global setting is only fetched when neither a custom route nor the account override decides the target
|
|
247
256
|
let webhooks = resolveTargetUrl(customRoute && customRoute.targetUrl, accountWebhooks, null).url || (await settings.get('webhooks'));
|
|
248
257
|
if (!webhooks) {
|
|
249
|
-
//
|
|
258
|
+
// A skipped delivery still reports the job as completed, so without this line a
|
|
259
|
+
// missing target is indistinguishable from a successful delivery - it reads as the
|
|
260
|
+
// receiver being slow rather than as nothing having been sent
|
|
261
|
+
logger.debug({
|
|
262
|
+
msg: 'Webhook URL is not set',
|
|
263
|
+
action: 'webhook',
|
|
264
|
+
queue: job.queue.name,
|
|
265
|
+
code: 'no_target_url',
|
|
266
|
+
job: job.id,
|
|
267
|
+
event: job.name,
|
|
268
|
+
account: job.data.account
|
|
269
|
+
});
|
|
250
270
|
return;
|
|
251
271
|
}
|
|
252
272
|
|