emailengine-app 2.89.0 → 2.91.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 +19 -8
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +73 -0
- package/Dockerfile +7 -3
- package/ENVIRONMENT.md +24 -23
- package/README.md +1 -1
- package/bin/healthcheck.js +1 -1
- package/copy-static-files.sh +0 -8
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -4
- package/lib/account/field-codec.js +396 -0
- package/lib/account-assignment.js +26 -9
- package/lib/account.js +196 -462
- package/lib/api-routes/account-routes.js +49 -6
- package/lib/api-routes/route-metadata.js +5 -2
- package/lib/api-routes/submit-routes.js +15 -2
- package/lib/api-token-auth.js +342 -274
- package/lib/arf-detect.js +174 -149
- package/lib/attachment-size.js +29 -0
- package/lib/autodetect-imap-settings.js +482 -296
- package/lib/consts.js +5 -5
- package/lib/db.js +1 -4
- package/lib/email-client/base-client.js +907 -780
- package/lib/email-client/gmail-client.js +557 -450
- package/lib/email-client/imap/cid-parts.js +61 -0
- package/lib/email-client/imap/mailbox.js +376 -422
- package/lib/email-client/imap/sync-operations.js +239 -178
- package/lib/email-client/imap-client.js +5 -5
- package/lib/email-client/message-builder.js +4 -5
- package/lib/email-client/new-message-steps.js +168 -2
- package/lib/email-client/outlook/graph-message.js +266 -0
- package/lib/email-client/outlook/subscription-expiry.js +30 -0
- package/lib/email-client/outlook-client.js +652 -808
- package/lib/get-raw-email.js +338 -232
- package/lib/get-secret.js +1 -4
- package/lib/imapproxy/imap-server.js +5 -5
- package/lib/license-subscription.js +60 -0
- package/lib/load-env.js +48 -0
- package/lib/logger-consts.js +37 -1
- package/lib/logger.js +1 -4
- package/lib/mail-probe.js +157 -0
- package/lib/mcp/tools.js +244 -207
- package/lib/metric-values.js +76 -0
- package/lib/metrics.js +320 -0
- package/lib/oauth/gmail.js +39 -120
- package/lib/oauth/http-request.js +195 -0
- package/lib/oauth/mail-ru.js +33 -60
- package/lib/oauth/outlook.js +37 -137
- package/lib/oauth/pubsub/google.js +176 -117
- package/lib/oauth2-apps.js +440 -463
- package/lib/openapi/build-document.js +10 -10
- package/lib/read-env-value.js +31 -7
- package/lib/redis-backend-warnings.js +70 -0
- package/lib/route-descriptors.js +78 -0
- package/lib/schemas.js +10 -1
- package/lib/sentry-integrations.js +299 -0
- package/lib/sentry.js +75 -27
- package/lib/sso-routes.js +249 -0
- package/lib/sso.js +29 -6
- package/lib/tools.js +17 -28
- package/lib/ui-routes/account-edit-form.js +198 -0
- package/lib/ui-routes/account-page.js +241 -0
- package/lib/ui-routes/account-routes.js +46 -349
- package/lib/ui-routes/account-setup.js +1 -1
- package/lib/ui-routes/auth-routes.js +10 -10
- package/lib/ui-routes/provider-signin.js +187 -0
- package/lib/ui-routes/route-helpers.js +1 -1
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/ui-view-context.js +328 -0
- package/lib/utils/public-suffix.js +22 -101
- package/lib/web-safe-html.js +20 -7
- package/lib/worker-metrics.js +82 -0
- package/list-generate.js +2 -5
- package/package.json +28 -24
- package/sbom.json +360 -1030
- package/scripts/refresh-test-tokens.js +1 -1
- package/server.js +400 -677
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +55 -1
- package/static/css/src/app.tailwind.css +18 -0
- package/static/js/ee-client.js +2619 -645
- package/static/js/ui.js +12 -2
- package/static/licenses.html +224 -764
- package/translations/de.mo +0 -0
- package/translations/de.po +429 -390
- package/translations/en.mo +0 -0
- package/translations/en.po +342 -257
- package/translations/es.mo +0 -0
- package/translations/es.po +440 -395
- package/translations/et.mo +0 -0
- package/translations/et.po +425 -375
- package/translations/fr.mo +0 -0
- package/translations/fr.po +425 -383
- package/translations/it.mo +0 -0
- package/translations/it.po +441 -394
- package/translations/ja.mo +0 -0
- package/translations/ja.po +408 -335
- package/translations/messages.pot +188 -130
- package/translations/nl.mo +0 -0
- package/translations/nl.po +419 -382
- package/translations/pl.mo +0 -0
- package/translations/pl.po +425 -379
- package/translations/sv.mo +0 -0
- package/translations/sv.po +440 -388
- package/translations/tr.mo +0 -0
- package/translations/tr.po +441 -387
- package/views/account-identity-error.hbs +1 -1
- package/views/account-workspace-error.hbs +2 -2
- package/views/accounts/browse.hbs +19 -1
- package/views/accounts/register/imap-server.hbs +22 -7
- package/views/accounts/register/imap.hbs +3 -0
- package/views/accounts/register/index.hbs +1 -27
- package/views/accounts/register/provider-signin.hbs +58 -0
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/provider_signin_button.hbs +30 -0
- package/views/queues/index.hbs +1 -1
- package/views/redirect.hbs +1 -1
- package/views/unsubscribe.hbs +6 -6
- package/workers/api.js +20 -451
- package/data/public_suffix_list.dat +0 -16698
package/lib/arf-detect.js
CHANGED
|
@@ -8,7 +8,7 @@ const { isUnsafeTransformedKey } = require('./utils/unsafe-key');
|
|
|
8
8
|
|
|
9
9
|
// The attachment types a complaint is read from: the ARF report itself, and the copy of the
|
|
10
10
|
// original message beside it, which some feedback loops send as text/rfc822-headers. Both arrival
|
|
11
|
-
// paths gate and download on these lists, and
|
|
11
|
+
// paths gate and download on these lists, and arfDetect() parses every type in them
|
|
12
12
|
const FEEDBACK_REPORT_TYPE = 'message/feedback-report';
|
|
13
13
|
const ORIGINAL_MESSAGE_TYPES = ['message/rfc822', 'message/rfc822-headers', 'text/rfc822-headers', 'text/rfc822-header'];
|
|
14
14
|
const COMPLAINT_ATTACHMENT_TYPES = [FEEDBACK_REPORT_TYPE, ...ORIGINAL_MESSAGE_TYPES];
|
|
@@ -54,6 +54,169 @@ function stripAngleBrackets(value) {
|
|
|
54
54
|
return value.substring(start, end);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// Normalizes one field of a feedback report. Returns the [key, value] pair to store, or null for a
|
|
58
|
+
// field that is empty or carries an invalid date
|
|
59
|
+
function normalizeArfField(key, value) {
|
|
60
|
+
if (!key || !value) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (ARF_SINGLE.includes(key)) {
|
|
65
|
+
value = capField(Array.isArray(value) ? value.join(',') : (value || '').toString());
|
|
66
|
+
} else if (!Array.isArray(value)) {
|
|
67
|
+
value = []
|
|
68
|
+
.concat(value || [])
|
|
69
|
+
.map(element => capField((element || '').toString().trim()))
|
|
70
|
+
.filter(element => element);
|
|
71
|
+
} else {
|
|
72
|
+
value = value.map(element => (typeof element === 'string' ? capField(element) : element));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!value || !value.length) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
switch (key) {
|
|
80
|
+
case 'original-mail-from':
|
|
81
|
+
value = stripAngleBrackets(value);
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'arrival-date':
|
|
85
|
+
case 'received-date':
|
|
86
|
+
key = 'arrival-date';
|
|
87
|
+
value = new Date(value);
|
|
88
|
+
if (value.toString() === 'Invalid Date') {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
value = value.toISOString();
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return [key, value];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Adds recipients to the report's list, each address once: before the ones already listed (the
|
|
99
|
+
// report's own) or after them (those collected from the original-message copies)
|
|
100
|
+
function addRecipients(report, addresses, first) {
|
|
101
|
+
const current = report.arf['original-rcpt-to'] || [];
|
|
102
|
+
report.arf['original-rcpt-to'] = first
|
|
103
|
+
? addresses.concat(current.filter(addr => !addresses.includes(addr)))
|
|
104
|
+
: current.concat(addresses.filter(addr => !current.includes(addr)));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The fields of a message/feedback-report attachment. Every field overwrites what an earlier
|
|
108
|
+
// attachment stored under the same key, except the recipients, which accumulate whichever order
|
|
109
|
+
// the attachments come in: the report's own come first, then the ones collected before it that it
|
|
110
|
+
// does not list
|
|
111
|
+
function parseFeedbackReport(content, report) {
|
|
112
|
+
const contents = decodeHeaders(content);
|
|
113
|
+
|
|
114
|
+
for (const key of Object.keys(contents)) {
|
|
115
|
+
const field = normalizeArfField(key, contents[key]);
|
|
116
|
+
if (!field) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const [fieldKey, value] = field;
|
|
120
|
+
if (fieldKey === 'original-rcpt-to') {
|
|
121
|
+
addRecipients(report, value, true);
|
|
122
|
+
} else {
|
|
123
|
+
report.arf[fieldKey] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The addresses of an address header, empty ones dropped
|
|
129
|
+
const headerAddresses = headerLines =>
|
|
130
|
+
headerLines
|
|
131
|
+
.flatMap(addressparser)
|
|
132
|
+
.map(entry => entry.address)
|
|
133
|
+
.filter(addr => addr);
|
|
134
|
+
|
|
135
|
+
const addressList = headerLines => {
|
|
136
|
+
const value = headerAddresses(headerLines);
|
|
137
|
+
return value.length ? value : undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// How each copied header of the original message is read from its non-empty lines. Returns
|
|
141
|
+
// undefined for a header that yields nothing. The first attachment to yield a value keeps it
|
|
142
|
+
const HEADER_EXTRACTORS = {
|
|
143
|
+
from: headerLines => {
|
|
144
|
+
const value = addressList(headerLines);
|
|
145
|
+
return value && value.pop();
|
|
146
|
+
},
|
|
147
|
+
to: addressList,
|
|
148
|
+
cc: addressList,
|
|
149
|
+
bcc: addressList,
|
|
150
|
+
subject: headerLines => libmime.decodeWords(headerLines.pop()).trim() || undefined,
|
|
151
|
+
date: headerLines => {
|
|
152
|
+
const value = new Date(headerLines.pop());
|
|
153
|
+
return value.toString() !== 'Invalid Date' ? value.toISOString() : undefined;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// The header block of an attachment carrying the original message or its headers
|
|
158
|
+
function readOriginalHeaders(content) {
|
|
159
|
+
let contents = capHeaderBlock(content);
|
|
160
|
+
const headerPos = contents.match(/\r?\n\r?\n/);
|
|
161
|
+
|
|
162
|
+
if (headerPos) {
|
|
163
|
+
contents = contents.substr(0, headerPos.index);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return decodeHeaders(contents);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Fills the report from a copy of the original message's headers. Recipients accumulate across
|
|
170
|
+
// attachments; every other value is only used when nothing before it set one
|
|
171
|
+
function parseOriginalHeaders(headers, report) {
|
|
172
|
+
// Hotmail original recipient X-HmXmrOriginalRecipient
|
|
173
|
+
const addresses = addressparser([].concat(headers['x-hmxmroriginalrecipient'] || []).join(', '))
|
|
174
|
+
.map(addr => addr.address)
|
|
175
|
+
.filter(addr => addr);
|
|
176
|
+
|
|
177
|
+
addRecipients(report, addresses, false);
|
|
178
|
+
|
|
179
|
+
let messageId = [].concat(headers['message-id'] || []).pop();
|
|
180
|
+
if (messageId && !report.headers['message-id']) {
|
|
181
|
+
report.headers['message-id'] = messageId;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let sourceIp = [].concat(headers['x-sender-ip'] || []).pop();
|
|
185
|
+
if (sourceIp && !report.arf['source-ip']) {
|
|
186
|
+
report.arf['source-ip'] = sourceIp;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let originalArrivalTime = [].concat(headers['x-ms-exchange-crosstenant-originalarrivaltime'] || []).pop();
|
|
190
|
+
if (originalArrivalTime && !report.arf['arrival-date']) {
|
|
191
|
+
let originalArrivalTimeDate = new Date(originalArrivalTime);
|
|
192
|
+
if (originalArrivalTimeDate && originalArrivalTimeDate.toString() !== 'Invalid Date') {
|
|
193
|
+
report.arf['arrival-date'] = originalArrivalTimeDate.toISOString();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
for (let [headerKey, extract] of Object.entries(HEADER_EXTRACTORS)) {
|
|
198
|
+
let headerLines = []
|
|
199
|
+
.concat(headers[headerKey] || [])
|
|
200
|
+
.map(val => val && typeof val === 'string' && val.trim())
|
|
201
|
+
.filter(val => val);
|
|
202
|
+
if (!headerLines.length) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let value = extract(headerLines);
|
|
207
|
+
if (value !== undefined) {
|
|
208
|
+
report.headers[headerKey] = report.headers[headerKey] || value;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// The last address of a Return-Path header, undefined when it names none
|
|
214
|
+
const lastAddress = header =>
|
|
215
|
+
addressparser([].concat(header || []).join(', '))
|
|
216
|
+
.map(addr => addr.address)
|
|
217
|
+
.filter(addr => addr)
|
|
218
|
+
.pop();
|
|
219
|
+
|
|
57
220
|
const arfDetect = async messageInfo => {
|
|
58
221
|
const report = {
|
|
59
222
|
arf: {},
|
|
@@ -63,155 +226,17 @@ const arfDetect = async messageInfo => {
|
|
|
63
226
|
let returnPath;
|
|
64
227
|
|
|
65
228
|
for (let attachment of messageInfo.attachments || []) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (ARF_SINGLE.includes(key)) {
|
|
80
|
-
value = capField(Array.isArray(contents[key]) ? contents[key].join(',') : (contents[key] || '').toString());
|
|
81
|
-
} else if (!Array.isArray(value)) {
|
|
82
|
-
value = []
|
|
83
|
-
.concat(value || [])
|
|
84
|
-
.map(element => capField((element || '').toString().trim()))
|
|
85
|
-
.filter(element => element);
|
|
86
|
-
} else {
|
|
87
|
-
value = value.map(element => (typeof element === 'string' ? capField(element) : element));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!value || !value.length) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
switch (key) {
|
|
95
|
-
case 'original-mail-from':
|
|
96
|
-
value = stripAngleBrackets(value);
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
case 'arrival-date':
|
|
100
|
-
case 'received-date':
|
|
101
|
-
key = 'arrival-date';
|
|
102
|
-
value = new Date(value);
|
|
103
|
-
if (value.toString() === 'Invalid Date') {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
value = value.toISOString();
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
report.arf[key] = value;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
break;
|
|
229
|
+
const contentType = attachment.contentType.toLowerCase();
|
|
230
|
+
|
|
231
|
+
if (contentType === FEEDBACK_REPORT_TYPE) {
|
|
232
|
+
// found a feedback report
|
|
233
|
+
parseFeedbackReport(attachment.content, report);
|
|
234
|
+
} else if (ORIGINAL_MESSAGE_TYPES.includes(contentType)) {
|
|
235
|
+
const headers = readOriginalHeaders(attachment.content);
|
|
236
|
+
parseOriginalHeaders(headers, report);
|
|
237
|
+
if (headers['return-path']) {
|
|
238
|
+
returnPath = lastAddress(headers['return-path']);
|
|
114
239
|
}
|
|
115
|
-
|
|
116
|
-
case 'message/rfc822':
|
|
117
|
-
case 'message/rfc822-headers':
|
|
118
|
-
case 'text/rfc822-headers':
|
|
119
|
-
case 'text/rfc822-header': {
|
|
120
|
-
let contents = capHeaderBlock(attachment.content);
|
|
121
|
-
const headerPos = contents.match(/\r?\n\r?\n/);
|
|
122
|
-
|
|
123
|
-
if (headerPos) {
|
|
124
|
-
contents = contents.substr(0, headerPos.index);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const headers = decodeHeaders(contents);
|
|
128
|
-
|
|
129
|
-
// Hotmail original recipient X-HmXmrOriginalRecipient
|
|
130
|
-
const addresses = addressparser([].concat(headers['x-hmxmroriginalrecipient'] || []).join(', '))
|
|
131
|
-
.map(addr => addr.address)
|
|
132
|
-
.filter(addr => addr && !(report.arf['original-rcpt-to'] && report.arf['original-rcpt-to'].includes(addr)));
|
|
133
|
-
|
|
134
|
-
report.arf['original-rcpt-to'] = [].concat(report.arf['original-rcpt-to'] || []).concat(addresses);
|
|
135
|
-
|
|
136
|
-
if (headers['return-path']) {
|
|
137
|
-
returnPath = addressparser([].concat(headers['return-path'] || []).join(', '))
|
|
138
|
-
.map(addr => addr.address)
|
|
139
|
-
.filter(addr => addr)
|
|
140
|
-
.pop();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let messageId = [].concat(headers['message-id'] || []).pop();
|
|
144
|
-
if (messageId && !report.headers['message-id']) {
|
|
145
|
-
report.headers['message-id'] = messageId;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let sourceIp = [].concat(headers['x-sender-ip'] || []).pop();
|
|
149
|
-
if (sourceIp && !report.arf['source-ip']) {
|
|
150
|
-
report.arf['source-ip'] = sourceIp;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let originalArrivalTime = [].concat(headers['x-ms-exchange-crosstenant-originalarrivaltime'] || []).pop();
|
|
154
|
-
if (originalArrivalTime && !report.arf['arrival-date']) {
|
|
155
|
-
let originalArrivalTimeDate = new Date(originalArrivalTime);
|
|
156
|
-
if (originalArrivalTimeDate && originalArrivalTimeDate.toString() !== 'Invalid Date') {
|
|
157
|
-
report.arf['arrival-date'] = originalArrivalTimeDate.toISOString();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
for (let headerKey of ['from', 'to', 'cc', 'bcc', 'subject', 'date']) {
|
|
162
|
-
let headerLines = []
|
|
163
|
-
.concat(headers[headerKey] || [])
|
|
164
|
-
.map(val => val && typeof val === 'string' && val.trim())
|
|
165
|
-
.filter(val => val);
|
|
166
|
-
if (!headerLines.length) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
switch (headerKey) {
|
|
171
|
-
case 'date':
|
|
172
|
-
{
|
|
173
|
-
let value = new Date(headerLines.pop());
|
|
174
|
-
if (value.toString() !== 'Invalid Date') {
|
|
175
|
-
report.headers[headerKey] = report.headers[headerKey] || value.toISOString();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case 'subject':
|
|
181
|
-
{
|
|
182
|
-
let value = libmime.decodeWords(headerLines.pop()).trim();
|
|
183
|
-
if (value) {
|
|
184
|
-
report.headers[headerKey] = report.headers[headerKey] || value;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
|
|
189
|
-
case 'from':
|
|
190
|
-
case 'to':
|
|
191
|
-
case 'cc':
|
|
192
|
-
case 'bcc':
|
|
193
|
-
{
|
|
194
|
-
let value = headerLines
|
|
195
|
-
.flatMap(addressparser)
|
|
196
|
-
.map(entry => entry.address)
|
|
197
|
-
.filter(addr => addr);
|
|
198
|
-
|
|
199
|
-
if (value && value.length) {
|
|
200
|
-
if (headerKey === 'from') {
|
|
201
|
-
value = value.pop();
|
|
202
|
-
}
|
|
203
|
-
report.headers[headerKey] = report.headers[headerKey] || value;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
default:
|
|
214
|
-
break;
|
|
215
240
|
}
|
|
216
241
|
}
|
|
217
242
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Base64 lines are 76 characters long (RFC 2045 section 6.8) and each ends in CRLF
|
|
4
|
+
const BASE64_LINE = 78;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The size of an IMAP attachment once its transfer encoding is undone, from the size of the
|
|
8
|
+
* encoded body part the BODYSTRUCTURE reports. base64 carries 3 bytes in 4 characters with a line
|
|
9
|
+
* break after every 76, so the file size is computed from it, assuming the standard 76 character lines (base64 written
|
|
10
|
+
* with other line lengths, or none, comes out up to about 2.5% off).
|
|
11
|
+
* Other encodings are left at the encoded size: 7bit, 8bit and binary are the file itself, and
|
|
12
|
+
* quoted-printable can not be undone without the content, so its encoded size is an upper bound.
|
|
13
|
+
*
|
|
14
|
+
* @param {number} encodedSize - Size of the encoded body part in bytes
|
|
15
|
+
* @param {string} [encoding] - Content-Transfer-Encoding of the part
|
|
16
|
+
* @returns {number|undefined} Size of the attachment in bytes
|
|
17
|
+
*/
|
|
18
|
+
function decodedAttachmentSize(encodedSize, encoding) {
|
|
19
|
+
if (typeof encodedSize !== 'number' || !Number.isFinite(encodedSize) || encodedSize < 0) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (String(encoding || '').toLowerCase() !== 'base64') {
|
|
23
|
+
return encodedSize;
|
|
24
|
+
}
|
|
25
|
+
const lineBreaks = Math.floor(encodedSize / BASE64_LINE) * 2;
|
|
26
|
+
return Math.floor(((encodedSize - lineBreaks) * 3) / 4);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { decodedAttachmentSize };
|