public string StoreMailBody(int id_tenant, string id_user, MailMessageItem mail)
        {
            if (string.IsNullOrEmpty(mail.HtmlBody))
            {
                return(string.Empty);
            }

            // Using id_user as domain in S3 Storage - allows not to add quota to tenant.
            var save_path = MailStoragePathCombiner.GetBodyKey(id_user, mail.StreamId);
            var storage   = MailDataStore.GetDataStore(id_tenant);

            try
            {
                var safe_body = ReplaceEmbeddedImages(mail);

                using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(safe_body)))
                {
                    var res = storage
                              .UploadWithoutQuota(string.Empty, save_path, reader, "text/html", string.Empty)
                              .ToString();

                    _log.Debug("StoreMailBody() tenant='{0}', user_id='{1}', save_body_path='{2}' Result: {3}",
                               id_tenant, id_user, save_path, res);

                    return(res);
                }
            }
            catch (Exception)
            {
                storage.Delete(string.Empty, save_path);
                _log.Debug(String.Format("StoreMailBody() Problems with message saving in messageId={0}. Body was deleted.", mail.MimeMessageId));
                throw;
            }
        }
Ejemplo n.º 2
0
        public string StoreMailBody(int id_tenant, string id_user, MailMessageItem mail)
        {
            try
            {
                if (!string.IsNullOrEmpty(mail.HtmlBody))
                {
                    var safe_body = ReplaceEmbeddedImages(mail);

                    using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(safe_body)))
                    {
                        // Using id_user as domain in S3 Storage - allows not to add quota to tenant.
                        var save_body_path = MailStoragePathCombiner.GetBodyKey(id_user, mail.StreamId);

                        return(GetDataStore(id_tenant)
                               .UploadWithoutQuota(string.Empty, save_body_path, reader, "text/html", string.Empty)
                               .ToString());
                    }
                }

                return(string.Empty);
            }
            catch (Exception)
            {
                GetDataStore(id_tenant).Delete(string.Empty, MailStoragePathCombiner.GetBodyKey(id_user, mail.StreamId));
                _log.Debug(String.Format("Problems with message saving in messageId={0}. Body was deleted.", mail.MessageId));
                throw;
            }
        }
        public string StoreMailBody(int tenant, string user, MailMessage messageItem)
        {
            if (string.IsNullOrEmpty(messageItem.HtmlBody))
            {
                return(string.Empty);
            }

            // Using id_user as domain in S3 Storage - allows not to add quota to tenant.
            var savePath = MailStoragePathCombiner.GetBodyKey(user, messageItem.StreamId);
            var storage  = MailDataStore.GetDataStore(tenant);

            try
            {
                using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(messageItem.HtmlBody)))
                {
                    var res = storage
                              .UploadWithoutQuota(string.Empty, savePath, reader, "text/html", string.Empty)
                              .ToString();

                    _log.Debug("StoreMailBody() tenant='{0}', user_id='{1}', save_body_path='{2}' Result: {3}",
                               tenant, user, savePath, res);

                    return(res);
                }
            }
            catch (Exception ex)
            {
                _log.Debug(
                    "StoreMailBody() Problems with message saving in messageId={0}. \r\n Exception: \r\n {0}\r\n",
                    messageItem.MimeMessageId, ex.ToString());

                storage.Delete(string.Empty, savePath);
                throw;
            }
        }
        public string StoreMailBody(MailBox mailBox, MailMessage messageItem)
        {
            if (string.IsNullOrEmpty(messageItem.HtmlBody) && (messageItem.HtmlBodyStream == null || messageItem.HtmlBodyStream.Length == 0))
            {
                return(string.Empty);
            }

            // Using id_user as domain in S3 Storage - allows not to add quota to tenant.
            var savePath = MailStoragePathCombiner.GetBodyKey(mailBox.UserId, messageItem.StreamId);
            var storage  = MailDataStore.GetDataStore(mailBox.TenantId);

            storage.QuotaController = null;

            try
            {
                string response;

                if (messageItem.HtmlBodyStream != null && messageItem.HtmlBodyStream.Length > 0)
                {
                    messageItem.HtmlBodyStream.Seek(0, SeekOrigin.Begin);

                    response = storage
                               .Save(savePath, messageItem.HtmlBodyStream, MailStoragePathCombiner.BODY_FILE_NAME)
                               .ToString();
                }
                else
                {
                    using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(messageItem.HtmlBody)))
                    {
                        response = storage
                                   .Save(savePath, reader, MailStoragePathCombiner.BODY_FILE_NAME)
                                   .ToString();
                    }
                }

                _log.Debug("StoreMailBody() tenant='{0}', user_id='{1}', save_body_path='{2}' Result: {3}",
                           mailBox.TenantId, mailBox.UserId, savePath, response);

                return(response);
            }
            catch (Exception ex)
            {
                _log.Debug(
                    "StoreMailBody() Problems with message saving in messageId={0}. \r\n Exception: \r\n {0}\r\n",
                    messageItem.MimeMessageId, ex.ToString());

                storage.Delete(string.Empty, savePath);
                throw;
            }
        }
Ejemplo n.º 5
0
 public MailMessageGarbage(string user, int id, string stream)
 {
     _id   = id;
     _path = MailStoragePathCombiner.GetBodyKey(user, stream);
 }