Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();
            wbMailRenderer.ContextMenu = new ContextMenu();
            wbMailRenderer.ResetZoom();

            // Initial start of the program. Here we will check if the user already has an account or not.
            // v0.1 - simple check; will write a decent settings loader later
            //if (Properties.Settings.Default.Accounts == null || Properties.Settings.Default.Accounts.Count == 0)
            App.Log.Info("Checking application settings");
            if (Properties.Settings.Default.Accounts == null || String.IsNullOrWhiteSpace(Properties.Settings.Default.Accounts))
            {
                App.Log.Info("No settings found, showing the account creation window.");
                if (Properties.Settings.Default.Accounts == null)
                {
                    //Properties.Settings.Default.Accounts = new Accounts();
                    //Properties.Settings.Default.Save();
                }


                // No accounts configured yet.
                // Show the Account creation window
                var acctCreation = new AccountCreation();
                acctCreation.ShowDialog();

                if (acctCreation.DialogResult.HasValue && acctCreation.DialogResult.Value)
                {
                    var acct = acctCreation.Account;
                    AccountController.Account = acct;

                    //Properties.Settings.Default.Accounts.Add(acct);
                    //Properties.Settings.Default.Save();
                }
                else
                {
                    Application.Current.Shutdown();
                    Environment.Exit(0);
                }
            }
            else // Load the existing accounts
            {
                App.Log.Info("Application settings found, now loading.");
                //AccountController.Account = Properties.Settings.Default.Accounts[0];
            }

            // Using Imap
            new Imap(AccountController.Account);
            App.Log.Info("Imap initialized.");

            // Now list the available folders
            var mailboxes = Imap.Client.List("", "*");

            App.Log.Info("Mailboxes loaded.");
            App.Log.Debug("Number of mailboxes: " + mailboxes.Mailboxes.Count());


            // Fill the list with mailboxes
            lstMailboxes.ItemsSource = mailboxes.Mailboxes;

            // Check for unread messages
            //CheckForUnreadMessages();

            // Always make sure there is a mailbox selected
            if (lstMailboxes.SelectedIndex < 0)
            {
                lstMailboxes.SelectedIndex = 1;
            }
        }