Skip to content

Commit

Permalink
fix(mime): Use custom MIME boundary pattern for generated emails
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 28, 2024
1 parent 16bd82d commit 0e2a110
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
14 changes: 12 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const {
getBoolean,
readEnvValue,
validUidValidity,
getDuration
getDuration,
genBaseBoundary
} = require('./tools');

const RESYNC_DELAY = 15 * 60;
Expand All @@ -62,7 +63,8 @@ const {
MAILBOX_DELETED_NOTIFY,
MAX_BACKOFF_DELAY,
TLS_DEFAULTS,
DEFAULT_DELIVERY_ATTEMPTS
DEFAULT_DELIVERY_ATTEMPTS,
MIME_BOUNDARY_PREFIX
} = require('./consts');

const DOWNLOAD_CHUNK_SIZE = getByteSize(readEnvValue('EENGINE_CHUNK_SIZE')) || DEFAULT_DOWNLOAD_CHUNK_SIZE;
Expand Down Expand Up @@ -2516,6 +2518,8 @@ class Connection {
// normal message
data.disableFileAccess = true;
data.disableUrlAccess = true;
data.boundaryPrefix = MIME_BOUNDARY_PREFIX;
data.baseBoundary = genBaseBoundary();

// convert data uri images to attachments
convertDataUrisToAtachments(data);
Expand Down Expand Up @@ -2614,6 +2618,8 @@ class Connection {
// normal message
data.disableFileAccess = true;
data.disableUrlAccess = true;
data.boundaryPrefix = MIME_BOUNDARY_PREFIX;
data.baseBoundary = genBaseBoundary();

let baseUrl = data.baseUrl || (await settings.get('serviceUrl')) || null;

Expand Down Expand Up @@ -3122,6 +3128,8 @@ class Connection {

data.disableFileAccess = true;
data.disableUrlAccess = true;
data.boundaryPrefix = MIME_BOUNDARY_PREFIX;
data.baseBoundary = genBaseBoundary();

// convert data uri images to attachments
convertDataUrisToAtachments(data);
Expand Down Expand Up @@ -3378,6 +3386,8 @@ class Connection {

data.disableUrlAccess = true;
data.disableFileAccess = true;
data.boundaryPrefix = MIME_BOUNDARY_PREFIX;
data.baseBoundary = genBaseBoundary();
data.newline = '\r\n';

if (data.internalDate && !data.date) {
Expand Down
2 changes: 2 additions & 0 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ module.exports = {
// nanoseconds
ALLOWED_REDIS_LATENCY: 5 * 1000000,

MIME_BOUNDARY_PREFIX: '----=_Part',

generateWebhookTable() {
let entries = [];

Expand Down
8 changes: 6 additions & 2 deletions lib/get-raw-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const addressparser = require('nodemailer/lib/addressparser');
const uuid = require('uuid');
const os = require('os');
const libmime = require('libmime');
const { getBoolean } = require('./tools');
const { getBoolean, genBaseBoundary } = require('./tools');
const msgpack = require('msgpack5')();
const crypto = require('crypto');

const { MIME_BOUNDARY_PREFIX } = require('./consts');

function getKeyHeader(licenseInfo) {
if (!licenseInfo) {
return 'UNLICENSED_COPY';
Expand Down Expand Up @@ -357,7 +359,9 @@ async function getRawEmail(data, licenseInfo) {
date: sendAt,
disableUrlAccess: true,
disableFileAccess: true,
newline: '\r\n'
newline: '\r\n',
boundaryPrefix: MIME_BOUNDARY_PREFIX,
baseBoundary: genBaseBoundary()
},
data,
{
Expand Down
8 changes: 8 additions & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,5 +1785,13 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
ref[key] = module.exports.getBoolean(module.exports.readEnvValue(envKey));
}
}
},

genBaseBoundary() {
return [
Buffer.from(Date.now().toString(16), 'hex').toString('base64url'),
Buffer.from(`ee@${packageData.version}`).toString('base64url'),
randomBytes(12).toString('base64url')
].join('_');
}
};

0 comments on commit 0e2a110

Please sign in to comment.