private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) { var result = MessageBox.Show($"Are you sure you want to delete {dataGridViewEmails.SelectedRows.Count} folder/s?", "Delete", MessageBoxButtons.YesNoCancel); if (result != DialogResult.Yes) { return; } foreach (DataGridViewRow row in dataGridViewEmails.SelectedRows) { CustomFolder folder; FolderList.TryRemove((string)row.Cells[0].Value, out folder); foreach (var email in EmailCollection.Values) { CollectionEmail collectionEmail; if (email.CustomFolderName == (string)row.Cells[0].Value) { EmailCollection.TryRemove(email.Id, out collectionEmail); } } dataGridViewEmails.Rows.RemoveAt(row.Index); } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { var result = MessageBox.Show($"Are you sure you want to delete {dataGridViewEmails.SelectedRows.Count} email/s?", "Delete", MessageBoxButtons.YesNoCancel); if (result != DialogResult.Yes) { return; } Task.Run(() => { if (CurrentView == EmailView.CustomFolder) { foreach (DataGridViewRow row in dataGridViewEmails.SelectedRows) { CollectionEmail collectionEmail; var selectedEmail = EmailCollection[(string)row.Cells[0].Value]; --FolderList[OpenedCustomFolderName].ItemCount; EmailCollection.TryRemove(selectedEmail.Id, out collectionEmail); } } else { foreach (DataGridViewRow row in dataGridViewEmails.SelectedRows) { if (CurrentView == EmailView.Inbox) { InboxEmail inboxEmail; var selectedEmail = ReceivedEmails[(string)row.Cells[0].Value]; MailReceiver.DeleteEmail(EmailType.Inbox, selectedEmail.UniqueId); ReceivedEmails.TryRemove(selectedEmail.Id, out inboxEmail); } else { SentEmail sentEmail; var selectedEmail = SentEmails[(string)row.Cells[0].Value]; MailReceiver.DeleteEmail(EmailType.SentEmails, selectedEmail.UniqueId); SentEmails.TryRemove(selectedEmail.Id, out sentEmail); } } } this.Invoke((Action)(() => toolStripButtonRefresh.PerformClick())); }); }
private void moveToToolStripMenuItem1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { Task.Run(() => { if (CurrentView == EmailView.CustomFolder) { foreach (DataGridViewRow row in dataGridViewEmails.SelectedRows) { var selectedEmail = GetCustomFolderList(OpenedCustomFolderName)[(string)row.Cells[0].Value]; var oldFolder = FolderList[selectedEmail.CustomFolderName]; --oldFolder.ItemCount; if (e.ClickedItem.Text == "Sent Emails") { var message = new MimeMessage(); message.From.Add(new MailboxAddress(selectedEmail.From)); message.To.Add(new MailboxAddress(selectedEmail.To)); message.Subject = selectedEmail.Subject; message.Body = new TextPart("plain") { Text = selectedEmail.TextBody }; message.Date = selectedEmail.Date; MailReceiver.AddMessageToFolder(EmailType.SentEmails, message); CollectionEmail collectionEmail; EmailCollection.TryRemove(selectedEmail.Id, out collectionEmail); } else if (e.ClickedItem.Text == "Inbox") { var message = new MimeMessage(); message.From.Add(new MailboxAddress(selectedEmail.From)); message.To.Add(new MailboxAddress(selectedEmail.To)); message.Subject = selectedEmail.Subject; message.Body = new TextPart("plain") { Text = selectedEmail.TextBody }; message.Date = selectedEmail.Date; MailReceiver.AddMessageToFolder(EmailType.Inbox, message); CollectionEmail collectionEmail; EmailCollection.TryRemove(selectedEmail.Id, out collectionEmail); } else { var selectedFolderId = FolderList.FirstOrDefault(x => x.Value.FolderName == e.ClickedItem.Text).Value.FolderName; var selectedFolder = FolderList[selectedFolderId]; ++selectedFolder.ItemCount; selectedEmail.CustomFolderName = selectedFolderId; } } } else { foreach (DataGridViewRow row in dataGridViewEmails.SelectedRows) { if (CurrentView == EmailView.Inbox) { var selectedEmail = ReceivedEmails[(string)row.Cells[0].Value]; var selectedFolderName = FolderList.FirstOrDefault(x => x.Value.FolderName == e.ClickedItem.Text).Value.FolderName; var selectedFolder = FolderList[selectedFolderName]; if (EmailCollection.ContainsKey(selectedEmail.Id)) { MessageBox.Show("This email already exists in collection.", "Moving failed"); return; } var email = MailReceiver.GetEmail(EmailType.Inbox, selectedEmail.UniqueId); ++selectedFolder.ItemCount; EmailCollection.TryAdd(selectedEmail.Id, new CollectionEmail { Id = selectedEmail.Id, From = selectedEmail.From, To = selectedEmail.To, Subject = selectedEmail.Subject, TextBody = email.TextBody, HtmlBody = email.HtmlBody, Date = selectedEmail.ArrivalTime, CustomFolderName = selectedFolderName, OriginalFolder = EmailType.Inbox, }); MailReceiver.DeleteEmail(EmailType.Inbox, selectedEmail.UniqueId); } else if (CurrentView == EmailView.SentEmails) { var selectedEmail = SentEmails[(string)row.Cells[0].Value]; var selectedFolderName = FolderList.FirstOrDefault(x => x.Value.FolderName == e.ClickedItem.Text).Value.FolderName; var selectedFolder = FolderList[selectedFolderName]; if (EmailCollection.ContainsKey(selectedEmail.Id)) { MessageBox.Show("This email already exists in collection.", "Moving failed"); return; } ++selectedFolder.ItemCount; var email = MailReceiver.GetEmail(EmailType.SentEmails, selectedEmail.UniqueId); ++selectedFolder.ItemCount; EmailCollection.TryAdd(selectedEmail.Id, new CollectionEmail { Id = selectedEmail.Id, From = selectedEmail.From, To = selectedEmail.To, Subject = selectedEmail.Subject, TextBody = email.TextBody, HtmlBody = email.HtmlBody, Date = selectedEmail.SentTime, CustomFolderName = selectedFolderName, OriginalFolder = EmailType.SentEmails, }); MailReceiver.DeleteEmail(EmailType.SentEmails, selectedEmail.UniqueId); } } } this.Invoke((Action)(() => toolStripButtonRefresh.PerformClick())); }); }