/// <summary> /// Downsamples all image attachments, and ensures that each attachment /// is below the size limit. /// </summary> private bool ProcessAttachments( IList <Attachment> attachments, out IList <string> attachmentErrors) { attachmentErrors = new List <string>(); foreach (var attachment in attachments) { if (attachment.IsImage) { bool downsampled = _imageProcessor.DownsampleImageToJpeg ( attachment.AttachmentData.FileContents, c_maxImageWidth, c_maxImageHeight, out var newImageData ); if (downsampled) { attachment.AttachmentData.FileContents = newImageData; attachment.FileName = Path.ChangeExtension(attachment.FileName, "jpg"); attachment.ContentType = "image/jpeg"; } } if (attachment.AttachmentData.FileContents.Length > c_maxAttachmentSizeKb * 1024) { attachmentErrors.Add ( $"Attachment {attachment.FileName} exceeds maximum size of " + $"{c_maxAttachmentSizeKb} KB." ); } } return(!attachmentErrors.Any()); }