Example #1
0
        public virtual Mailbox[] ListSuscribesMailboxes(string reference, string pattern)
        {
            IdlePause();

            var x = new List<Mailbox>();
            string command = GetTag() + "LSUB " + reference.QuoteString() + " " + pattern.QuoteString();
            string reg = "\\* LSUB \\(([^\\)]*)\\) \\\"([^\\\"]+)\\\" \\\"([^\\\"]+)\\\"";
            string response = SendCommandGetResponse(command);
            Match m = Regex.Match(response, reg);
            while (m.Groups.Count > 1) {
                Mailbox mailbox = new Mailbox(m.Groups[3].ToString());
                x.Add(mailbox);
                response = GetResponse();
                m = Regex.Match(response, reg);
            }
            IdleResume();
            return x.ToArray();
        }
Example #2
0
        public virtual Mailbox SelectMailbox(string mailboxName)
        {
            IdlePause();

            mailboxName = ModifiedUtf7Encoding.Encode(mailboxName);
            var tag = GetTag();
            var command = tag + "SELECT " + mailboxName.QuoteString();
            var response = SendCommandGetResponse(command);
            if (IsResultOK(response))
                response = GetResponse();
            var mailbox = new Mailbox(mailboxName);
            Match match;

            while (response.StartsWith("*")) {
                if ((match = Regex.Match(response, @"\d+(?=\s+EXISTS)")).Success)
                    mailbox.NumMsg = match.Value.ToInt();

                else if ((match = Regex.Match(response, @"\d+(?=\s+RECENT)")).Success)
                    mailbox.NumNewMsg = match.Value.ToInt();

                else if ((match = Regex.Match(response, @"(?<=UNSEEN\s+)\d+")).Success)
                    mailbox.NumUnSeen = match.Value.ToInt();

                else if ((match = Regex.Match(response, @"(?<=\sFLAGS\s+\().*?(?=\))")).Success)
                    mailbox.SetFlags(match.Value);

                response = GetResponse();
            }

            CheckResultOK(response);
            mailbox.IsWritable = Regex.IsMatch(response, "READ.WRITE", RegexOptions.IgnoreCase);
            _SelectedMailbox = mailboxName;

            IdleResume();
            return mailbox;
        }
Example #3
0
        public virtual Mailbox SelectMailbox(string mailbox)
        {
            IdlePause();

            mailbox = ModifiedUtf7Encoding.Encode(mailbox);
            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;
        }
Example #4
0
        public virtual Mailbox Examine(string mailbox)
        {
            IdlePause();

            Mailbox x = null;
            string tag = GetTag();
            string command = tag + "EXAMINE " + ModifiedUtf7Encoding.Encode(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;
        }
Example #5
0
        protected virtual string HandleUntaggedResponse(string response, Mailbox mailbox)
        {
            Match match;
            while (response.StartsWith("*"))
            {
                if (mailbox != null)
                {
                    if ((match = Regex.Match(response, @"\d+(?=\s+EXISTS)")).Success)
                        mailbox.NumMsg = match.Value.ToInt();

                    else if ((match = Regex.Match(response, @"\d+(?=\s+RECENT)")).Success)
                        mailbox.NumNewMsg = match.Value.ToInt();

                    else if ((match = Regex.Match(response, @"(?<=UNSEEN\s+)\d+")).Success)
                        mailbox.NumUnSeen = match.Value.ToInt();

                    else if ((match = Regex.Match(response, @"(?<=\sFLAGS\s+\().*?(?=\))")).Success)
                        mailbox.SetFlags(match.Value);

                    else if ((match = Regex.Match(response, @"UIDVALIDITY (\d+)")).Success)
                        mailbox.UIDValidity = match.Groups[1].Value.ToInt();

                    else if (response.StartsWith("* CAPABILITY "))
                    {
                        response = response.Substring(13);
                        _Capability = response.Trim().Split(' ');
                    }

                    else if (response.StartsWith("* OK"))
                    {

                    }

                    else return response;
                }
                response = GetResponse();
            }

            return response;
        }
Example #6
0
 protected virtual string SendCommandGetResponse(string command, Mailbox mailbox)
 {
     var response = base.SendCommandGetResponse(command);
     response = HandleUntaggedResponse(response, Mailbox);
     return response;
 }
Example #7
0
        public virtual Mailbox[] ListMailboxes(string reference, string pattern)
        {
            IdlePause();

            var x = new List<Mailbox>();
            string command = GetTag() + "LIST " + reference.QuoteString() + " " + pattern.QuoteString();
            const string reg = "\\* LIST \\(([^\\)]*)\\) \\\"([^\\\"]+)\\\" \\\"?([^\\\"]+)\\\"?";
            string response = SendCommandGetResponse(command);
            Match m = Regex.Match(response, reg);
            while (m.Groups.Count > 1)
            {
                Mailbox mailbox = new Mailbox(_utf7.Decode(m.Groups[3].Value));
                mailbox.SetFlags(m.Groups[1].Value);
                x.Add(mailbox);
                response = GetResponse();
                m = Regex.Match(response, reg);
            }
            IdleResume();
            return x.ToArray();
        }
Example #8
0
        public virtual Mailbox SelectMailbox(string mailboxName)
        {
            IdlePause();

            var tag = GetTag();
            var command = tag + "SELECT " + _utf7.Encode(mailboxName).QuoteString();
            _Mailbox = new Mailbox(mailboxName);
            _SelectedMailbox = mailboxName;
            var response = SendCommandGetResponse(command);

            CheckResultOK(response);
            _Mailbox.IsWritable = Regex.IsMatch(response, "READ.WRITE", RegexOptions.IgnoreCase);

            IdleResume();
            return _Mailbox;
        }
Example #9
0
        private static void ParseSelectResponseLine( Mailbox mailbox, string response )
        {
            Match m;
            m = Regex.Match( response, @"(\d+) EXISTS" );
            if ( m.Groups.Count > 1 )
                mailbox.NumMsg = Convert.ToInt32( m.Groups[1].ToString() );

            m = Regex.Match( response, @"(\d+) RECENT" );
            if ( m.Groups.Count > 1 )
                mailbox.NumNewMsg = Convert.ToInt32( m.Groups[1].ToString() );

            m = Regex.Match( response, @"UNSEEN (\d+)" );
            if ( m.Groups.Count > 1 )
            {
                mailbox.FirstUnseenUid = Int32.Parse( m.Groups[1].Value );
                mailbox.NumUnSeen = mailbox.FirstUnseenUid.Value;
            }

            m = Regex.Match( response, @"UIDNEXT (\d+)" );
            if ( m.Groups.Count > 1 )
            {
                mailbox.NextUid = Int32.Parse( m.Groups[1].Value );
            }

            m = Regex.Match( response, @" FLAGS \((.*?)\)" );
            if ( m.Groups.Count > 1 )
                mailbox.SetFlags( m.Groups[1].ToString() );
        }
Example #10
0
        public virtual Mailbox SelectMailbox( string mailbox )
        {
            IdlePause();

            mailbox = ModifiedUtf7Encoding.Encode( mailbox );
            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( "*" ) )
                {
                    ParseSelectResponseLine( x, response );
                    response = GetResponse();
                }
                if ( IsResultOK( response ) )
                {
                    x.IsWritable = Regex.IsMatch( response, "READ.WRITE", RegexOptions.IgnoreCase );
                }
                _SelectedMailbox = mailbox;
            }
            else
            {
                throw new Exception( response );
            }
            IdleResume();
            return x;
        }
Example #11
0
        public virtual Mailbox Examine(string mailbox)
        {
            IdlePause();

            Mailbox x = null;
            string tag = GetTag();
            string command = tag + "EXAMINE " + ModifiedUtf7Encoding.Encode(mailbox).QuoteString();
            string response = SendCommandGetResponse(command);
            if (response.StartsWith("*")) {
                x = new Mailbox(mailbox);
                while (response.StartsWith("*")) {
                    ParseSelectResponseLine( x, response );
                    response = GetResponse();
                }
                _SelectedMailbox = mailbox;
            }
            IdleResume();
            return x;
        }
Example #12
0
        public Mailbox SelectMailbox(string mailbox)
        {
            IdlePause();

            Mailbox x = null;
            string tag = GetTag();
            string command = tag + "SELECT \"" + mailbox + "\"";
            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 = _Reader.ReadLine();
                }
                if (response.StartsWith(tag + "OK")) {
                    if (response.ToUpper().IndexOf("READ-WRITE") > -1) x.Rw = true;
                }
                _selectedmailbox = mailbox;
            }
            IdleResume();
            return x;
        }
Example #13
0
        public Mailbox[] ListMailboxes(string reference, string pattern)
        {
            IdlePause();

            var x = new List<Mailbox>();
            string command = GetTag() + "LIST \"" + reference + "\" \"" + pattern + "\"";
            string reg = "\\* LIST \\(([^\\)]*)\\) \\\"([^\\\"]+)\\\" \\\"([^\\\"]+)\\\"";
            string response = SendCommandGetResponse(command);
            Match m = Regex.Match(response, reg);
            while (m.Groups.Count > 1) {
                Mailbox mailbox = new Mailbox(m.Groups[3].ToString());
                x.Add(mailbox);
                response = _Reader.ReadLine();
                m = Regex.Match(response, reg);
            }
            IdleResume();
            return x.ToArray();
        }