示例#1
0
        static void Main(string[] args)
        {
            // init
            var u = Prompt("Mail: ");
            var p = Prompt("Pass: "******"https://remote.stenoweb.net/EWS/Exchange.asmx";

            exchange.Credentials = new WebCredentials(u, p);
            try
            {
                exchange.AutodiscoverUrl(u, ad => ad.StartsWith("https"));
            }
            catch (AutodiscoverLocalException)
            {
                exchange.Url = new Uri(e);
            }
            // my exchange server doesn't like using email as username
            // so just go for the URL
            catch (FormatException)
            {
                exchange.Url = new Uri(e);
            }

            // state
            Folder f = Folder.Bind(exchange, WellKnownFolderName.Inbox);
            FindItemsResults <Item> lastList = GetFolderItems(f.Id, 10, 0);
            var folders = GetFolders();

            int pageSize = 10;
            int offset   = 0;

            bool prompting = true;

            while (prompting)
            {
                var command = Prompt(f.DisplayName + "> ");
                int number  = -1;

                if (command == "folders")
                {
                    FoldersCommand(folders);
                }
                else if (command.StartsWith("cd "))
                {
                    FolderId id = CdCommand(command.Remove(0, 3), folders);
                    if (id != null)
                    {
                        offset   = 0;
                        f        = Folder.Bind(exchange, id);
                        lastList = GetFolderItems(id, pageSize, offset);
                    }
                }
                else if (command == "ls")
                {
                    LsCommand(lastList);
                }
                else if (command == "n")
                {
                    lastList = GetFolderItems(f.Id, pageSize, pageSize * ++offset);
                }
                else if (command == "p")
                {
                    lastList = GetFolderItems(f.Id, pageSize, pageSize * --offset);
                }
                else if (int.TryParse(command, out number))
                {
                    // the message given state
                    var m = lastList.Skip(number).FirstOrDefault();
                    if (m != null && m.GetType() == typeof(EmailMessage))
                    {
                        EmailMessage full = EmailMessage.Bind(exchange, m.Id);
                        PrintEmail(full);
                    }
                    else
                    {
                        Console.WriteLine("no message (tried paginating?)");
                    }
                }
            }
        }