Example #1
0
 public List <MailBox> GetAllMailbox()
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         return(GetAllMailbox(ctx));
     }
 }
Example #2
0
        public MailBox CreateMailboxIfNotExist(string path, MSGorillaMailEntities ctx)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new Exception("Path can't be null");
            }
            if (path.Length > 256)
            {
                throw new Exception("Folder path too long. No more than 256 chars");
            }

            MailBox box = null;

            string[] split   = path.Split('/');
            string   curPath = "";

            foreach (string str in split)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    curPath += str;
                    box      = CreateSingleMailboxIfNotExist(curPath, ctx);
                    curPath += '/';
                }
            }
            ctx.SaveChanges();
            return(box);
        }
Example #3
0
 public MailBox GetMailbox(string path)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         return(GetMailbox(path, ctx));
     }
 }
Example #4
0
 public int GetUnseenMailCount(MailBox mailbox)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         return(GetUnseenMailCount(mailbox));
     }
 }
Example #5
0
 public int GetUnseenMailCount(MailBox mailbox, MSGorillaMailEntities ctx)
 {
     return(ctx.MailMessages.Count(mail => mail.MailboxID == mailbox.MailboxID && mail.Seen == false));
     //(from mailMessage in ctx.MailMessages
     //    where mailMessage.MailboxID == mailbox.MailboxID
     //        && mailMessage.Seen == false)
 }
Example #6
0
 public void AddMailMessage(string msgorillaMessageID, int size, int importance, int mailboxID)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         AddMailMessage(msgorillaMessageID, size, importance, mailboxID, ctx);
     }
 }
Example #7
0
 public List <MailBox> SearchMailbox(string name)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         return(SearchMailbox(name, ctx));
     }
 }
Example #8
0
        public void AddMailMessage(string msgorillaMessageID,
                                   int size,
                                   int importance,
                                   int mailboxID,
                                   MSGorillaMailEntities ctx)
        {
            MailBox mailbox = ctx.MailBoxes.Find(mailboxID);

            MailMessage message = new MailMessage();

            message.MailboxID          = mailbox.MailboxID;
            message.MSGorillaMessageID = msgorillaMessageID;
            message.Recent             = true;
            message.Seen           = false;
            message.Deleted        = false;
            message.SequenceNumber = mailbox.Exist + 1;
            message.Uid            = mailbox.UidNext;
            message.Important      = importance;
            message.Timestamp      = DateTime.UtcNow;
            message.Size           = size;

            ctx.MailMessages.Add(message);

            mailbox.UidNext++;
            mailbox.Recent++;
            mailbox.Exist++;
            ctx.SaveChanges();
        }
Example #9
0
 public MailBox GetMailbox(int id)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         return(GetMailbox(id, ctx));
     }
 }
Example #10
0
 public void DeleteMailboxIfExist(string path)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         DeleteMailboxIfExist(path, ctx);
         ctx.SaveChanges();
     }
 }
Example #11
0
 /// <summary>
 /// the size is wrong. This function need to be refined
 /// </summary>
 /// <param name="msgorillaMessageID"></param>
 /// <param name="mailbox"></param>
 /// <param name="ctx"></param>
 public void AddMailMessage(string msgorillaMessageID,
                            int size,
                            int importance,
                            MailBox mailbox,
                            MSGorillaMailEntities ctx)
 {
     AddMailMessage(msgorillaMessageID, size, importance, mailbox.MailboxID, ctx);
 }
Example #12
0
 public MailBox CreateMailboxIfNotExist(string path)
 {
     using (var ctx = new MSGorillaMailEntities())
     {
         MailBox mailbox = CreateMailboxIfNotExist(path, ctx);
         ctx.SaveChanges();
         return(mailbox);
     }
 }
Example #13
0
        public void DeleteMailboxIfExist(string path, MSGorillaMailEntities ctx)
        {
            MailBox mailbox = GetMailbox(path, ctx);

            if (mailbox != null)
            {
                ctx.MailBoxes.Remove(mailbox);
            }
        }
Example #14
0
 public List <MailBox> SearchMailbox(string name, MSGorillaMailEntities ctx)
 {
     if (name.Contains('%') || name.Contains('*'))
     {
         name = name.Replace('*', '%');
         return(ctx.MailBoxes.SqlQuery(
                    "select * from Mailbox where Userid = {0} and Path like {1}",
                    this.Userid,
                    name
                    ).ToList());
     }
     return(ctx.MailBoxes.Where(
                mailbox => mailbox.Userid == Userid && mailbox.Path == name
                ).ToList());
 }
Example #15
0
        protected MailBox CreateSingleMailboxIfNotExist(string path, MSGorillaMailEntities ctx)
        {
            if (GetMailbox(path, ctx) == null)
            {
                MailBox mailbox = new MailBox();
                mailbox.Path        = path;
                mailbox.Exist       = 0;
                mailbox.Recent      = 0;
                mailbox.UidNext     = 1;
                mailbox.UidValidity = 1;
                mailbox.Userid      = this.Userid;

                ctx.MailBoxes.Add(mailbox);
                return(mailbox);
            }
            return(ctx.MailBoxes.Where(mailbox => mailbox.Path == path && mailbox.Userid == Userid).FirstOrDefault());
        }
Example #16
0
 public List <MailBox> GetAllMailbox(MSGorillaMailEntities ctx)
 {
     return(ctx.MailBoxes.Where(mailbox => mailbox.Userid == Userid).ToList());
 }
Example #17
0
 public List <MailMessage> GetMailMessageBySeqIDRange(int start, int end, MailBox mailbox, MSGorillaMailEntities ctx)
 {
     return(ctx.MailMessages.Where(
                mail => mail.MailboxID == mailbox.MailboxID && mail.SequenceNumber >= start && mail.SequenceNumber <= end
                ).ToList());
 }
Example #18
0
 public MailMessage GetMailMessageByUid(int uid, MailBox mailbox, MSGorillaMailEntities ctx)
 {
     return(ctx.MailMessages.Where(
                mail => mail.Uid == uid && mail.MailboxID == mailbox.MailboxID
                ).FirstOrDefault());
 }
Example #19
0
 public List <MailMessage> GetMailMessageByUidRange(int start, int end, MailBox mailbox, MSGorillaMailEntities ctx)
 {
     return(ctx.MailMessages.Where(
                mail => mail.Uid >= start && mail.Uid <= end && mail.MailboxID == mailbox.MailboxID
                ).ToList());
 }
Example #20
0
 public MailMessage GetMailMessageBySeqID(int seqID, MailBox mailbox, MSGorillaMailEntities ctx)
 {
     return(ctx.MailMessages.Where(
                mail => mail.MailboxID == mailbox.MailboxID && mail.SequenceNumber == seqID
                ).FirstOrDefault());
 }
Example #21
0
 public MailBox GetMailbox(int id, MSGorillaMailEntities ctx)
 {
     return(ctx.MailBoxes.Find(id));
 }
Example #22
0
 public MailBox GetMailbox(string path, MSGorillaMailEntities ctx)
 {
     return(ctx.MailBoxes.Where(mailbox => mailbox.Path == path && mailbox.Userid == Userid).FirstOrDefault());
 }