emailengine-app 2.75.0 → 2.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +0 -10
- package/CHANGELOG.md +15 -0
- package/config/e2e.toml +1 -1
- package/data/google-crawlers.json +1 -1
- package/lib/api-routes/route-helpers.js +3 -0
- package/lib/api-routes/submit-routes.js +159 -52
- package/lib/email-client/base-client.js +164 -19
- package/lib/email-client/gmail/send-request.js +16 -1
- package/lib/email-client/gmail-client.js +89 -5
- package/lib/email-client/imap-client.js +103 -1
- package/lib/email-client/message-builder.js +24 -7
- package/lib/email-client/outlook/send-request.js +18 -1
- package/lib/email-client/outlook-client.js +79 -4
- package/package.json +13 -18
- package/playwright.config.js +1 -1
- package/sbom.json +1 -1
- package/server.js +12 -0
- package/static/licenses.html +13 -13
- package/translations/messages.pot +31 -31
- package/Gruntfile.js +0 -58
|
@@ -27,7 +27,7 @@ const {
|
|
|
27
27
|
const settings = require('../settings');
|
|
28
28
|
|
|
29
29
|
const { GMAIL_API_BASE, LIST_BATCH_SIZE, request: gmailApiRequest, executeBatchRequests } = require('./gmail/gmail-api');
|
|
30
|
-
const { buildSendRequest } = require('./gmail/send-request');
|
|
30
|
+
const { buildSendRequest, buildDraftSendRequest } = require('./gmail/send-request');
|
|
31
31
|
|
|
32
32
|
const MAX_GMAIL_BATCH_SIZE = 50;
|
|
33
33
|
|
|
@@ -69,6 +69,22 @@ function toGmailLabelId(label) {
|
|
|
69
69
|
return SYSTEM_LABELS_REV.hasOwnProperty(label) ? SYSTEM_LABELS_REV[label] : label;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// Extract the Message-ID header value (including angle brackets) from a raw RFC822 message,
|
|
73
|
+
// tolerating folded headers. Returns null if the message has no Message-ID header.
|
|
74
|
+
function extractMessageIdHeader(raw) {
|
|
75
|
+
let headerEnd = raw.indexOf('\r\n\r\n');
|
|
76
|
+
if (headerEnd < 0) {
|
|
77
|
+
headerEnd = raw.indexOf('\n\n');
|
|
78
|
+
}
|
|
79
|
+
let headerBlock = raw
|
|
80
|
+
.subarray(0, headerEnd >= 0 ? headerEnd : raw.length)
|
|
81
|
+
.toString()
|
|
82
|
+
// unfold wrapped header lines
|
|
83
|
+
.replace(/\r?\n[ \t]+/g, ' ');
|
|
84
|
+
let match = headerBlock.match(/^Message-ID:\s*(<[^>]+>)/im);
|
|
85
|
+
return match ? match[1] : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
// Timing constants for Gmail Pub/Sub watch
|
|
73
89
|
const RENEW_WATCH_TTL = 60 * 60 * 1000; // 1h - how often to check if watch needs renewal
|
|
74
90
|
const MIN_WATCH_TTL = 24 * 3600 * 1000; // 1day - minimum time before renewing watch
|
|
@@ -1536,6 +1552,64 @@ class GmailClient extends BaseClient {
|
|
|
1536
1552
|
return response;
|
|
1537
1553
|
}
|
|
1538
1554
|
|
|
1555
|
+
/**
|
|
1556
|
+
* Resolves a stored draft message for sending
|
|
1557
|
+
* Verifies that the message carries the DRAFT label, downloads its raw content and
|
|
1558
|
+
* looks up the Gmail draft resource id so the delivery step can use drafts.send
|
|
1559
|
+
* @param {string} emailId - Gmail message id of the draft
|
|
1560
|
+
* @returns {Object} { raw: Buffer, draft: { message, draftId }, threadId }
|
|
1561
|
+
*/
|
|
1562
|
+
async resolveDraftForSubmit(emailId) {
|
|
1563
|
+
await this.prepare();
|
|
1564
|
+
|
|
1565
|
+
// A single format=raw fetch provides the label check, the thread id and the raw content
|
|
1566
|
+
let messageData;
|
|
1567
|
+
try {
|
|
1568
|
+
messageData = await this.request(`${GMAIL_API_BASE}/gmail/v1/users/me/messages/${emailId}`, 'get', { format: 'raw' });
|
|
1569
|
+
} catch (err) {
|
|
1570
|
+
if (err?.oauthRequest?.status === 404 || err?.oauthRequest?.response?.error?.code === 404) {
|
|
1571
|
+
let error = new Error('Requested message was not found');
|
|
1572
|
+
error.code = 'MessageNotFound';
|
|
1573
|
+
error.statusCode = 404;
|
|
1574
|
+
throw error;
|
|
1575
|
+
}
|
|
1576
|
+
throw err;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
if (!messageData?.labelIds?.includes('DRAFT')) {
|
|
1580
|
+
let err = new Error('Requested message is not a draft');
|
|
1581
|
+
err.code = 'MessageNotDraft';
|
|
1582
|
+
err.statusCode = 400;
|
|
1583
|
+
throw err;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
let raw = messageData?.raw ? Buffer.from(messageData.raw, 'base64url') : null;
|
|
1587
|
+
if (!raw) {
|
|
1588
|
+
let err = new Error('Requested message was not found');
|
|
1589
|
+
err.code = 'MessageNotFound';
|
|
1590
|
+
err.statusCode = 404;
|
|
1591
|
+
throw err;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
// Find the draft resource that wraps this message (Gmail wraps every DRAFT-labeled
|
|
1595
|
+
// message in one, even messages.insert uploads). The lookup can still come up empty -
|
|
1596
|
+
// no Message-ID header, or the rfc822msgid search index lagging behind a fresh upload -
|
|
1597
|
+
// and such a message is sent as a raw copy instead of drafts.send at delivery time
|
|
1598
|
+
let draftId = null;
|
|
1599
|
+
let messageIdHeader = extractMessageIdHeader(raw);
|
|
1600
|
+
if (messageIdHeader) {
|
|
1601
|
+
try {
|
|
1602
|
+
let listing = await this.request(`${GMAIL_API_BASE}/gmail/v1/users/me/drafts`, 'get', { q: `rfc822msgid:${messageIdHeader}` });
|
|
1603
|
+
draftId = listing?.drafts?.find(draftEntry => draftEntry?.message?.id === emailId)?.id || null;
|
|
1604
|
+
} catch (err) {
|
|
1605
|
+
// draft id resolution is best effort - fall back to sending the raw copy
|
|
1606
|
+
this.logger.info({ msg: 'Failed to resolve Gmail draft id', emailId, err });
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
return { raw, draft: { message: emailId, draftId }, threadId: messageData?.threadId };
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1539
1613
|
/**
|
|
1540
1614
|
* Sends a message via Gmail API or SMTP gateway
|
|
1541
1615
|
* @param {Object} data - Message data
|
|
@@ -1588,12 +1662,22 @@ class GmailClient extends BaseClient {
|
|
|
1588
1662
|
return false;
|
|
1589
1663
|
}
|
|
1590
1664
|
|
|
1591
|
-
//
|
|
1592
|
-
//
|
|
1593
|
-
|
|
1665
|
+
// A resolved draft is sent through drafts.send (Gmail moves the message from Drafts to
|
|
1666
|
+
// Sent itself); everything else goes out as a raw message - endpoint, content type and
|
|
1667
|
+
// payload encoding then depend on message size and threading, see
|
|
1668
|
+
// lib/email-client/gmail/send-request.js
|
|
1669
|
+
const { targetEndpoint, contentType, payload } = data.draft?.draftId
|
|
1670
|
+
? buildDraftSendRequest(data.draft.draftId)
|
|
1671
|
+
: buildSendRequest(raw, data?.reference?.threadId);
|
|
1594
1672
|
|
|
1595
|
-
// Send via Gmail API
|
|
1596
1673
|
const submitInfo = await this.request(`${GMAIL_API_BASE}${targetEndpoint}`, 'post', payload, { contentType });
|
|
1674
|
+
|
|
1675
|
+
if (data.draft && !data.draft.draftId) {
|
|
1676
|
+
// The draft resource could not be resolved at queue time, so the draft was sent as
|
|
1677
|
+
// a raw copy - remove the original draft message (the Gmail API can only move it
|
|
1678
|
+
// to Trash)
|
|
1679
|
+
await this.cleanupSubmittedDraft(data.draft, { permanent: false, queueId, messageId });
|
|
1680
|
+
}
|
|
1597
1681
|
/*
|
|
1598
1682
|
SEND RESPONSE {
|
|
1599
1683
|
id: '18f85d2eb6adb232',
|
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
readEnvValue,
|
|
27
27
|
validUidValidity,
|
|
28
28
|
getDuration,
|
|
29
|
+
download,
|
|
29
30
|
LRUCache
|
|
30
31
|
} = require('../tools');
|
|
31
32
|
const { getLocalAddress } = require('../utils/network');
|
|
@@ -143,6 +144,14 @@ class IMAPClient extends BaseClient {
|
|
|
143
144
|
// Secondary connection for commands that shouldn't interrupt IDLE
|
|
144
145
|
this.commandClient = null;
|
|
145
146
|
|
|
147
|
+
// The client whose folder listing connect() already fetched and registered a
|
|
148
|
+
// Mailbox for. syncMailboxes() consumes it once to skip a listing refresh that
|
|
149
|
+
// would only re-issue the LIST connect() just ran. Keyed on the client rather
|
|
150
|
+
// than a plain flag so a marker that is never consumed - a setup that finished
|
|
151
|
+
// just as the account was paused - can not make an unrelated later sync, such
|
|
152
|
+
// as an operator-requested one, skip its refresh
|
|
153
|
+
this.listedClient = null;
|
|
154
|
+
|
|
146
155
|
// Flag indicating if mailbox synchronization is in progress
|
|
147
156
|
this.syncing = false;
|
|
148
157
|
|
|
@@ -908,6 +917,13 @@ class IMAPClient extends BaseClient {
|
|
|
908
917
|
// Handle flag changes
|
|
909
918
|
imapClient.on('flags', event => this.handleFlagsEvent(imapClient, event));
|
|
910
919
|
|
|
920
|
+
// The loop above registered a Mailbox for every listed folder, which is what
|
|
921
|
+
// processListing() would have done, so the sync that follows this call has
|
|
922
|
+
// nothing left to discover from a second listing. Keep the two registration
|
|
923
|
+
// paths in step - a filtering rule added to processListing() alone would never
|
|
924
|
+
// be applied during connection setup
|
|
925
|
+
this.listedClient = imapClient;
|
|
926
|
+
|
|
911
927
|
return response;
|
|
912
928
|
}
|
|
913
929
|
|
|
@@ -1179,13 +1195,37 @@ class IMAPClient extends BaseClient {
|
|
|
1179
1195
|
clearTimeout(this.resyncTimer);
|
|
1180
1196
|
clearTimeout(this.completedTimer);
|
|
1181
1197
|
|
|
1198
|
+
// Consumed unconditionally, so every later pass on this connection refreshes as
|
|
1199
|
+
// usual (see the field declaration for why this is keyed on the client)
|
|
1200
|
+
const listingIsFresh = this.listedClient === this.imapClient;
|
|
1201
|
+
this.listedClient = null;
|
|
1202
|
+
|
|
1182
1203
|
if (!this.imapClient || !this.imapClient.usable) {
|
|
1183
1204
|
this.logger.debug({ msg: 'Skipped syncing', reason: 'no imap client' });
|
|
1184
1205
|
return;
|
|
1185
1206
|
}
|
|
1186
1207
|
|
|
1187
1208
|
// Refresh folder list and sync new folders
|
|
1188
|
-
let synced
|
|
1209
|
+
let synced;
|
|
1210
|
+
if (!listingIsFresh) {
|
|
1211
|
+
try {
|
|
1212
|
+
synced = await this.refreshFolderList();
|
|
1213
|
+
} catch (err) {
|
|
1214
|
+
if (!err.responseStatus || !this.imapClient || !this.imapClient.usable || !this.mailboxes.size) {
|
|
1215
|
+
// Only a tagged command failure is tolerated. Network-level errors carry
|
|
1216
|
+
// no responseStatus and keep propagating (same rule as in mailbox.js), a
|
|
1217
|
+
// dead connection has to be re-established, and with no folder tracked
|
|
1218
|
+
// there would be nothing left to sync anyway
|
|
1219
|
+
throw err;
|
|
1220
|
+
}
|
|
1221
|
+
// The refresh only looks for folder changes - the folders already tracked
|
|
1222
|
+
// can be synced without it, and the next pass tries again. Some servers
|
|
1223
|
+
// refuse a repeated LIST on an otherwise healthy session (one Exchange-alike
|
|
1224
|
+
// answers "NO [SERVERBUG]"), and letting that throw used to tear down an
|
|
1225
|
+
// authenticated connection and reconnect on every attempt
|
|
1226
|
+
this.logger.warn({ msg: 'Failed to refresh folder list, syncing known folders', err });
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1189
1229
|
|
|
1190
1230
|
// Sync existing folders that weren't just synced
|
|
1191
1231
|
for (let mailbox of this.mailboxes.values()) {
|
|
@@ -1498,6 +1538,13 @@ class IMAPClient extends BaseClient {
|
|
|
1498
1538
|
this.imapClient = null;
|
|
1499
1539
|
}
|
|
1500
1540
|
|
|
1541
|
+
if (prevImapClient === this.listedClient) {
|
|
1542
|
+
// Only reachable when this start() returns before connect() reassigns
|
|
1543
|
+
// the marker (e.g. an account with no usable credentials). Without it
|
|
1544
|
+
// the closed client stays referenced until some later setup or sync
|
|
1545
|
+
this.listedClient = null;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1501
1548
|
// The close handler that maintains the connection count was removed
|
|
1502
1549
|
// above, so update the tracking for the replaced client manually
|
|
1503
1550
|
await this.untrackConnection(prevImapClient);
|
|
@@ -2310,6 +2357,61 @@ class IMAPClient extends BaseClient {
|
|
|
2310
2357
|
return mailbox.getAttachment(message, false, options, connectionOptions);
|
|
2311
2358
|
}
|
|
2312
2359
|
|
|
2360
|
+
/**
|
|
2361
|
+
* Resolves a stored draft message for sending
|
|
2362
|
+
* Verifies that the message is a draft and downloads its raw content
|
|
2363
|
+
* @param {string} id - API message id of the draft
|
|
2364
|
+
* @param {Object} connectionOptions - Connection options
|
|
2365
|
+
* @returns {Object} { raw: Buffer, draft: { message } }
|
|
2366
|
+
*/
|
|
2367
|
+
async resolveDraftForSubmit(id, connectionOptions) {
|
|
2368
|
+
connectionOptions = connectionOptions || { allowSecondary: true };
|
|
2369
|
+
|
|
2370
|
+
this.checkIMAPConnection(connectionOptions);
|
|
2371
|
+
|
|
2372
|
+
let buf = Buffer.from(id, 'base64url');
|
|
2373
|
+
let message = await this.unpackUid(buf.subarray(0, 8));
|
|
2374
|
+
if (!message) {
|
|
2375
|
+
let err = new Error('Requested message was not found');
|
|
2376
|
+
err.code = 'MessageNotFound';
|
|
2377
|
+
err.statusCode = 404;
|
|
2378
|
+
throw err;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
// The message counts as a draft when it is stored in the Drafts folder or carries
|
|
2382
|
+
// the \Draft flag (covers accounts that keep drafts in a non-special-use folder)
|
|
2383
|
+
const inDraftsFolder = this.mailboxes.get(normalizePath(message.path))?.listingEntry?.specialUse === '\\Drafts';
|
|
2384
|
+
if (!inDraftsFolder) {
|
|
2385
|
+
// fetch flags only - nothing else from the message is needed for the check
|
|
2386
|
+
let messageData = await this.getMessage(id, { fields: { uid: true, flags: true } }, connectionOptions);
|
|
2387
|
+
if (!messageData) {
|
|
2388
|
+
let err = new Error('Requested message was not found');
|
|
2389
|
+
err.code = 'MessageNotFound';
|
|
2390
|
+
err.statusCode = 404;
|
|
2391
|
+
throw err;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
if (!(messageData.flags || []).includes('\\Draft')) {
|
|
2395
|
+
let err = new Error('Requested message is not a draft');
|
|
2396
|
+
err.code = 'MessageNotDraft';
|
|
2397
|
+
err.statusCode = 400;
|
|
2398
|
+
throw err;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
let rawStream = await this.getRawMessage(id, {}, connectionOptions);
|
|
2403
|
+
if (!rawStream) {
|
|
2404
|
+
let err = new Error('Requested message was not found');
|
|
2405
|
+
err.code = 'MessageNotFound';
|
|
2406
|
+
err.statusCode = 404;
|
|
2407
|
+
throw err;
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
let raw = await download(rawStream);
|
|
2411
|
+
|
|
2412
|
+
return { raw, draft: { message: id } };
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2313
2415
|
/**
|
|
2314
2416
|
* Lists messages in a mailbox with pagination and search
|
|
2315
2417
|
* @param {Object} options - Listing options including path, search criteria, pagination
|
|
@@ -511,6 +511,27 @@ class SmtpErrorBuilder {
|
|
|
511
511
|
* Determines whether to copy sent message to Sent folder
|
|
512
512
|
*/
|
|
513
513
|
class SentMailCopyDecider {
|
|
514
|
+
/**
|
|
515
|
+
* Whether the provider files SMTP-submitted messages into the Sent Mail folder on its
|
|
516
|
+
* own. True for Gmail and for non-delegated Outlook when no gateway is used - both store
|
|
517
|
+
* the sent message themselves, so an upload would duplicate it. Emails for delegated
|
|
518
|
+
* Outlook accounts are still uploaded as the sender is different (SMTP is disabled for
|
|
519
|
+
* shared mailboxes, so the message is sent using the main account).
|
|
520
|
+
* @param {Object} options - Decision options
|
|
521
|
+
* @param {Object} options.accountData - Account data
|
|
522
|
+
* @param {boolean} options.isGmail - Whether account is Gmail
|
|
523
|
+
* @param {boolean} options.isOutlook - Whether account is Outlook
|
|
524
|
+
* @param {Object} options.gatewayData - Gateway data if using gateway
|
|
525
|
+
* @returns {boolean} Whether the provider stores the sent copy itself
|
|
526
|
+
*/
|
|
527
|
+
static providerSavesSentCopy(options) {
|
|
528
|
+
const { accountData, isGmail, isOutlook, gatewayData } = options;
|
|
529
|
+
|
|
530
|
+
const skipIfOutlook = isOutlook && (!accountData.oauth2 || !accountData.oauth2.auth || !accountData.oauth2.auth.delegatedUser);
|
|
531
|
+
|
|
532
|
+
return Boolean((isGmail || skipIfOutlook) && !gatewayData);
|
|
533
|
+
}
|
|
534
|
+
|
|
514
535
|
/**
|
|
515
536
|
* Determines if sent mail should be copied to Sent folder
|
|
516
537
|
* @param {Object} options - Decision options
|
|
@@ -522,7 +543,7 @@ class SentMailCopyDecider {
|
|
|
522
543
|
* @returns {boolean} Whether to copy to Sent folder
|
|
523
544
|
*/
|
|
524
545
|
static shouldCopy(options) {
|
|
525
|
-
const { accountData, data
|
|
546
|
+
const { accountData, data } = options;
|
|
526
547
|
|
|
527
548
|
// The default is to copy message to Sent Mail folder
|
|
528
549
|
let shouldCopy = !Object.prototype.hasOwnProperty.call(accountData, 'copy');
|
|
@@ -532,14 +553,10 @@ class SentMailCopyDecider {
|
|
|
532
553
|
shouldCopy = accountData.copy;
|
|
533
554
|
}
|
|
534
555
|
|
|
535
|
-
// Suppress uploads
|
|
556
|
+
// Suppress uploads when the provider stores the sent copy itself.
|
|
536
557
|
// Unfortunately, previous default schema for all added accounts was copy=true,
|
|
537
558
|
// so can't prefer account specific setting here
|
|
538
|
-
|
|
539
|
-
// SMTP is disabled for shared mailboxes, so we need to send using the main account.
|
|
540
|
-
const skipIfOutlook = isOutlook && (!accountData.oauth2 || !accountData.oauth2.auth || !accountData.oauth2.auth.delegatedUser);
|
|
541
|
-
|
|
542
|
-
if ((isGmail || skipIfOutlook) && !gatewayData) {
|
|
559
|
+
if (this.providerSavesSentCopy(options)) {
|
|
543
560
|
shouldCopy = false;
|
|
544
561
|
}
|
|
545
562
|
|
|
@@ -45,4 +45,21 @@ function buildStructuredSendMailRequest(messagePayload, oauth2UserPath) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Builds the request that sends an existing draft message. Graph requires an empty body
|
|
50
|
+
* (Content-Length: 0), answers 202 Accepted, and files the message into Sent Items itself.
|
|
51
|
+
*
|
|
52
|
+
* @param {String} emailId - Graph message id of the draft
|
|
53
|
+
* @param {String} oauth2UserPath - Graph user path ("me" or "users/<id>")
|
|
54
|
+
* @returns {Object} { path, body, options } for OutlookOauth.request()
|
|
55
|
+
*/
|
|
56
|
+
function buildDraftSendRequest(emailId, oauth2UserPath) {
|
|
57
|
+
return {
|
|
58
|
+
path: `/${oauth2UserPath}/messages/${emailId}/send`,
|
|
59
|
+
// An empty Buffer keeps the request body at Content-Length: 0
|
|
60
|
+
body: Buffer.alloc(0),
|
|
61
|
+
options: { returnText: true }
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { buildRawSendMailRequest, buildStructuredSendMailRequest, buildDraftSendRequest };
|
|
@@ -16,7 +16,7 @@ const { detectMimeType, detectExtension } = require('nodemailer/lib/mime-funcs/m
|
|
|
16
16
|
|
|
17
17
|
// Import Graph API module for MS Graph API handling
|
|
18
18
|
const graphApi = require('./outlook/graph-api');
|
|
19
|
-
const { buildRawSendMailRequest, buildStructuredSendMailRequest } = require('./outlook/send-request');
|
|
19
|
+
const { buildRawSendMailRequest, buildStructuredSendMailRequest, buildDraftSendRequest } = require('./outlook/send-request');
|
|
20
20
|
|
|
21
21
|
const {
|
|
22
22
|
REDIS_PREFIX,
|
|
@@ -2379,6 +2379,50 @@ class OutlookClient extends BaseClient {
|
|
|
2379
2379
|
* Send an email message
|
|
2380
2380
|
* Can use either Graph API sendMail endpoint or fall back to SMTP
|
|
2381
2381
|
*/
|
|
2382
|
+
/**
|
|
2383
|
+
* Resolves a stored draft message for sending
|
|
2384
|
+
* Verifies that the message is a Graph draft and downloads its raw content
|
|
2385
|
+
* @param {string} emailId - Graph message id of the draft
|
|
2386
|
+
* @returns {Object} { raw: Buffer, draft: { message } }
|
|
2387
|
+
*/
|
|
2388
|
+
async resolveDraftForSubmit(emailId) {
|
|
2389
|
+
await this.prepare();
|
|
2390
|
+
|
|
2391
|
+
// The draft check and the raw download have no data dependency, so run them in parallel
|
|
2392
|
+
let messageData;
|
|
2393
|
+
let raw;
|
|
2394
|
+
try {
|
|
2395
|
+
[messageData, raw] = await Promise.all([
|
|
2396
|
+
this.request(`/${this.oauth2UserPath}/messages/${emailId}`, 'get', { $select: 'id,isDraft' }),
|
|
2397
|
+
this.getRawMessage(emailId)
|
|
2398
|
+
]);
|
|
2399
|
+
} catch (err) {
|
|
2400
|
+
if (err.oauthRequest?.status === 404 || err.code === 'NotFound') {
|
|
2401
|
+
let error = new Error('Requested message was not found');
|
|
2402
|
+
error.code = 'MessageNotFound';
|
|
2403
|
+
error.statusCode = 404;
|
|
2404
|
+
throw error;
|
|
2405
|
+
}
|
|
2406
|
+
throw err;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
if (!messageData?.isDraft) {
|
|
2410
|
+
let err = new Error('Requested message is not a draft');
|
|
2411
|
+
err.code = 'MessageNotDraft';
|
|
2412
|
+
err.statusCode = 400;
|
|
2413
|
+
throw err;
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
if (!raw) {
|
|
2417
|
+
let err = new Error('Requested message was not found');
|
|
2418
|
+
err.code = 'MessageNotFound';
|
|
2419
|
+
err.statusCode = 404;
|
|
2420
|
+
throw err;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
return { raw, draft: { message: emailId } };
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2382
2426
|
async submitMessage(data) {
|
|
2383
2427
|
await this.prepare();
|
|
2384
2428
|
|
|
@@ -2426,9 +2470,40 @@ class OutlookClient extends BaseClient {
|
|
|
2426
2470
|
return false;
|
|
2427
2471
|
}
|
|
2428
2472
|
|
|
2429
|
-
//
|
|
2430
|
-
//
|
|
2431
|
-
|
|
2473
|
+
// Three delivery shapes: an existing draft is sent via /messages/{id}/send, otherwise
|
|
2474
|
+
// the message goes through /sendMail as raw MIME (default - preserves calendar invites
|
|
2475
|
+
// and special MIME types) or as a structured JSON message (opt-in - respects the from
|
|
2476
|
+
// field for shared mailboxes)
|
|
2477
|
+
if (data.draft) {
|
|
2478
|
+
// Send the existing draft message - Graph files it into Sent Items itself
|
|
2479
|
+
try {
|
|
2480
|
+
let sendRequest = buildDraftSendRequest(data.draft.message, this.oauth2UserPath);
|
|
2481
|
+
await this.request(sendRequest.path, 'post', sendRequest.body, sendRequest.options);
|
|
2482
|
+
} catch (err) {
|
|
2483
|
+
switch (err.oauthRequest?.status) {
|
|
2484
|
+
case 400:
|
|
2485
|
+
case 404: {
|
|
2486
|
+
// the draft is gone or not sendable - retrying would not help
|
|
2487
|
+
let error = new Error(err.oauthRequest.status === 404 ? 'Draft message was not found' : 'Draft message can not be sent');
|
|
2488
|
+
error.info = {
|
|
2489
|
+
response: err.oauthRequest?.response?.error?.message || error.message
|
|
2490
|
+
};
|
|
2491
|
+
error.code = err.oauthRequest?.response?.error?.code || 'MessageNotFound';
|
|
2492
|
+
error.statusCode = 500; // do not retry sending
|
|
2493
|
+
throw error;
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
default:
|
|
2497
|
+
this.logger.error({
|
|
2498
|
+
msg: 'Failed to submit draft message',
|
|
2499
|
+
messageId,
|
|
2500
|
+
draft: data.draft.message,
|
|
2501
|
+
err
|
|
2502
|
+
});
|
|
2503
|
+
throw err;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
} else if (data.useStructuredFormat) {
|
|
2432
2507
|
// Parse raw message into structured format to properly handle 'from' address
|
|
2433
2508
|
// Microsoft Graph API ignores the From header in raw MIME messages and uses
|
|
2434
2509
|
// the authenticated user's address instead. By parsing and sending as structured
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emailengine-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.76.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"productTitle": "EmailEngine",
|
|
6
6
|
"description": "Email Sync Engine",
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
"dev": "EE_OPENAPI_VERBOSE=true EENGINE_LOG_RAW=true node --tls-keylog=keylog.txt server --dbs.redis='redis://127.0.0.1:6379/9' --api.port=7003 --api.host=0.0.0.0 | tee $HOME/ee.log.dev.txt | pino-pretty",
|
|
12
12
|
"single": "EE_OPENAPI_VERBOSE=true EENGINE_LOG_RAW=true EENGINE_SECRET=your-encryption-key EENGINE_WORKERS=1 node --inspect server --dbs.redis='redis://127.0.0.1:6379/6' --api.port=7003 --api.host=0.0.0.0 | tee $HOME/ee.log.single.txt | pino-pretty",
|
|
13
13
|
"gmail": "EE_OPENAPI_VERBOSE=true EENGINE_LOG_RAW=true EENGINE_SECRET=your-encryption-key EENGINE_WORKERS=2 EENGINE_CORS_ORIGIN='*' node --inspect server --dbs.redis='redis://127.0.0.1:6379/11' --api.port=7003 --api.host=0.0.0.0 | tee $HOME/ee.log.gmail.txt | pino-pretty",
|
|
14
|
-
"test": "
|
|
15
|
-
"test:unit": "NODE_ENV=test
|
|
16
|
-
"test:integration": "NODE_ENV=test
|
|
14
|
+
"test": "npm run lint:src && npm run test:unit && npm run test:integration",
|
|
15
|
+
"test:unit": "NODE_ENV=test node test/run-tests.js unit",
|
|
16
|
+
"test:integration": "NODE_ENV=test node test/run-tests.js integration",
|
|
17
17
|
"test:dovecot": "./test/dovecot/run-dovecot-tests.sh",
|
|
18
18
|
"test:e2e": "playwright test",
|
|
19
19
|
"test:e2e:install": "playwright install --with-deps chromium",
|
|
20
|
-
"lint": "npx eslint 'lib/**/*.js' 'workers/**/*.js' 'test/**/*.js' server.js
|
|
20
|
+
"lint": "npx eslint 'lib/**/*.js' 'workers/**/*.js' 'test/**/*.js' server.js",
|
|
21
|
+
"lint:src": "npx eslint 'lib/**/*.js' 'workers/**/*.js' server.js",
|
|
21
22
|
"swagger": "./getswagger.sh",
|
|
22
23
|
"build:css": "tailwindcss -i static/css/src/app.tailwind.css -o static/css/flyonui.css --minify",
|
|
23
24
|
"build-source": "rm -rf node_modules && npm install && rm -rf node_modules && npm ci --omit=dev && rm -rf node_modules/ace-builds node_modules/@postalsys/ee-client && ./update-info.sh",
|
|
@@ -49,8 +50,8 @@
|
|
|
49
50
|
},
|
|
50
51
|
"homepage": "https://emailengine.app/",
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@bull-board/api": "8.
|
|
53
|
-
"@bull-board/hapi": "8.
|
|
53
|
+
"@bull-board/api": "8.4.0",
|
|
54
|
+
"@bull-board/hapi": "8.4.0",
|
|
54
55
|
"@elastic/elasticsearch": "8.15.3",
|
|
55
56
|
"@hapi/accept": "6.0.3",
|
|
56
57
|
"@hapi/bell": "13.1.0",
|
|
@@ -65,12 +66,12 @@
|
|
|
65
66
|
"@postalsys/certs": "1.0.16",
|
|
66
67
|
"@postalsys/ee-client": "1.6.0",
|
|
67
68
|
"@postalsys/email-ai-tools": "1.13.15",
|
|
68
|
-
"@postalsys/email-content": "0.1.
|
|
69
|
+
"@postalsys/email-content": "0.1.2",
|
|
69
70
|
"@postalsys/email-text-tools": "2.4.11",
|
|
70
71
|
"@postalsys/gettext": "4.1.1",
|
|
71
72
|
"@postalsys/joi-messages": "1.0.5",
|
|
72
73
|
"@postalsys/templates": "2.0.1",
|
|
73
|
-
"@sentry/node": "10.
|
|
74
|
+
"@sentry/node": "10.69.0",
|
|
74
75
|
"@simplewebauthn/browser": "13.3.0",
|
|
75
76
|
"@simplewebauthn/server": "13.3.2",
|
|
76
77
|
"@zone-eu/mailsplit": "5.4.14",
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"html-to-text": "10.0.0",
|
|
92
93
|
"ical.js": "1.5.0",
|
|
93
94
|
"iconv-lite": "0.7.3",
|
|
94
|
-
"imapflow": "1.6.
|
|
95
|
+
"imapflow": "1.6.5",
|
|
95
96
|
"ioredfour": "1.4.2",
|
|
96
97
|
"ioredis": "5.11.1",
|
|
97
98
|
"ipaddr.js": "2.4.0",
|
|
@@ -121,7 +122,7 @@
|
|
|
121
122
|
},
|
|
122
123
|
"devDependencies": {
|
|
123
124
|
"@eslint/js": "10.0.1",
|
|
124
|
-
"@iconify-json/tabler": "1.2.
|
|
125
|
+
"@iconify-json/tabler": "1.2.38",
|
|
125
126
|
"@iconify/tailwind4": "1.2.3",
|
|
126
127
|
"@playwright/test": "1.62.0",
|
|
127
128
|
"@tailwindcss/cli": "4.3.3",
|
|
@@ -131,9 +132,6 @@
|
|
|
131
132
|
"eerawlog": "1.5.5",
|
|
132
133
|
"eslint": "10.8.0",
|
|
133
134
|
"flyonui": "2.4.1",
|
|
134
|
-
"grunt": "1.6.3",
|
|
135
|
-
"grunt-cli": "1.5.0",
|
|
136
|
-
"grunt-shell-spawn": "0.5.0",
|
|
137
135
|
"pino-pretty": "13.1.3",
|
|
138
136
|
"prettier": "3.9.6",
|
|
139
137
|
"resedit": "3.0.2",
|
|
@@ -143,10 +141,7 @@
|
|
|
143
141
|
"xgettext-template": "5.0.0"
|
|
144
142
|
},
|
|
145
143
|
"overrides": {
|
|
146
|
-
"@asamuzakjp/css-color": "4.1.1"
|
|
147
|
-
"grunt": {
|
|
148
|
-
"js-yaml": "3.15.0"
|
|
149
|
-
}
|
|
144
|
+
"@asamuzakjp/css-color": "4.1.1"
|
|
150
145
|
},
|
|
151
146
|
"engines": {
|
|
152
147
|
"node": ">=20.x"
|
package/playwright.config.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = defineConfig({
|
|
|
30
30
|
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
|
31
31
|
webServer: {
|
|
32
32
|
// Flush the isolated e2e Redis DB so every run starts from a clean, unconfigured instance.
|
|
33
|
-
command: 'node test/
|
|
33
|
+
command: 'node test/helpers/flush-redis.js && node server.js',
|
|
34
34
|
url: BASE_URL,
|
|
35
35
|
timeout: 120000,
|
|
36
36
|
// Always boot fresh: the suite asserts fresh-instance behaviour (enabling auth, activating
|