Exemplo n.º 1
0
        internal static ImapMailboxInfo FromAnswer(string name, ImapAnswer answer)
        {
            var result = new ImapMailboxInfo()
            {
                Name = name,
            };

            foreach (var line in answer.GetDataLines())
            {
                if (line.StartsWith("* "))
                {
                    var parts = ImapParser.SplitAnswer(line);
                    switch (parts[1])
                    {
                    case "FLAGS":
                        result.Flags = parts[2].UnboxBrackets().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        continue;

                    case "OK":
                        if (parts.Length > 2)
                        {
                            var subParts = ImapParser.SplitAnswer(parts[2].UnboxBrackets());
                            switch (subParts[0])
                            {
                            case "PERMANENTFLAGS":
                                result.PermanentFlags = subParts[1].UnboxBrackets().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                continue;

                            case "UIDVALIDITY":
                                result.UidValidity = uint.Parse(subParts[1]);
                                continue;

                            case "UIDNEXT":
                                result.UidNext = uint.Parse(subParts[1]);
                                continue;

                            case "UNSEEN":
                                result.Unseen = uint.Parse(subParts[1]);
                                continue;
                            }
                        }
                        break;

                    default:
                        switch (parts[2])
                        {
                        case "EXISTS":
                            result.Exist = int.Parse(parts[1]);
                            continue;

                        case "RECENT":
                            result.Recent = int.Parse(parts[1]);
                            continue;
                        }
                        break;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        ImapAnswer ReadAnswer(string id, bool throwEx)
        {
            var answer = ImapParser.Parse(id, stream);

            if (throwEx && !answer.Success)
            {
                answer.Throw();
            }

            return(answer);
        }
Exemplo n.º 3
0
        /// <summary>Obtains a list of all present mailboxes.</summary>
        /// <returns></returns>
        public string[] ListMailboxes()
        {
            var list   = new List <string>();
            var answer = SendCommand("LIST \"\" *");

            foreach (var line in answer.GetDataLines())
            {
                if (line.StartsWith("* LIST "))
                {
                    var parts   = ImapParser.SplitAnswer(line);
                    var mailbox = parts[4].UnboxText(false);
                    mailbox = UTF7.DecodeExtendedUTF7(mailbox);
                    list.Add(mailbox);
                }
            }
            return(list.ToArray());
        }