From 996f8e664b7b64c7aae54d1413ccb660959cba3e Mon Sep 17 00:00:00 2001 From: Kieran Huggins Date: Thu, 6 Apr 2017 16:29:17 -0400 Subject: [PATCH] replace all occurrences of the same CID reference This fixes the incorrect behaviour of only replacing the _first_ instance of a CID reference by using a regular expression with a global flag. Example: referencing the same inline-attachment in multiple places within the same email (often used for responsive HTML emails) --- assets/js/controllers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/js/controllers.js b/assets/js/controllers.js index 8425d46..846c413 100644 --- a/assets/js/controllers.js +++ b/assets/js/controllers.js @@ -373,7 +373,9 @@ mailhogApp.controller('MailCtrl', function ($scope, $http, $sce, $timeout) { h = $scope.getMessageHTML(data) for(c in data.$cidMap) { - h = h.replace("cid:" + c, data.$cidMap[c]) + str = "cid:" + c; + pat = str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); + h = h.replace(new RegExp(pat, 'g'), data.$cidMap[c]) } data.previewHTML = $sce.trustAsHtml(h); $scope.preview = data;