Beispiel #1
0
        }                                                         //給Thread呼叫用

        private void UpdateIMAPQuota(object o)
        {
            if (RegSetting.hasRight(FConstants.FeatureByte.Hide))
            {
                IMAPQuotaLock = false;
                return;
            }

            int    QuotaStatus = 0; //0=normal, 1=full, 2=very ful, -1=can't check
            string IMAPQuotaLabel = "-", IMAPQuotaTip = "-";

            using (var client = new ImapClient())
            {
                try
                {
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true; //ignore SSL certification
                    client.Connect(RegSetting.IMAPServerIP, 993, SecureSocketOptions.SslOnConnect);

                    // Bug of MailKit
                    // https://stackoverflow.com/questions/39573233/mailkit-authenticate-to-imap-fails
                    client.AuthenticationMechanisms.Remove("NTLM");

                    client.Authenticate(RegSetting.EMail, RegSetting.getPassword());
                    //client.Authenticate("*****@*****.**", "Hansone04");

                    if (client.Capabilities.HasFlag(ImapCapabilities.Quota))
                    {
                        var quota = client.Inbox.GetQuota();

                        if (quota.StorageLimit.HasValue && quota.StorageLimit.Value > 0)
                        {
                            IMAPQuotaTip = (quota.CurrentStorageSize.Value > 976.5625) ?
                                           string.Format("{0:0.00}MB / {1}MB", quota.CurrentStorageSize.Value / 976.5625, quota.StorageLimit.Value / 1000000) :
                                           string.Format("{0:0}KB / {1}MB", quota.CurrentStorageSize.Value, quota.StorageLimit.Value / 1000000);
                            IMAPQuotaLabel = (quota.CurrentStorageSize.Value > 976.5625) ?
                                             string.Format("{0:0}\r\n", quota.CurrentStorageSize.Value / 976.5625) :
                                             string.Format("{0:0}\r\nKB", quota.CurrentStorageSize.Value);
                            if (quota.CurrentStorageSize.Value * 1000 > quota.StorageLimit.Value)
                            {
                                QuotaStatus = 1; //mailbox full
                            }
                            if (quota.CurrentStorageSize.Value * 1000 / 3 > quota.StorageLimit.Value)
                            {
                                QuotaStatus = 2; //mailbox very full
                            }
                        }
                        else
                        {
                            QuotaStatus  = -1;  //can't get quota
                            IMAPQuotaTip = "Server does not provide Quota informaiton.";
                        }
                    }
                    client.Disconnect(true);
                }
                catch (Exception ex)
                {
                    QuotaStatus  = -1;  //can't get quota
                    IMAPQuotaTip = ex.Message.ToString();
                }
            }

            this.BeginInvoke(new MethodInvoker(delegate
            {
                switch (QuotaStatus)
                {
                case -1:        // Can't get Quota
                    label_IMAPQuota.Image = (Image)Resources.QuotaUnAvailable;
                    toolTip.SetToolTip(label_IMAPQuota, "Can't get MailBox Quota, something wrong!\r\n" + IMAPQuotaTip);
                    label_IMAPQuota.ForeColor = Color.Gray;
                    label_IMAPQuota.Text      = "-\r\n";
                    break;

                case 0:         // Mailbox normal
                    label_IMAPQuota.Image = (Image)Resources.QuotaAvailable;
                    toolTip.SetToolTip(label_IMAPQuota, "MailBox Quota: " + IMAPQuotaTip);
                    label_IMAPQuota.ForeColor = Color.Gray;
                    label_IMAPQuota.Text      = IMAPQuotaLabel;
                    break;

                case 2:
                    UpdateMSGtoUI($"MailBox Full! Please clean up ASAP! ({IMAPQuotaTip})");
                    goto case 1;

                case 1:         // Mailbox full
                    label_IMAPQuota.Image = (Image)Resources.QuotaAvailable;
                    toolTip.SetToolTip(label_IMAPQuota, "MailBox Quota Exceed!: " + IMAPQuotaTip + "\r\n Clean up MailBox now!");
                    label_IMAPQuota.ForeColor = Color.Red;
                    label_IMAPQuota.Text      = IMAPQuotaLabel;
                    break;

                default:
                    break;
                }
            }));

            IMAPQuotaLock = false;
        }
Beispiel #2
0
        private void FormSetting_Load(object sender, EventArgs e)
        {
            RegSetting.GetSettingsFromRegistry();

            //// Version Text
            label_Version.Text = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

            //// Advanced - LogLevel
            comboBox_LogLevel.DataSource         = Enum.GetValues(typeof(FConstants.FreyaLogLevel));
            comboBox_LogLevel.SelectedItem       = RegSetting.LogLevel;
            checkBox_SMTPLogWriterEnable.Checked = RegSetting.SMTPLogWriterEnable;

            //// Mail - Email Addres
            textBox_Email.Text = RegSetting.EMail;
            if (textBox_Email.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - Password
            textBox_Password.Text = RegSetting.getPassword();
            if (textBox_Password.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - IMAP Server
            textBox_IMAPServer.Text = RegSetting.IMAPServerIP;
            if (textBox_IMAPServer.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - SMTP Server
            textBox_SMTPServer.Text = RegSetting.SMTPServerIP;
            if (textBox_SMTPServer.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - WebService
            textBox_WebService.Text = RegSetting.WebServiceIP;
            if (textBox_WebService.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - SMTPLogLevel
            string[] SMTPLogLevels = { "None", "Critical", "Error", "Warning", "Information", "Verbose", "Raw" };
            comboBox_SMTPLogLevel.Items.AddRange(SMTPLogLevels);
            string SMTPLogLevel = RegSetting.SMTPLogLevel;

            comboBox_SMTPLogLevel.SelectedItem = (SMTPLogLevel == null) ? SMTPLogLevels[0] : SMTPLogLevel;

            //// DMS - Enable/Disable
            checkBox_DMSEnable.Checked = RegSetting.DMS_Enable;
            setDMSControlsStatus();

            textBox_DMS_UserID.Text            = RegSetting.DMS_Setting.UserID;
            textBox_DMS_Password.Text          = RegSetting.DMS_Setting.getPassword();
            textBox_DMS_Action.Text            = RegSetting.DMS_Setting.Action;
            textBox_DMS_Target.Text            = RegSetting.DMS_Setting.Target;
            textBox_DMS_Event.Text             = RegSetting.DMS_Setting.Event;
            dateTimePicker_DMS_From.Value      = RegSetting.DMS_Setting.From;
            dateTimePicker_DMS_To.Value        = RegSetting.DMS_Setting.To;
            dateTimePicker_DMS_TriggerAt.Value = RegSetting.DMS_TriggerAt;
            numericUpDown_DMS_Items.Value      = (RegSetting.DMS_Setting.Items >= numericUpDown_DMS_Items.Minimum && RegSetting.DMS_Setting.Items <= numericUpDown_DMS_Items.Maximum) ? RegSetting.DMS_Setting.Items : numericUpDown_DMS_Items.Minimum;
            label_DMS_hours.Text = string.Format("Total hours : {0}",
                                                 dateTimePicker_DMS_To.Value.TimeOfDay.Subtract(dateTimePicker_DMS_From.Value.TimeOfDay).TotalHours.ToString());

            Dictionary <string, string> ComboboxItem = new Dictionary <string, string>();

            ComboboxItem.Add(RegSetting.DMS_Setting.project, RegSetting.DMS_Setting.projectname);
            comboBox_DMS_Projects.DisplayMember = "Value";
            comboBox_DMS_Projects.ValueMember   = "Key";
            comboBox_DMS_Projects.DataSource    = new BindingSource(ComboboxItem, null);
            comboBox_DMS_Projects.SelectedIndex = 0;


            /// --------------------------------------------------------------
            /// Encryotion
            /// --------------------------------------------------------------
            ///
            string[] EncryptionMethods = { "StringCipher", "CeasarCipher" };
            comboBox_EncryptionMethod.Items.AddRange(EncryptionMethods);
            comboBox_EncryptionMethod.SelectedItem = EncryptionMethods[1];


            // 把每個tabpage都跑一次,讓每個控制項都initialize
            for (int i = 0; i < tabControl1.TabCount; i++)
            {
                tabControl1.SelectedIndex = i;
            }
            tabControl1.SelectedIndex = 0;

            //// 確認哪些UI要顯示
            if (RegSetting.hasRight(FConstants.FeatureByte.Hide))
            {
                UI_Adjust(0);   //Hide mode
            }
            else if (RegSetting.hasRight(FConstants.FeatureByte.Odin))
            {
                UI_Adjust(3);   //Odie mode
            }
            else
            {
                UI_Adjust(1);   //Normal mode
            }
            //reset switchs
            sw_needIMAPAuthCheck = false;
            restartProxy         = false;
        }