diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs index 69fbb0235..43afdb81a 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs @@ -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); } @@ -179,9 +179,10 @@ public MSGFileProcessor(Stream sourceStream) { const float maxSize = 700; Regex.Match(match.Value, "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=(\"|\')?(?\\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; @@ -194,7 +195,17 @@ public MSGFileProcessor(Stream sourceStream) width = (int) (width * scale); height = (int) (height * scale); } - string imgReplacementString = ""; + string widthString = string.Empty; + string heightString = string.Empty; + if (width > 0) + { + widthString = " width =\"" + width +"\""; + } + if (height > 0) + { + heightString = " height =\"" + height + "\""; + } + string imgReplacementString = ""; bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt); startAt = match.Index + imgReplacementString.Length; }