diff --git a/lib/api/messages.js b/lib/api/messages.js
index 0a42ecb9..6712f342 100644
--- a/lib/api/messages.js
+++ b/lib/api/messages.js
@@ -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(/(]* 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;
});
}
diff --git a/lib/api/submit.js b/lib/api/submit.js
index 586f4f22..9885cadf 100644
--- a/lib/api/submit.js
+++ b/lib/api/submit.js
@@ -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(/(]* 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;
});
}