Skip to content

Commit

Permalink
Merge pull request #651 from bcgov/test-marshal-NK-4339
Browse files Browse the repository at this point in the history
additional fix for logic for starting from last regex match
  • Loading branch information
nkan-aot authored Dec 7, 2023
2 parents 5798047 + 3b2c1f6 commit 32518c3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ public MSGFileProcessor(Stream sourceStream)
var _inlineAttachment = (Storage.Attachment)inlineAttachment;
Regex regex = new Regex("<img(.|\\n)*cid:" + _inlineAttachment.ContentId + "(.|\\n)*?>");
Match match = regex.Match(bodyreplaced, startAt);
bodyreplaced = regex.Replace(bodyreplaced, "<img style=\"max-width: 700px\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>", 1, startAt);
startAt = match.Index + match.Length;
if (match.Success)
{
string imgReplacementString = "<img style=\"max-width: 700px\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>";
bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt);
startAt = match.Index + imgReplacementString.Length;
}
foreach (KeyValuePair<MemoryStream, Dictionary<string, string>> attachment in attachmentsObj)
{
if (attachment.Value.ContainsKey("cid") && attachment.Value["cid"] == _inlineAttachment.ContentId)
Expand Down

0 comments on commit 32518c3

Please sign in to comment.