예제 #1
0
        public IMAPHostRecord Create(string host, uint uid, DateTime from)
        {
            var item = this.repository.Table.FirstOrDefault(c => c.Host.ToLower() == host.ToLower());

            if (item != null)
            {
                throw new ArgumentException("There is an existing record with the Host:" + host);
            }

            item          = new IMAPHostRecord();
            item.Host     = host;
            item.EmailUid = uid;
            item.FromDate = from;
            this.repository.Create(item);

            return(item);
        }
예제 #2
0
        private void RaiseWorkflow(IMAPHostRecord hostRecord, MailMessage mail, uint id)
        {
            var contentManager   = this.orchardServices.ContentManager;
            var emailContentItem = contentManager.New(IMAPEmailPart.ContentItemTypeName);
            var emailPart        = emailContentItem.As <IMAPEmailPart>();

            // I don't know why it is null
            if (emailPart == null)
            {
                emailPart = new IMAPEmailPart();
                emailContentItem.Weld(emailPart);
            }

            emailPart.MailMessage = mail;
            dynamic sender = new JObject();

            sender.Name  = mail.From.DisplayName;
            sender.Email = mail.From.Address;
            var user = this.userRepository.Table.FirstOrDefault(c => c.Email.ToLower() == mail.From.Address.ToLower());

            if (user != null)
            {
                var commonPart = emailContentItem.As <CommonPart>();
                commonPart.Owner = contentManager.Get <IUser>(user.Id);
                sender.UserId    = user.Id;
                sender.UserName  = user.UserName;
            }

            emailPart.From    = JsonConvert.SerializeObject(sender);
            emailPart.Subject = string.IsNullOrEmpty(mail.Subject) ? this.T("[No subject]").Text : mail.Subject;
            emailPart.UId     = id;

            contentManager.Create(emailContentItem);
            contentManager.Publish(emailContentItem);

            workflowManager.TriggerEvent(
                IMapEmailReceivedActivity.ActivityName,
                emailContentItem,
                () => new Dictionary <string, object> {
                { "Content", emailContentItem }
            });

            hostRecord.EmailUid = id;
            this.imapHostRecordService.Save(hostRecord);
        }
예제 #3
0
 public void Save(IMAPHostRecord record)
 {
     this.repository.Update(record);
     this.repository.Flush();
 }