public void StoreAttachmentWithoutQuota(MailAttachment attachment) { try { if ((attachment.dataStream == null || attachment.dataStream.Length == 0) && (attachment.data == null || attachment.data.Length == 0)) { return; } if (string.IsNullOrEmpty(attachment.fileName)) { attachment.fileName = "attachment.ext"; } var storage = MailDataStore.GetDataStore(Tenant); storage.QuotaController = null; var ext = Path.GetExtension(attachment.fileName); attachment.storedName = MailUtil.CreateStreamId(); if (!string.IsNullOrEmpty(ext)) { attachment.storedName = Path.ChangeExtension(attachment.storedName, ext); } attachment.fileNumber = !string.IsNullOrEmpty(attachment.contentId) //Upload hack: embedded attachment have to be saved in 0 folder ? 0 : attachment.fileNumber; var attachmentPath = MailStoragePathCombiner.GerStoredFilePath(attachment); if (attachment.data != null) { using (var reader = new MemoryStream(attachment.data)) { var uploadUrl = storage.Save(attachmentPath, reader, attachment.fileName); attachment.storedFileUrl = MailStoragePathCombiner.GetStoredUrl(uploadUrl); } } else { var uploadUrl = storage.Save(attachmentPath, attachment.dataStream, attachment.fileName); attachment.storedFileUrl = MailStoragePathCombiner.GetStoredUrl(uploadUrl); } } catch (Exception e) { _logger.Error("StoreAttachmentWithoutQuota(). filename: {0}, ctype: {1} Exception:\r\n{2}\r\n", attachment.fileName, attachment.contentType, e.ToString()); throw; } }
public static AttachmentStream GetAttachmentStream(MailAttachment attachment) { if (attachment != null) { var storage = MailDataStore.GetDataStore(attachment.tenant); var attachmentPath = MailStoragePathCombiner.GerStoredFilePath(attachment); var result = new AttachmentStream { FileStream = storage.GetReadStream("", attachmentPath), FileName = attachment.fileName }; return(result); } throw new InvalidOperationException("Attachment not found"); }
public void StoreAttachmentWithoutQuota(int tenant, string user, MailAttachment attachment, IDataStore storage) { try { if (attachment.data == null || attachment.data.Length == 0) { return; } if (string.IsNullOrEmpty(attachment.fileName)) { attachment.fileName = "attachment.ext"; } var contentDisposition = MailStoragePathCombiner.PrepareAttachmentName(attachment.fileName); var ext = Path.GetExtension(attachment.fileName); attachment.storedName = MailUtil.CreateStreamId(); if (!string.IsNullOrEmpty(ext)) { attachment.storedName = Path.ChangeExtension(attachment.storedName, ext); } attachment.fileNumber = !string.IsNullOrEmpty(attachment.contentId) //Upload hack: embedded attachment have to be saved in 0 folder ? 0 : attachment.fileNumber; var attachmentPath = MailStoragePathCombiner.GerStoredFilePath(attachment); using (var reader = new MemoryStream(attachment.data)) { var uploadUrl = storage.UploadWithoutQuota(string.Empty, attachmentPath, reader, attachment.contentType, contentDisposition); attachment.storedFileUrl = MailStoragePathCombiner.GetStoredUrl(uploadUrl); } } catch (Exception e) { _logger.Error("StoreAttachmentWithoutQuota(). filename: {0}, ctype: {1} Exception:\r\n{2}\r\n", attachment.fileName, attachment.contentType, e.ToString()); throw; } }
public string StoreCKeditorImageWithoutQuota(int mailboxId, string fileName, byte[] imageData, IDataStore storage) { try { if (imageData == null || imageData.Length == 0) { throw new ArgumentNullException("imageData"); } var ext = string.IsNullOrEmpty(fileName) ? ".jpg" : Path.GetExtension(fileName); if (string.IsNullOrEmpty(ext)) { ext = ".jpg"; } var storeName = imageData.GetMd5(); storeName = Path.ChangeExtension(storeName, ext); var contentDisposition = ContentDispositionUtil.GetHeaderValue(storeName); var contentType = MimeMapping.GetMimeMapping(ext); var signatureImagePath = MailStoragePathCombiner.GerStoredSignatureImagePath(mailboxId, storeName); using (var reader = new MemoryStream(imageData)) { var uploadUrl = storage.Save(User, signatureImagePath, reader, contentType, contentDisposition); return(MailStoragePathCombiner.GetStoredUrl(uploadUrl)); } } catch (Exception e) { _logger.Error("StoreCKeditorImageWithoutQuota(). filename: {0} Exception:\r\n{1}\r\n", fileName, e.ToString()); throw; } }