コード例 #1
0
ファイル: ImapClient.cs プロジェクト: achingono/WinPhoneGmail
        public virtual async Task<Mailbox[]> ListSuscribesMailboxesAsync(string reference, string pattern)
        {
            await IdlePauseAsync();

            var x = new List<Mailbox>();
            string command = GetTag() + "LSUB " + reference.QuoteString() + " " + pattern.QuoteString();
            string reg = "\\* LSUB \\(([^\\)]*)\\) \\\"([^\\\"]+)\\\" \\\"([^\\\"]+)\\\"";
            string response = await SendCommandGetResponseAsync(command);
            Match m = Regex.Match(response, reg);
            while (m.Groups.Count > 1)
            {
                Mailbox mailbox = new Mailbox(m.Groups[3].ToString());
                x.Add(mailbox);
                response = await GetResponseAsync();
                m = Regex.Match(response, reg);
            }
            await IdleResumeAsync();
            return x.ToArray();
        }
コード例 #2
0
ファイル: ImapClient.cs プロジェクト: achingono/WinPhoneGmail
        /*
        public virtual Lazy<MailMessage>[] SearchMessages(SearchCondition criteria, bool headersonly = false, bool setseen = false)
        {
            return Search(criteria, true)
                    .Select(x => new Lazy<MailMessage>(() => GetMessage(x, headersonly, setseen)))
                    .ToArray();
        }
        */
        public virtual async Task<Mailbox> SelectMailboxAsync(string mailboxName)
        {
            await IdlePauseAsync();

            mailboxName = ModifiedUtf7Encoding.Encode(mailboxName);
            var tag = GetTag();
            var command = tag + "SELECT " + mailboxName.QuoteString();
            var response = await SendCommandGetResponseAsync(command);
            if (IsResultOK(response))
                response = await GetResponseAsync();
            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 = await GetResponseAsync();
            }

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

            await IdleResumeAsync();
            return mailbox;
        }
コード例 #3
0
ファイル: ImapClient.cs プロジェクト: achingono/WinPhoneGmail
        public virtual async Task<Mailbox> ExamineAsync(string mailbox)
        {
            await IdlePauseAsync();

            Mailbox x = null;
            string tag = GetTag();
            string command = tag + "EXAMINE " + ModifiedUtf7Encoding.Encode(mailbox).QuoteString();
            string response = await SendCommandGetResponseAsync(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 = m.Groups[1].ToString().ToInt();

                    m = Regex.Match(response, @"(\d+) RECENT");
                    if (m.Groups.Count > 1)
                        x.NumNewMsg = m.Groups[1].Value.ToInt();

                    m = Regex.Match(response, @"UNSEEN (\d+)");
                    if (m.Groups.Count > 1)
                        x.NumUnSeen = m.Groups[1].Value.ToInt();

                    m = Regex.Match(response, @"UIDVALIDITY (\d+)");
                    if (m.Groups.Count > 1)
                        x.UIDValidity = m.Groups[1].Value.ToInt();

                    m = Regex.Match(response, @" FLAGS \((.*?)\)");
                    if (m.Groups.Count > 1)
                        x.SetFlags(m.Groups[1].ToString());

                    response = await GetResponseAsync();
                }
                _SelectedMailbox = mailbox;
            }
            await IdleResumeAsync();
            return x;
        }