Exemplo n.º 1
0
        public MailClientForm()
        {
            InitializeComponent();
            ImportExportTool = new ImportExportTool(this);

            EmailCollection = ImportExportTool.LoadCollection();
            if (EmailCollection == null)
            {
                EmailCollection = new ConcurrentDictionary <string, CollectionEmail>();
            }

            FolderList = ImportExportTool.LoadFolderList();
            if (FolderList == null)
            {
                FolderList = new ConcurrentDictionary <string, CustomFolder>();
            }

            Type         dgvType = dataGridViewEmails.GetType();
            PropertyInfo pi      = dgvType.GetProperty("DoubleBuffered",
                                                       BindingFlags.Instance | BindingFlags.NonPublic);

            pi.SetValue(dataGridViewEmails, true, null);
            dataGridViewEmails.MouseDown                         += dataGridViewEmails_MouseDown;
            dataGridViewEmails.RowTemplate.Height                 = 45;
            dataGridViewEmails.RowTemplate.Resizable              = DataGridViewTriState.False;
            dataGridViewEmails.ColumnHeadersHeightSizeMode        = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dataGridViewEmails.ColumnHeadersHeight                = 30;
            dataGridViewEmails.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", 12F, GraphicsUnit.Pixel);

            dataGridViewEmails.DefaultCellStyle.SelectionBackColor = Color.LightSkyBlue;
            dataGridViewEmails.DefaultCellStyle.SelectionForeColor = Color.Black;
            dataGridViewEmails.DefaultCellStyle.Font = new Font("Segoe UI", 15F, GraphicsUnit.Pixel);
            loginForm = new LoginForm(this);
        }
Exemplo n.º 2
0
 private void MailClientForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (MailReceiver != null)
     {
         ImportExportTool.SaveCollectionToDb();
         ImportExportTool.SaveFolderListToDb();
     }
 }
Exemplo n.º 3
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (comboBoxImportFrom.Text == "" || comboBoxImportTo.Text == "")
            {
                MessageBox.Show("Please provide valid parameters.", "Failed");
                return;
            }
            if (comboBoxImportFrom.Text == "Gmail" || comboBoxImportFrom.Text == "Yandex" || comboBoxImportFrom.Text == "Custom Folder")
            {
                if (comboBoxServerFolder.Text == "" || tbUsername.Text == "" || tbPassword.Text == "")
                {
                    MessageBox.Show("Please provide valid parameters.", "Failed");
                    return;
                }
            }
            if (comboBoxImportFrom.Text == "Custom Folder")
            {
                if (textBoxImap.Text == "" || textBoxImapPort.Text == "")
                {
                    MessageBox.Show("Please provide valid parameters.", "Failed");
                    return;
                }
            }

            EmailType destinationType       = new EmailType();
            string    destinationFolderName = comboBoxImportTo.Text;

            _importExportTool    = new ImportExportTool(_parentForm);
            buttonImport.Enabled = false;
            buttonImport.Text    = "Importing...";

            switch (comboBoxImportTo.Text)
            {
            case "Inbox":
            {
                destinationType = EmailType.Inbox;
            }
            break;

            case "Sent Emails":
            {
                destinationType = EmailType.SentEmails;
            }
            break;

            default:
            {
                destinationType = EmailType.CollectionEmail;
            }
            break;
            }

            EmailType sourceType = new EmailType();

            if (comboBoxServerFolder.Text == "Inbox")
            {
                sourceType = EmailType.Inbox;
            }
            else if (comboBoxServerFolder.Text == "Sent Emails")
            {
                sourceType = EmailType.SentEmails;
            }

            if (comboBoxImportFrom.Text == "Gmail")
            {
                Task.Run(() =>
                {
                    this.Invoke((Action)(() => pictureBoxLoading.Visible = true));

                    _importExportTool.ImportEmailsFromServer(
                        new ServerInfo(ServerInfo.ServerPreset.Gmail), sourceType, destinationType,
                        tbUsername.Text, tbPassword.Text, destinationFolderName);

                    this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                    this.Invoke((Action)(() => this.Close()));
                });
            }
            else if (comboBoxImportFrom.Text == "Yandex")
            {
                Task.Run(() =>
                {
                    this.Invoke((Action)(() => pictureBoxLoading.Visible = true));

                    _importExportTool.ImportEmailsFromServer(
                        new ServerInfo(ServerInfo.ServerPreset.Yandex), sourceType, destinationType,
                        tbUsername.Text, tbPassword.Text, destinationFolderName);

                    this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                    this.Invoke((Action)(() => this.Close()));
                });
            }
            else if (comboBoxImportFrom.Text == "Custom Server")
            {
                if (!Regex.IsMatch(textBoxImapPort.Text, @"^\d+$"))
                {
                    MessageBox.Show("IMAP port must be numeric value", "Failed");
                    return;
                }

                var serverInfo = new ServerInfo(textBoxImap.Text, Convert.ToInt32(textBoxImapPort.Text));

                Task.Run(() =>
                {
                    this.Invoke((Action)(() => pictureBoxLoading.Visible = true));

                    _importExportTool.ImportEmailsFromServer(
                        serverInfo, sourceType, destinationType,
                        tbUsername.Text, tbPassword.Text, destinationFolderName);

                    this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                    this.Invoke((Action)(() => this.Close()));
                });
            }
            else
            {
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

                folderBrowserDialog.Description = "Browse for folder that contains .eml files";
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    Task.Run(() =>
                    {
                        this.Invoke((Action)(() => pictureBoxLoading.Visible = true));

                        _importExportTool.ImportEmailsFromFile(destinationType, folderBrowserDialog.SelectedPath, destinationFolderName);

                        this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                        this.Invoke((Action)(() => this.Close()));
                    });
                }
            }
        }
Exemplo n.º 4
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            if (comboBoxExportFrom.Text == "")
            {
                MessageBox.Show("Please provide valid parameters.", "Failed");
                return;
            }

            EmailType sourceType       = new EmailType();
            string    sourceFolderName = comboBoxExportFrom.Text;

            _importExportTool    = new ImportExportTool(_parentForm);
            buttonImport.Enabled = false;
            buttonImport.Text    = "Exporting...";

            var folderBrowserDialog1 = new FolderBrowserDialog();

            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            switch (comboBoxExportFrom.Text)
            {
            case "Inbox":
            {
                sourceType = EmailType.Inbox;

                Task.Run(() =>
                    {
                        this.Invoke((Action)(() => pictureBoxLoading.Visible = true));
                        _importExportTool.ExportEmails(sourceType, folderBrowserDialog1.SelectedPath);
                        this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                        this.Invoke((Action)(() => this.Close()));
                    });
            }
            break;

            case "Sent Emails":
            {
                sourceType = EmailType.SentEmails;

                Task.Run(() =>
                    {
                        this.Invoke((Action)(() => pictureBoxLoading.Visible = true));
                        _importExportTool.ExportEmails(sourceType, folderBrowserDialog1.SelectedPath);
                        this.Invoke((Action)(() => pictureBoxLoading.Visible = false));
                        this.Invoke((Action)(() => this.Close()));
                    });
            }
            break;

            default:
            {
                sourceType = EmailType.CollectionEmail;
                _importExportTool.ExportEmails(sourceType, folderBrowserDialog1.SelectedPath, sourceFolderName);
                this.Close();
            }
            break;
            }
        }