Exemplo n.º 1
0
        public Mailbox SelectMailbox(string mailbox)
        {
            IdlePause();

            Mailbox x        = null;
            string  tag      = GetTag();
            string  command  = tag + "SELECT " + mailbox.QuoteString();
            string  response = SendCommandGetResponse(command);

            if (response.StartsWith("*"))
            {
                x = new Mailbox(mailbox);
                while (response.StartsWith("*"))
                {
                    Match m;
                    m = Regex.Match(response, @"(\d+) EXISTS");
                    if (m.Groups.Count > 1)
                    {
                        x.NumMsg = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @"(\d+) RECENT");
                    if (m.Groups.Count > 1)
                    {
                        x.NumNewMsg = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @"UNSEEN (\d+)");
                    if (m.Groups.Count > 1)
                    {
                        x.NumUnSeen = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @" FLAGS \((.*?)\)");
                    if (m.Groups.Count > 1)
                    {
                        x.SetFlags(m.Groups[1].ToString());
                    }
                    response = GetResponse();
                }
                if (IsResultOK(response))
                {
                    x.IsWritable = Regex.IsMatch(response, "READ.WRITE", RegexOptions.IgnoreCase);
                }
                _SelectedMailbox = mailbox;
            }
            else
            {
                throw new Exception(response);
            }
            IdleResume();
            return(x);
        }
Exemplo n.º 2
0
        public Mailbox Examine(string mailbox)
        {
            IdlePause();

            Mailbox x        = null;
            string  tag      = GetTag();
            string  command  = tag + "EXAMINE " + mailbox.QuoteString();
            string  response = SendCommandGetResponse(command);

            if (response.StartsWith("*"))
            {
                x = new Mailbox(mailbox);
                while (response.StartsWith("*"))
                {
                    Match m;
                    m = Regex.Match(response, @"(\d+) EXISTS");
                    if (m.Groups.Count > 1)
                    {
                        x.NumMsg = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @"(\d+) RECENT");
                    if (m.Groups.Count > 1)
                    {
                        x.NumNewMsg = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @"UNSEEN (\d+)");
                    if (m.Groups.Count > 1)
                    {
                        x.NumUnSeen = Convert.ToInt32(m.Groups[1].ToString());
                    }
                    m = Regex.Match(response, @" FLAGS \((.*?)\)");
                    if (m.Groups.Count > 1)
                    {
                        x.SetFlags(m.Groups[1].ToString());
                    }
                    response = GetResponse();
                }
                _SelectedMailbox = mailbox;
            }
            IdleResume();
            return(x);
        }