Exemple #1
0
        public bool AddEmail(string mail, int groupID)
        {
            string userID = "";

            if (_httpContextAccessor != null && _httpContextAccessor.HttpContext != null && _httpContextAccessor.HttpContext.User != null &&
                _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier) != null && !String.IsNullOrEmpty(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            }
            else
            {
                return(false);
            }

            var emails = _mailRepository.GetAll(groupID, userID);

            if (emails.Any(x => x.Email == mail))
            {
                return(false);
            }
            else
            {
                _mailRepository.Create(mail, groupID, userID);
            }

            return(true);
        }
Exemple #2
0
        private bool SaveMessage(ILogger <MailDamMessageStore> logger, IMailRepository mailRepository, MemoryStream messageStream, Guid mailId, MimeMessage message, Guid mailboxId, Guid sessionId)
        {
            try
            {
                var mail = new Mail
                {
                    MailId      = mailId,
                    HtmlBody    = message.HtmlBody,
                    TextBody    = message.TextBody,
                    From        = string.Join(",", message.From.Mailboxes.Select(m => !string.IsNullOrWhiteSpace(m.Name) ? $"{m.Name} <{m.Address}>" : m.Address).ToList()),
                    To          = string.Join(",", message.To.Mailboxes.Select(m => !string.IsNullOrWhiteSpace(m.Name) ? $"{m.Name} <{m.Address}>" : m.Address).ToList()),
                    ReceiveDate = DateTime.Now,
                    MailboxId   = mailboxId,
                    Status      = (int)MailStatus.Unread,
                    Subject     = message.Subject,
                    RawEmail    = messageStream.ToArray()
                };

                mailRepository.Create(mail);

                logger.LogInformation($"Storing mail {mailId} in session {sessionId} for mailbox {mailboxId}");

                return(true);
            }
            catch (Exception e)
            {
                logger.LogError(e, $"Storing of mail failed with in session {sessionId} for mailbox {mailboxId} because: {e.Message}");

                return(false);
            }
        }
 public OperationResult Create(CreateMail entity)
 {
     try
     {
         const string source = "*****@*****.**";
         var          mail   = new Mail(entity.Destination, entity.Subject, entity.Message, source);
         _mailRepository.Create(mail);
         _mailRepository.SaveChanges();
         return(_operation.But(Tables.MailTableName).Succeeded(MailMessages.Success));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
         return(_operation.Failed(MailMessages.Failed));
     }
 }
        public void Compose(ComposeMail command)
        {
            var mail = new Mail
            {
                Id             = 1,
                Subject        = command.Subject,
                Message        = command.Message,
                Sender         = command.Sender,
                Receiver       = command.Receiver,
                HasAttachments = false,
                IsDeleted      = false,
                IsRead         = false,
                SendDate       = DateTime.Now
            };

            //mail.CheckSomething(command.Sender, command.Receiver);
            _mailRepository.Create(mail);
        }