Esempio n. 1
0
        public EmailHistoryDTO SaveHistory(EmailHistoryDTO dto)
        {
            ValidationResult validationResult;

            if (this.IsValid(dto, out validationResult))
            {
                if (dto.body != null)
                {
                    var message = dto.body;
                    message = Regex.Replace(message, "<[^>]*(>|$)", string.Empty);
                    message = message.Replace("\r\n", "\n").Replace("\r", "\n").Replace("&nbsp;", " ").Replace("&#39;", @"'");
                    message = Regex.Replace(message, @"[ ]{2,}", " ");
                    message = message.Replace("\n ", "\n");
                    message = Regex.Replace(message, @"[\n]{2,}", "\n");
                    message = message.Replace("Enriching online interaction for meetings, training and education on Adobe Connect", string.Empty);
                    message = message.TrimStart("\n".ToCharArray());

                    dto.message = message;
                }

                var emailHistory = ConvertDto(dto);

                this.EmailHistoryModel.RegisterSave(emailHistory, true);

                return(new EmailHistoryDTO(emailHistory));
            }

            var error = this.GenerateValidationError(validationResult);

            this.LogError("EmailHistory.Save", error);
            throw new FaultException <Error>(error, error.errorMessage);
        }
Esempio n. 2
0
 private EmailHistory ConvertDto(EmailHistoryDTO history)
 {
     return(new EmailHistory
     {
         Body = history.body,
         Date = history.date.ConvertFromUnixTimeStamp(),
         Message = history.message,
         SentBcc = history.sentBcc,
         SentCc = history.sentCc,
         SentFrom = history.sentFrom,
         SentTo = history.sentTo,
         Subject = history.subject,
         User = this.UserModel.GetOneByEmail(history.sentTo).Value,
         Status = history.status,
     });
 }
Esempio n. 3
0
        /// <summary>
        /// The resend email.
        /// </summary>
        /// <param name="emailHistoryId">
        /// The email history id.
        /// </param>
        /// <returns>
        /// The <see cref="EmailHistoryDTO"/>.
        /// </returns>
        /// <exception cref="FaultException{T}">
        /// Exception if sending failed
        /// </exception>
        public EmailHistoryDTO ResendEmail(int emailHistoryId)
        {
            var item = EmailHistoryModel.GetOneById(emailHistoryId).Value;

            if (item != null)
            {
                var cc = item.SentCc != null
                             ? FormEmailList(item.SentCc)
                             : new List <MailAddress>();

                var bcc = item.SentBcc != null
                             ? FormEmailList(item.SentBcc)
                             : new List <MailAddress>();

                MailModel.SendEmail(
                    item.SentToName != null ? item.SentToName.Split(';').ToArray() : new string[] { },
                    item.SentTo != null ? item.SentTo.Split(';').ToArray() : new string[] { },
                    item.Subject,
                    item.Body,
                    item.SentFromName,
                    item.SentFrom,
                    null,
                    cc,
                    bcc);

                var newHistoryItem = new EmailHistoryDTO(item)
                {
                    body           = item.Body,
                    date           = DateTime.Now.ConvertToUnixTimestamp(),
                    emailHistoryId = 0
                };
                return(this.SaveHistory(newHistoryItem));
            }

            var error = new Error(Errors.CODE_ERRORTYPE_GENERIC_ERROR, ErrorsTexts.GetResultError_NotFound, "No item with such id found");

            this.LogError("EmailService.Save", error);
            throw new FaultException <Error>(error, error.errorMessage);
        }