Skip to content

Commit

Permalink
Merge pull request #663 from bcgov/dev-DV-4859
Browse files Browse the repository at this point in the history
msg conversion exception fixes
  • Loading branch information
divyav-aot authored Dec 18, 2023
2 parents 34057bb + f01ba49 commit a48441e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public MSGFileProcessor(Stream sourceStream)
var _attachment = (Storage.Attachment)attachment;
if (htmlInline)
{
if (!String.IsNullOrEmpty(_attachment.ContentId) && bodyreplaced.Contains(_attachment.ContentId))
if (!String.IsNullOrEmpty(_attachment.ContentId) && (bodyreplaced.Contains(_attachment.ContentId) || _attachment.Hidden))
{
inlineAttachments.Add(_attachment);
}
Expand Down Expand Up @@ -179,9 +179,10 @@ public MSGFileProcessor(Stream sourceStream)
{
const float maxSize = 700;
Regex.Match(match.Value, "width=(\"|\')?(?<width>\\d+)(\"|\')?").Groups.TryGetValue("width", out var w);
float width = float.Parse(w.Value);
float width = float.TryParse(w?.Value, out float tempWidth) ? tempWidth : 0;
Regex.Match(match.Value, "height=(\"|\')?(?<height>\\d+)(\"|\')?").Groups.TryGetValue("height", out var h);
float height = float.Parse(h.Value);
float height = float.TryParse(h?.Value, out float tempHeight) ? tempHeight : 0;

if (width > maxSize && width >= height)
{
float scale = maxSize / width;
Expand All @@ -194,7 +195,17 @@ public MSGFileProcessor(Stream sourceStream)
width = (int) (width * scale);
height = (int) (height * scale);
}
string imgReplacementString = "<img width=\"" + width + "\" height=\"" + height + "\" style=\"margin: 1px;\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>";
string widthString = string.Empty;
string heightString = string.Empty;
if (width > 0)
{
widthString = " width =\"" + width +"\"";
}
if (height > 0)
{
heightString = " height =\"" + height + "\"";
}
string imgReplacementString = "<img "+ widthString + heightString + " style =\"margin: 1px;\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>";
bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt);
startAt = match.Index + imgReplacementString.Length;
}
Expand Down

0 comments on commit a48441e

Please sign in to comment.