Esempio n. 1
0
        static void Main(string[] args)
        {
            ImapClient ic = new ImapClient();

            for (;;)
            {
                if (caseSwitch == -1)
                {
                    break;
                }

                ShowMenu();

                Console.Write("A" + ic.commandNumber + ":  Preferred function : ");
                bool valid = Int32.TryParse(Console.ReadLine(), out caseSwitch);

                if (valid)
                {
                    switch (caseSwitch)
                    {
                    case 0:             // exit
                        if (ic.userAvailable)
                        {
                            ic.DcFromGmail();
                        }
                        caseSwitch = -1;
                        break;

                    case 1:             // log in
                        if (!ic.userAvailable)
                        {
                            ic.ConnectToGmail();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User has already logged in");
                        }
                        break;

                    case 2:             // log off
                        if (ic.userAvailable)
                        {
                            ic.DcFromGmail();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 3:             // inbox status
                        if (ic.userAvailable)
                        {
                            ic.DefaultStatus();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 4:             // Show all mailboxes
                        if (ic.userAvailable)
                        {
                            ic.SelectMailboxes();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 5:             // Select mailbox
                        if (ic.userAvailable)
                        {
                            ic.SelectMailbox();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 6:             // Close mailbox
                        if (ic.userAvailable)
                        {
                            ic.ClosetMailbox();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 7:             // Fetch Header
                        if (ic.userAvailable)
                        {
                            ic.FetchHead();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 8:             // Fetch date
                        if (ic.userAvailable)
                        {
                            ic.FetchDate();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 9:             // Flags: mark all as read
                        if (ic.userAvailable)
                        {
                            ic.SetAllRead();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 10:            // Flags: mark 1x as unread
                        if (ic.userAvailable)
                        {
                            ic.SetAsUnread();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 11:            // Expunge e-mail
                        if (ic.userAvailable)
                        {
                            ic.DeleteLetter();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 12:            // Search by criteria
                        if (ic.userAvailable)
                        {
                            ic.SearchByText();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 13:            // Search unseen UIDs
                        if (ic.userAvailable)
                        {
                            ic.SearchUnseenUIDs();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 14:            // Copy e-mail
                        if (ic.userAvailable)
                        {
                            ic.Copy();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 15:            // Create new mailbox
                        if (ic.userAvailable)
                        {
                            ic.CreateNew();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 16:            // Rename mailbox
                        if (ic.userAvailable)
                        {
                            ic.RenameMail();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 17:            // Delete mailbox
                        if (ic.userAvailable)
                        {
                            ic.DeleteMail();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 18:            // Check answer's validity
                        if (ic.userAvailable)
                        {
                            ic.DoNothing();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 19:            // Examine mailbox
                        if (ic.userAvailable)
                        {
                            ic.ExamineMailbox();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 20:            // Subscribe to a mailbox
                        if (ic.userAvailable)
                        {
                            ic.SubscribeMailbox();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 21:            // Unubscribe from a mailbox
                        if (ic.userAvailable)
                        {
                            ic.UnsubscribeMailbox();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 22:            // Check subscribes mailboxes
                        if (ic.userAvailable)
                        {
                            ic.CheckSubscribed();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 23:            // All e-mail IDs
                        if (ic.userAvailable)
                        {
                            ic.UIDSearch();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    case 24:            // All e-mail flags
                        if (ic.userAvailable)
                        {
                            ic.GetFlags();
                        }
                        else
                        {
                            Console.WriteLine("ERR : User is not logged in");
                        }
                        break;

                    default:
                        Console.WriteLine("Wrong choice.");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Wrong choice.");
                }
            }
        }