Skip to content

Commit b04d0fe

Browse files
committed
fix(websafe): Process web safe HTML before injecting base64 attachments to speed the process up
1 parent fb3e593 commit b04d0fe

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

Diff for: lib/account.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,18 @@ class Account {
13821382
}
13831383
}
13841384

1385+
if (options.preProcessHtml && messageData.text && (messageData.text.html || messageData.text.plain)) {
1386+
// If available, use the cached version
1387+
messageData.text.html =
1388+
messageData.text._generatedHtml ||
1389+
mimeHtml({
1390+
html: messageData.text.html,
1391+
text: messageData.text.plain
1392+
});
1393+
messageData.text.webSafe = true;
1394+
messageData.text._cachedWebSafe = !!messageData.text._generatedHtml;
1395+
}
1396+
13851397
if (options.embedAttachedImages && messageData.text && messageData.text.html && messageData.attachments && messageData.attachments.length) {
13861398
let attachmentsToDownload = [];
13871399

@@ -1417,18 +1429,6 @@ class Account {
14171429
});
14181430
}
14191431

1420-
if (options.preProcessHtml && messageData.text && (messageData.text.html || messageData.text.plain)) {
1421-
// If available, use the cached version
1422-
messageData.text.html =
1423-
messageData.text._generatedHtml ||
1424-
mimeHtml({
1425-
html: messageData.text.html,
1426-
text: messageData.text.plain
1427-
});
1428-
messageData.text.webSafe = true;
1429-
messageData.text._cachedWebSafe = !!messageData.text._generatedHtml;
1430-
}
1431-
14321432
if (messageData.text && messageData.text._generatedHtml) {
14331433
// remove cached pre-processed HTML from output
14341434
delete messageData.text._generatedHtml;

Diff for: lib/email-client/base-client.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,12 @@ class BaseClient {
21842184
let notifyWebSafeHtml = await settings.get('notifyWebSafeHtml');
21852185
if (notifyWebSafeHtml && messageData.text && (messageData.text.html || messageData.text.plain)) {
21862186
// convert to web safe
2187+
messageData.text._generatedHtml = mimeHtml({
2188+
html: messageData.text.html,
2189+
text: messageData.text.plain
2190+
});
21872191

2192+
// embed images
21882193
if (messageData.text.html && messageData.attachments) {
21892194
let attachmentList = new Map();
21902195

@@ -2218,11 +2223,6 @@ class BaseClient {
22182223
}
22192224
}
22202225

2221-
messageData.text._generatedHtml = mimeHtml({
2222-
html: messageData.text.html,
2223-
text: messageData.text.plain
2224-
});
2225-
22262226
messageData.text.webSafe = true;
22272227
}
22282228

Diff for: lib/email-client/gmail-client.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,14 @@ class GmailClient extends BaseClient {
10431043

10441044
let formattedMessage = this.formatMessage(messageData, { extended: true, textType: options.textType });
10451045

1046+
if (options.preProcessHtml && formattedMessage.text && (formattedMessage.text.html || formattedMessage.text.plain)) {
1047+
formattedMessage.text.html = mimeHtml({
1048+
html: formattedMessage.text.html,
1049+
text: formattedMessage.text.plain
1050+
});
1051+
formattedMessage.text.webSafe = true;
1052+
}
1053+
10461054
if (options.embedAttachedImages && formattedMessage.text?.html && formattedMessage.attachments) {
10471055
let attachmentMap = new Map();
10481056

@@ -1070,14 +1078,6 @@ class GmailClient extends BaseClient {
10701078
});
10711079
}
10721080

1073-
if (options.preProcessHtml && formattedMessage.text && (formattedMessage.text.html || formattedMessage.text.plain)) {
1074-
formattedMessage.text.html = mimeHtml({
1075-
html: formattedMessage.text.html,
1076-
text: formattedMessage.text.plain
1077-
});
1078-
formattedMessage.text.webSafe = true;
1079-
}
1080-
10811081
return formattedMessage;
10821082
}
10831083

Diff for: lib/email-client/imap/mailbox.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,13 @@ class Mailbox {
11641164
let notifyWebSafeHtml = await settings.get('notifyWebSafeHtml');
11651165
if (notifyWebSafeHtml && messageInfo.text && (messageInfo.text.html || messageInfo.text.plain)) {
11661166
// convert to web safe
1167+
messageInfo.text._generatedHtml = mimeHtml({
1168+
html: messageInfo.text.html,
1169+
text: messageInfo.text.plain
1170+
});
1171+
messageInfo.text.webSafe = true;
11671172

1173+
// embed images
11681174
if (messageInfo.text.html && messageInfo.attachments) {
11691175
let attachmentList = new Map();
11701176
let partList = [];
@@ -1227,12 +1233,6 @@ class Mailbox {
12271233
});
12281234
}
12291235
}
1230-
1231-
messageInfo.text._generatedHtml = mimeHtml({
1232-
html: messageInfo.text.html,
1233-
text: messageInfo.text.plain
1234-
});
1235-
messageInfo.text.webSafe = true;
12361236
}
12371237

12381238
await this.connection.notify(this, MESSAGE_NEW_NOTIFY, messageInfo, {
@@ -2453,6 +2453,14 @@ class Mailbox {
24532453
}
24542454
}
24552455

2456+
if (options.preProcessHtml && messageInfo.text && (messageInfo.text.html || messageInfo.text.plain)) {
2457+
messageInfo.text.html = mimeHtml({
2458+
html: messageInfo.text.html,
2459+
text: messageInfo.text.plain
2460+
});
2461+
messageInfo.text.webSafe = true;
2462+
}
2463+
24562464
if (options.embedAttachedImages && messageInfo.text && messageInfo.text.html && messageInfo.attachments) {
24572465
let attachmentList = new Map();
24582466
let partList = [];
@@ -2508,14 +2516,6 @@ class Mailbox {
25082516
}
25092517
}
25102518

2511-
if (options.preProcessHtml && messageInfo.text && (messageInfo.text.html || messageInfo.text.plain)) {
2512-
messageInfo.text.html = mimeHtml({
2513-
html: messageInfo.text.html,
2514-
text: messageInfo.text.plain
2515-
});
2516-
messageInfo.text.webSafe = true;
2517-
}
2518-
25192519
if (this.listingEntry.specialUse) {
25202520
messageInfo.specialUse = this.listingEntry.specialUse;
25212521
}

Diff for: lib/email-client/outlook-client.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,15 @@ class OutlookClient extends BaseClient {
11841184
showPath: options.showPath
11851185
});
11861186

1187+
if (options.preProcessHtml && formattedMessage.text && (formattedMessage.text.html || formattedMessage.text.plain)) {
1188+
formattedMessage.text.html = mimeHtml({
1189+
html: formattedMessage.text.html,
1190+
text: formattedMessage.text.plain
1191+
});
1192+
1193+
formattedMessage.text.webSafe = true;
1194+
}
1195+
11871196
if (options.embedAttachedImages && formattedMessage.text?.html && formattedMessage.attachments) {
11881197
let attachmentMap = new Map();
11891198

@@ -1210,15 +1219,6 @@ class OutlookClient extends BaseClient {
12101219
});
12111220
}
12121221

1213-
if (options.preProcessHtml && formattedMessage.text && (formattedMessage.text.html || formattedMessage.text.plain)) {
1214-
formattedMessage.text.html = mimeHtml({
1215-
html: formattedMessage.text.html,
1216-
text: formattedMessage.text.plain
1217-
});
1218-
1219-
formattedMessage.text.webSafe = true;
1220-
}
1221-
12221222
if (specialUse) {
12231223
formattedMessage.messageSpecialUse = specialUse;
12241224
}

0 commit comments

Comments
 (0)