public static string UpdateEmbeddedImageLinks()

in Mail2Bug/Email/EmailBodyProcessingUtils.cs [155:179]


        public static string UpdateEmbeddedImageLinks(string originalHtml, System.Collections.Generic.IReadOnlyCollection<MessageAttachmentInfo> attachments)
        {
            if (attachments == null || attachments.Count == 0)
            {
                return originalHtml;
            }

            CQ dom = originalHtml;
            foreach (var attachment in attachments)
            {
                string originalImgSrc = $"cid:{attachment.ContentId}";
                var matchingImgLinks = dom[$"img[src$='{originalImgSrc}']"];

                // This may point to the file on the local file-system if we haven't yet uploaded the attachment
                // However, the work item APIs seem to magically 'just work' with this and update the URI to point to the uploaded location
                // If for some reason that stops working, we'd need to either infer the uploaded URI or upload first and mutate the html afterward
                var newSrc = new Uri(attachment.FilePath);
                foreach (IDomObject img in matchingImgLinks)
                {
                    img.SetAttribute("src", newSrc.AbsoluteUri);
                }
            }

            return dom.Render();
        }