Ejemplo n.º 1
0
        public static List <ImapResponse> Execute(MailDb mailDb, string args)
        {
            var parts = TextUtils.SplitQuotedString(args, ' ', false, 2);

            string folderName = IMAP_Utils.DecodeMailbox(TextUtils.UnQuoteString(parts[0]));

            if (!(parts[1].StartsWith("(") && parts[1].EndsWith(")")))
            {
                throw new Exception("Error in arguments.");
            }

            var index     = args.IndexOf(" ");
            var folderArg = args.Substring(0, index);

            var folder = new SelectFolder(folderName, mailDb);
            var stat   = folder.Stat;

            var commandReader = new CommandReader(parts[1]);
            var AllDataItems  = commandReader.ReadAllDataItems();

            var builder = new StringBuilder()
                          .Append("* STATUS ").Append(folderArg).Append(" (");

            var first = true;

            foreach (var each in AllDataItems)
            {
                if (!first)
                {
                    builder.Append(" ");
                }
                switch (each.Name)
                {
                case "MESSAGES":
                    builder.Append("MESSAGES ").Append(stat.Exists);
                    break;

                case "RECENT":
                    builder.Append("RECENT ").Append(stat.Recent);
                    break;

                case "UIDNEXT":
                    builder.Append("UIDNEXT ").Append(stat.NextUid);
                    break;

                case "UIDVALIDITY":
                    builder.Append("UIDVALIDITY ").Append(stat.FolderUid);
                    break;

                case "UNSEEN":
                    builder.Append("UNSEEN ").Append(stat.UnSeen);
                    break;

                default:
                    break;
                }
                if (first)
                {
                    first = false;
                }
            }

            builder.Append(")");

            return(new List <ImapResponse>
            {
                new ImapResponse(builder.ToString())
            });
        }