update reuse cid for same data url

This commit is contained in:
Andris Reinman 2019-04-29 23:20:38 +03:00
parent ec3317b2b6
commit 2f3c45d98e
2 changed files with 10 additions and 0 deletions

View file

@ -2569,7 +2569,11 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
if (data.html && typeof data.html === 'string') {
let fromAddress = (data.from && data.from.address).toString() || os.hostname();
let cids = new Map();
data.html = data.html.replace(/(<img\b[^>]* src\s*=[\s"']*)(data:[^"'>\s]+)/gi, (match, prefix, dataUri) => {
if (cids.has(dataUri)) {
return prefix + 'cid:' + cids.get(dataUri);
}
let cid = uuid.v4() + '-attachments@' + fromAddress.split('@').pop();
data.attachments.push(
processDataUrl({
@ -2577,6 +2581,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
cid
})
);
cids.set(dataUri, cid);
return prefix + 'cid:' + cid;
});
}

View file

@ -330,7 +330,11 @@ module.exports = (db, server, messageHandler, userHandler) => {
if (data.html && typeof data.html === 'string') {
let fromAddress = (data.from && data.from.address).toString() || os.hostname();
let cids = new Map();
data.html = data.html.replace(/(<img\b[^>]* src\s*=[\s"']*)(data:[^"'>\s]+)/gi, (match, prefix, dataUri) => {
if (cids.has(dataUri)) {
return prefix + 'cid:' + cids.get(dataUri);
}
let cid = uuid.v4() + '-attachments@' + fromAddress.split('@').pop();
data.attachments.push(
processDataUrl({
@ -338,6 +342,7 @@ module.exports = (db, server, messageHandler, userHandler) => {
cid
})
);
cids.set(dataUri, cid);
return prefix + 'cid:' + cid;
});
}