This commit is contained in:
Andris Reinman 2019-04-15 15:11:03 +03:00
parent d893d9239d
commit 664b3792a4
2 changed files with 42 additions and 1 deletions

View file

@ -4,6 +4,8 @@ const config = require('wild-config');
const log = require('npmlog');
const libmime = require('libmime');
const Joi = require('../joi');
const uuid = require('uuid');
const os = require('os');
const MongoPaging = require('mongo-cursor-pagination');
const addressparser = require('nodemailer/lib/addressparser');
const MailComposer = require('nodemailer/lib/mail-composer');
@ -2436,6 +2438,20 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
keepBcc: true
};
if (data.html && typeof data.html === 'string') {
let fromAddress = (data.from && data.from.address).toString() || os.hostname();
data.html = data.html.replace(/(<img\b[^>]* src\s*=[\s"']*)(data:[^"'>\s]+)/gi, (match, prefix, dataUri) => {
let cid = uuid.v4() + '-attachments@' + fromAddress.split('@').pop();
data.attachments.push(
processDataUrl({
path: dataUri,
cid
})
);
return prefix + 'cid:' + cid;
});
}
// ensure plaintext content if html is provided
if (data.html && !data.text) {
try {
@ -4002,3 +4018,28 @@ function parseAddresses(data) {
walk([].concat(data || []));
return Array.from(addresses);
}
function processDataUrl(element) {
let parts = (element.path || element.href).match(/^data:((?:[^;]*;)*(?:[^,]*)),(.*)$/i);
if (!parts) {
return element;
}
element.content = /\bbase64$/i.test(parts[1]) ? Buffer.from(parts[2], 'base64') : Buffer.from(decodeURIComponent(parts[2]));
if ('path' in element) {
element.path = false;
}
if ('href' in element) {
element.href = false;
}
parts[1].split(';').forEach(item => {
if (/^\w+\/[^/]+$/i.test(item)) {
element.contentType = element.contentType || item.toLowerCase();
}
});
return element;
}

View file

@ -1,6 +1,6 @@
{
"name": "wildduck",
"version": "1.17.1",
"version": "1.17.2",
"description": "IMAP/POP3 server built with Node.js and MongoDB",
"main": "server.js",
"scripts": {