Example #1
0
        public override IMAPShell.Shell.CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            bool errorsOnly = (Args.Length > 0 && Args[0].Equals("errors"));
            
            foreach (string logLine in Shell.Client.Aggregator.LogEntries)
            {
                bool thisLineIsError = false;
                string colorCode = "^07:00";
                if (logLine.Contains("WARN"))
                    colorCode = "^14:00";

                if (logLine.Contains("ERROR"))
                {
                    colorCode = "^12:00";
                    thisLineIsError = true;
                }

                if (logLine.Contains("INFO"))
                    colorCode = "^11:00";

                if (errorsOnly && thisLineIsError)
                    ColorConsole.WriteLine("{0}{1}", colorCode, logLine);
                else if (!errorsOnly)
                    ColorConsole.WriteLine("{0}{1}", colorCode, logLine);
            }

            return result;
        }
Example #2
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {
                Shell.Config.UseSSL = !Shell.Config.UseSSL;
                Shell.PrintConfig();
                Shell.Client.Stop();
                result.SuccessMessage = "Configuration has been updated.";
            }
            else
            {
                string state = Args[0].ToLower();
                if (state.Equals("on"))
                    Shell.Config.UseSSL = true;
                else if (state.Equals("off"))
                    Shell.Config.UseSSL = false;
                else
                {
                    return CommandResult.CreateError(Command, Args,
                                                     String.Format("Did not understand state '{0}'", state));
                }

                Shell.PrintConfig();
                Shell.Client.Stop();
                result.SuccessMessage = "Configuration has been updated.";

                
            }

            return result;
        }
Example #3
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {                
                return CommandResult.CreateError(Command, Args, "You must specify a folder to delete");
            }

            
            IFolder folderToKill = null;
            string folderToFind = Args.Length > 1 ? string.Join(" ", Args) : Args[0];

            folderToFind = folderToFind.Trim('"');

            folderToKill = Shell.FindFolder(folderToFind);

            if (folderToKill == null)
            {

                return CommandResult.CreateError(Command, Args,
                                                 String.Format("Could not find folder '{0}'", folderToFind));
            }

            Shell.Client.MailboxManager.DeleteFolder(folderToKill);

            return result;
        }
Example #4
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {                
                return CommandResult.CreateError(Command, Args, "You must specify a folder name");
            }

            if (Regex.Match(Args[0], "[\\\\/\\.]+").Success)            
            {                
                return CommandResult.CreateError(Command, Args, "Folder name cannot contain characters '\\' '/' '.'");
            }

            
            CreateFolderRequest cfr = new CreateFolderRequest(Args[0],Shell.CurrentFolder,
                delegate(IRequest req)
                    {
                        CreateFolderProcessor cfp = req.GetProcessorAsType<CreateFolderProcessor>();
                        if (cfp.FolderCreated)
                        {
                            IFolder parentFolder = Shell.CurrentFolder;
                            Shell.Client.MailboxManager.AddFolder(Args[0], parentFolder);
                        }
                        
                    });

            Shell.Client.RequestManager.SubmitAndWait(cfr, false);

            


            return result;
        }
Example #5
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {                
                return CommandResult.CreateError(Command, Args, "You must specify a config file to load");
            }

            string file = Args[0];
            if (File.Exists(file))
            {
                Shell.Client.Config = new IMAPConfig(file);
                Shell.Config = Shell.Client.Config;
                Shell.Client.Stop();
                Shell.PrintConfig();
                result.SuccessMessage = "Configuration loaded. Please re-connect.";
            }
            else
            {                
                return CommandResult.CreateError(Command, Args, String.Format("Could not find file '{0}'", file));
            }

            return result;
        }
Example #6
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            Shell.ClearScreen();

            return result;
        }
Example #7
0
        public override IMAPShell.Shell.CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            result.Type = ResultType.Exit;

            return result;
        }
Example #8
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {                
                return CommandResult.CreateError(Command, Args, "You are missing some arguments");
            }

            //Arguments args = new Arguments(Args);
            ArgumentParser parser = new ArgumentParser(Args);

            if (parser["o"] == null && parser["n"] == null)
            {
                return CommandResult.CreateError(Command, Args, "You are missing some arguments");
            }

            string sourceFolder = parser["o"].Trim(' ','"');
            string destFolder = parser["n"].Trim(' ','"');

            IFolder sourceFolderObj = Shell.FindFolder(sourceFolder);

            // if we can't find it at all, then throw an error
            if (sourceFolderObj == null)
            {
                return CommandResult.CreateError(Command, Args,
                                                 String.Format(
                                                     "The source folder '{0}' could not be found. Try specifying its full path.",
                                                     sourceFolder));
            }

            IFolder parentFolder = sourceFolderObj.Parent;
            RenameFolderRequest rfr = new RenameFolderRequest(sourceFolderObj, destFolder,
                delegate(IRequest req)
                    {
                        if (req.Result.Response == IMAPResponse.IMAP_SUCCESS_RESPONSE)
                        {
                            Shell.Client.MailboxManager.RenameFolder(sourceFolderObj, destFolder);
                        }
                    });

            Shell.Client.RequestManager.SubmitAndWait(rfr, false);

            return result;
        }
Example #9
0
        public override IMAPShell.Shell.CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length <= 0)
            {                
                return CommandResult.CreateError(Command, Args, "You must specify a server name.");
            }

            Shell.Config.Host = Args[0];
            result.Type = ResultType.Success;
            result.SuccessMessage = "Server configuration updated. Please reconnect.";

            Shell.PrintConfig();
            Shell.Client.Stop();

            return result;
        }
Example #10
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            IFolder cFolder = Shell.CurrentFolder;
            IFolder[] subFolders = Shell.Client.MailboxManager.GetChildFolders(cFolder);
            
            
            
            ColorConsole.WriteLine("\n^15:00 {0} {1}     {2}^07:00", ("Name").PadRight(30), ("Unseen").PadRight(2), ("Exists").PadRight(5));
            ColorConsole.Write("^08:00{0}", new string('-', Console.BufferWidth));
            foreach (IFolder f in subFolders)
            {
                ColorConsole.WriteLine("^07:00{0}{1} {2}     {3}", f.SubFolders.Length > 0 ? "+":" ", f.Name.PadRight(30), f.Unseen.ToString().PadLeft(6), f.Exists.ToString().PadLeft(6));
            }

            Console.WriteLine();

            return result;
        }
Example #11
0
        public override IMAPShell.Shell.CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Shell.Config.ConfigFile == null)
            {
                if (Args.Length == 0)
                {                    
                    return CommandResult.CreateError(Command, Args, "You must specify a config file to save to");
                }
                else
                {
                    Shell.Config.ConfigFile = Args[0];
                }
            }

            Shell.Config.SaveConfig();
            result.SuccessMessage = String.Format("Configuration has been saved to {0}", Shell.Config.ConfigFile);

            return result;
        }
Example #12
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            ArgumentParser parser = new ArgumentParser(Args);
            if (parser.Count < 2)
            {                
                return CommandResult.CreateError(Command, Args, "Incorrect number of arguments");
            }

            if (parser["f"] == null && parser["p"] == null)
            {                
                return CommandResult.CreateError(Command, Args, "Missing -f and/or -p arguments");
            }

            IFolder sourceFolder = Shell.FindFolder(parser["f"].Trim());
            IFolder parentFolder = Shell.FindFolder(parser["p"].Trim());

            if (sourceFolder == null)
                return CommandResult.CreateError(Command, Args, "Source folder could not be found");
            

            if (parentFolder == null && !parser["p"].Trim().Equals("/"))
                return CommandResult.CreateError(Command, Args, "Parent folder could not be found");

            if (sourceFolder == Shell.CurrentFolder)
            {
                return CommandResult.CreateError(Command, Args,
                                                 "You cannot move the current folder. Please change to a different folder first.");
            }

            Shell.Client.RequestManager.SubmitAndWait(new MoveFolderRequest(sourceFolder, parentFolder,
                delegate(IRequest req)
                    {
                        if (req.Result.Response == IMAPResponse.IMAP_SUCCESS_RESPONSE)
                            Shell.Client.MailboxManager.MoveFolder(sourceFolder, parentFolder);
                    }),false);

            return result;
        }
Example #13
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args != null && Args.Length > 0)
            {
                string cmd = Args[0];
                if (Shell.AvailableCommands.Contains(cmd))
                {
                    Shell.PrintHelp(Args[0]);
                    return result;
                }
                else
                {                    
                    return CommandResult.CreateError(Command, Args, String.Format("Command '{0}' not recognized", cmd));
                }
            }
            
            Shell.PrintHelp(null);

            return result;
        }
Example #14
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {
                Shell.PrintConfig();
                return result;
            }

            if (Args[0].Equals("-p"))
            {
                Shell.PrintFullConfig(true);
                return result;
            }
            else
            {
                return CommandResult.CreateError(Command, Args,
                                                 String.Format("Invalid parameters: {0}", string.Join(" ", Args)));
            }

            return result;
        }
Example #15
0
        public override IMAPShell.Shell.CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);


            Console.Write("Enter new password: ");
            string password = PasswordInput.ReadPassword();
            Console.Write("Confirm password: ");
            string confirm = PasswordInput.ReadPassword();
            if (password.CompareTo(confirm)==0)
            {
                result.SuccessMessage = "Password has been updated.";
                Shell.Config.Password = password;
                Shell.PrintConfig();
                return result;
            }
            else
            {                
                return CommandResult.CreateError(Command, Args, "Passwords do not match. Please try again.");
            }

            return result;
        }
Example #16
0
 public static CommandResult CreateError(string cmd, string[] args, string msg)
 {
     CommandResult result = new CommandResult(cmd, args);
     result.Type = ResultType.Error;
     result.ErrorMessage = msg;
     return result;
 }
Example #17
0
        private bool ProcessResult(CommandResult result)
        {

            switch (result.Type)
            {
                case ResultType.Exit:
                    return true;
                case ResultType.Invalid:
                    ColorConsole.WriteLine("^14:00Command '{0}' not recognized. Type 'help' to see list of valid commands.", result.Command);
                    return false;
                case ResultType.Error:
                    ColorConsole.WriteLine("\n^04:00A problem was encountered when trying to execute '{0}'", result.Command);
                    ColorConsole.Write("^08:00{0}", new string('-', Console.BufferWidth));
                    ColorConsole.WriteLine("^12:00{0}", result.ErrorMessage);
                    ColorConsole.WriteLine("^08:00{0}", new string('-', Console.BufferWidth));
                    ProcessCommand("printresult errors");
                    ColorConsole.WriteLine("^08:00{0}", new string('-', Console.BufferWidth));
                    return false;
                case ResultType.Success:
                    if (!String.IsNullOrEmpty(result.SuccessMessage))
                    {
                        ColorConsole.Write("\n^03:00{0}", new string('-', Console.BufferWidth));
                        ColorConsole.WriteLine("^11:00{0}", result.SuccessMessage);
                        ColorConsole.Write("^03:00{0}\n", new string('-', Console.BufferWidth));
                    }
                    return false;
            }
            return false;
        }
Example #18
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);
            /*
             * Here is where things get interesting. In order to make this command work as efficiently 
             * as possible the best route to take is to download and display the header data for messages 
             * 20 or so at a time. After each group the user can choose to get the next group, go back to
             * the previous group, view details of a specific message, or cancel.
             * 
             * Possible arguments
             * 
             * -s <num>     message number to start with
             * -e <num>     message number to end with
             * 
             * */
            if (Shell.CurrentFolder == null)
            {                
                return CommandResult.CreateError(Command, Args, "This folder does not contain any message data.");
            }
            Shell.Client.Aggregator.ClearLogs();
            Arguments processedArgs = new Arguments(Args);

            // first we have to get all the UIDs for the messages in the current folder
            bool messageListComplete = false;
            Shell.Client.RequestManager.SubmitRequest(
                new MessageListRequest(Shell.CurrentFolder, delegate
                                                              {
                                                                  messageListComplete = true;
                                                              }),false);
            while (!messageListComplete) {}
            MessageListDirection direction = MessageListDirection.Descending;
            if (Args.Length > 0)
            {
                if (Args[0].Equals("desc"))
                    direction = MessageListDirection.Descending;
                else if (Args[0].Equals("asc"))
                    direction = MessageListDirection.Ascending;
            }

            IMessage[] msgList = Shell.Client.MailboxManager.GetMessagesByFolder(Shell.CurrentFolder, direction);

            if (msgList.Length == 0)
            {
                result.SuccessMessage = "This folder does not contain any messages.";
                return result;
            }

            bool view;
            bool del;
            int uid;
            DoMessageGroups(msgList, out view, out del, out uid);

            if (view)
            {
                ColorConsole.WriteLine("\nViewing message {0}\n", uid);
            }

            if (del)
            {
                DeleteMessage(uid);
            }

            return result;
        }
Example #19
0
        private CommandResult ProcessCommand(string command)
        {
            CommandResult result = new CommandResult(command, null);

            if (command.Equals(""))
            {
                result.Type = ResultType.Success;
                return result;
            }

            _cmdHistory.Add(command);

            string actualCommand = command;
            string[] args = null;
            if (command.Contains(" "))
            {
                string[] temp = command.Split(' ');
                actualCommand = temp[0];                
                List<string> tempArgs = new List<string>(temp);
                tempArgs.RemoveAt(0);
                args = tempArgs.ToArray();
            }

            if (_commandMap.ContainsKey(actualCommand))
            {
                Type cmdType = _commandMap[actualCommand];
                if (_requiresConnection.Contains(cmdType) && !Client.ReadyToGo)
                {
                    result.Type = ResultType.Error;
                    result.ErrorMessage =
                        "This command requires an active connection. Please connect to the server and then try this command again.";
                    return result;
                }
                ICommand cmd = (ICommand)Activator.CreateInstance(cmdType, this, args);
                result = cmd.Execute();
            }
            else
            {
                result.Type = ResultType.Invalid;
            }

            return result;
        }
Example #20
0
        public override CommandResult Execute()
        {
            CommandResult result = new CommandResult(Command, Args);

            if (Args.Length == 0)
            {
                string folderName = null;
                folderName = Shell.CurrentFolder == null ? "/" : Shell.CurrentFolder.FullPath;
                Console.WriteLine(folderName);
                return result;
            }

            string newFolderName = null;
            IFolder newFolder = null;

            if (Args.Length > 1) // if folder name has spaces, combine separate args into one folder name
            {
                newFolderName = string.Join(" ", Args);
                    
            }
            else
            {
                newFolderName = Args[0];
            }

            if (newFolderName.Equals("."))
            {                
                return result;
            }

            if (newFolderName.Equals(".."))
            {
                if (Shell.CurrentFolder != null)
                {
                    if (Shell.CurrentFolder.ParentID > -1)
                    {
                        newFolder = Shell.Client.MailboxManager.GetFolderByID(Shell.CurrentFolder.ParentID);
                        SetCurrentFolder(newFolder);
                        return result;
                    }
                    else
                    {
                        SetCurrentFolder(null);
                        return result;
                    }

                }
                
            }

            // first we check if the specified folder is a sub folder of the current folder
            
            foreach (IFolder folder in (Shell.CurrentFolder == null ? Shell.Client.MailboxManager.Folders : Shell.CurrentFolder.SubFolders))
            {
                if (folder.Name.Equals(newFolderName) || folder.FullPath.Equals(newFolderName))
                {
                    newFolder = folder;
                    SetCurrentFolder(newFolder);
                    return result;
                }
            }

            // if we didn't find it there, then we check all folders, compile a list of all folders
            // that match the file name regardless of full path, and let the user chose which folder
            // they would like to select. If the result is only 1, then we just use that.
            
            List<IFolder> matchingFolderList = new List<IFolder>();
            foreach (IFolder folder in Shell.Client.MailboxManager.GetAllFolders())
            {
                if (!folder.Name.Equals(newFolderName) && !folder.FullPath.Equals(newFolderName)) continue;
                matchingFolderList.Add(folder);
            }

            if (matchingFolderList.Count == 1)
            {
                newFolder = matchingFolderList[0];
                SetCurrentFolder(newFolder);
                return result;
            }
            else
            {
                SetCurrentFolder(PromptMatchingFolders(matchingFolderList.ToArray()));
            }
           

            return result;
        }