public override void HandleRetrievedMessage(MailBox mailbox, Message message, MailMessageItem message_item, int folder_id, string uidl, string md5_hash, bool unread, int[] tags_ids) { if (string.IsNullOrEmpty(mailbox.EMailInFolder)) { return; } try { foreach (var attachment in message_item.Attachments) { using (var file = AttachmentManager.GetAttachmentStream(attachment)) { log.Debug("EmailInMessageHandler HandleRetrievedMessage file name: {0}, folder id: {1}", file.FileName, mailbox.EMailInFolder); var uploaded_file_id = FilesUploader.UploadToFiles(file.FileStream, file.FileName, attachment.contentType, mailbox.EMailInFolder, new Guid(mailbox.UserId), log); if (uploaded_file_id < 0) { log.Error("EmailInMessageHandler HandleRetrievedMessage uploaded_file_id < 0"); } } } } catch (WebException we) { var status_code = ((HttpWebResponse)we.Response).StatusCode; if (status_code == HttpStatusCode.NotFound || status_code == HttpStatusCode.Forbidden) { MailBoxManager.CreateUploadToDocumentsFailureAlert(mailbox.TenantId, mailbox.UserId, mailbox.MailBoxId, (status_code == HttpStatusCode.NotFound) ? MailBoxManager.UploadToDocumentsErrorType .FolderNotFound : MailBoxManager.UploadToDocumentsErrorType .AccessDenied); MailBoxManager.SetMailboxEmailInFolder(mailbox.TenantId, mailbox.UserId, mailbox.MailBoxId, null); mailbox.EMailInFolder = null; } throw; } }
public int StoreAttachmentToMyDocuments(int attachment_id) { CoreContext.TenantManager.SetCurrentTenant(TenantId); var attachment = Manager.GetMessageAttachment(attachment_id, TenantId, UserIdString); if (attachment != null) { using (var file = Manager.GetAttachmentStream(attachment_id, TenantId, UserIdString)) { var uploaded_file_id = FilesUploader.UploadToFiles(file.FileStream, file.FileName, attachment.contentType, MyDocsFolderId, UserId); return(uploaded_file_id); } } return(-1); }
public List <int> StoreAttachmentsToMyDocuments(int message_id) { CoreContext.TenantManager.SetCurrentTenant(TenantId); var file_ids = new List <int>(); var attachments = Manager.GetMessageAttachments(TenantId, UserIdString, message_id); foreach (var attachment in attachments) { using (var file = AttachmentManager.GetAttachmentStream(attachment)) { var uploaded_file_id = FilesUploader.UploadToFiles(file.FileStream, file.FileName, attachment.contentType, MyDocsFolderId, UserId); if (uploaded_file_id > 0) { file_ids.Add(uploaded_file_id); } } } return(file_ids); }