Пример #1
0
        MailStore.MailStore GetMailStore(string userid)
        {
            if (_mailStoreCache.Contains(userid))
            {
                return(_mailStoreCache[userid] as MailStore.MailStore);
            }

            MailStore.MailStore store = new MailStore.MailStore(userid);
            _mailStoreCache.Add(userid, store, DateTime.Now.AddHours(12));  //cache 12 hours
            return(store);
        }
Пример #2
0
        int GetMailBoxID(string userid, string path)
        {
            string key = string.Format("{0};{1}", userid, path);

            if (_mailboxCache.Contains(key))
            {
                return((int)_mailboxCache[key]);
            }

            MailStore.MailStore store   = GetMailStore(userid);
            MailBox             mailbox = store.CreateMailboxIfNotExist(path);

            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTime.Now.AddHours(24);
            _mailboxCache.Set(key, mailbox.MailboxID, policy);

            //_mailboxCache.Add(key, mailbox.MailboxID, DateTime.Now.AddHours(12));
            return(mailbox.MailboxID);
        }
Пример #3
0
 public AuthenticatedState(IMAPSession session, string username)
     : base(session)
 {
     this.User  = username;
     this.store = new MailStore.MailStore(this.User);
 }
Пример #4
0
        public void DispatchMail(Message msg)
        {
            int    defaultMailLength = 0;
            string richMessage       = null;

            if (string.IsNullOrEmpty(msg.RichMessageID))
            {
                richMessage = _richMsgManager.GetRichMessage(richMessage);
            }

            defaultMailLength = MSGorillaMailGenerator.CreateTextMessageMail(msg, richMessage, "somebody").Length;

            try
            {
                //Owner
                if (msg.Owner != null)
                {
                    foreach (string owner in msg.Owner)
                    {
                        MailStore.MailStore store = GetMailStore(owner);
                        int boxID = GetMailBoxID(owner, "Inbox/Own");
                        store.AddMailMessage(msg.ID,
                                             defaultMailLength - "somebody".Length + owner.Length,
                                             msg.Importance,
                                             boxID);
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                Trace.TraceError(e.StackTrace);
            }

            try
            {
                //Mention
                if (msg.AtUser != null)
                {
                    foreach (string userid in msg.AtUser)
                    {
                        MailStore.MailStore store = GetMailStore(userid);
                        int boxID = GetMailBoxID(userid, "Inbox/Mention");
                        store.AddMailMessage(msg.ID,
                                             defaultMailLength - "somebody".Length + userid.Length,
                                             msg.Importance,
                                             boxID);
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                Trace.TraceError(e.StackTrace);
            }

            try
            {
                //Home/Group
                foreach (string userid in GetGroupFollower(msg.Group, msg.User))
                {
                    MailStore.MailStore store = GetMailStore(userid);
                    int boxID = GetMailBoxID(userid, "Inbox/Home/" + GetGroupDisplayName(msg.Group));
                    store.AddMailMessage(msg.ID,
                                         defaultMailLength - "somebody".Length + userid.Length,
                                         msg.Importance,
                                         boxID);
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                Trace.TraceError(e.StackTrace);
            }

            try
            {
                //Topic/Topics
                if (msg.TopicName != null)
                {
                    foreach (var topicName in msg.TopicName)
                    {
                        Topic topic = _topicManager.FindTopicByName(topicName, msg.Group);
                        List <FavouriteTopic> whoLikesTopic = null;
                        using (var ctx = new MSGorillaEntities())
                        {
                            whoLikesTopic = ctx.FavouriteTopics.Where(fa => fa.TopicID == topic.Id).ToList();
                        }
                        foreach (var fa in whoLikesTopic)
                        {
                            string userid             = fa.Userid;
                            MailStore.MailStore store = GetMailStore(userid);
                            int boxID = GetMailBoxID(userid,
                                                     string.Format("Inbox/Topic/{0}({1})", topic.Name, GetGroupDisplayName(topic.GroupID)));
                            store.AddMailMessage(msg.ID,
                                                 defaultMailLength - "somebody".Length + userid.Length,
                                                 msg.Importance,
                                                 boxID);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                Trace.TraceError(e.StackTrace);
            }
        }