public ActionResult PreviewMailAttachment(string mailId, string subPath, int idx) { ValidateMailId(mailId); subPath = subPath ?? ""; ValidateSubPath(subPath); var filePath = Path.Combine(Properties.Settings.Default.MailDir, subPath, mailId); if (!MailHelper.ListMailFiles(Path.Combine(Properties.Settings.Default.MailDir, subPath)).Select(f => f.FullName).Contains(filePath)) { throw new ArgumentException("mailId is not in white list", nameof(mailId)); } var mail = new MailModel(filePath); return(Content(Encoding.UTF8.GetString(mail.GetAttachmentContentFromIdx(idx)), mail.GetAttachmentMediaTypeFromIdx(idx))); }
public FileResult DownloadMailAttachment(string mailId, string subPath, int idx) { ValidateMailId(mailId); subPath = subPath ?? ""; ValidateSubPath(subPath); var filePath = Path.Combine(Properties.Settings.Default.MailDir, subPath, mailId); if (!MailHelper.ListMailFiles(Path.Combine(Properties.Settings.Default.MailDir, subPath)).Select(f => f.FullName).Contains(filePath)) { throw new ArgumentException("mailId is not in white list", nameof(mailId)); } var mail = new MailModel(filePath); var result = File(mail.GetAttachmentContentFromIdx(idx), mail.GetAttachmentMediaTypeFromIdx(idx)); result.FileDownloadName = mail.AttachmentNames[idx]; return(result); }