private static EmailStatus GetEmailStatusFromConversation(dynamic item, DateTime creationTime) { var emailStatus = EmailStatus.Unknown; var conversation = (List <ConversationTableData>)GpiOutlookWrapper.GetConversation(item); if (conversation != null) { var conversationList = conversation.Where(c => c.CreationTime > creationTime).OrderBy(c => c.CreationTime).ToList(); if (conversationList.Any()) { foreach (var parentMail in conversationList) { if (parentMail.MessageClass == "IPM.Note") { emailStatus = EmailStatus.Delivery; break; } if (parentMail.MessageClass == "REPORT.IPM.Note.DR") { emailStatus = EmailStatus.Delivery; break; } if (parentMail.MessageClass == "REPORT.IPM.Note.NDR") { emailStatus = EmailStatus.Nodelivery; break; } if (parentMail.MessageClass == "REPORT.IPM.Note.IPNRN") { emailStatus = EmailStatus.Delivery; break; } if (parentMail.MessageClass == "REPORT.IPM.Note.IPNNRN") { emailStatus = EmailStatus.Delivery; break; } } } } return(emailStatus); }
/// <summary> /// The find parent email button_ click. /// </summary> private void DisplayParentEmail() { try { if (this.NdrDataGridView.SelectedCells.Count == 0) { return; } var row = this.NdrDataGridView.SelectedCells[0].RowIndex; var id = (int)this.NdrDataGridView.Rows[row].Cells["IdColumn"].Value; var entryId = this.emailParsingDataList.First(c => c.Id == id).EntryId; var item = ThisAddIn.thisApplication.GetNamespace("MAPI").GetItemFromID(entryId, Type.Missing); var conversation = (List <ConversationTableData>)GpiOutlookWrapper.GetConversation(item); var paremtMailTableContent = conversation.Where(c => c.CreationTime < item.CreationTime).OrderByDescending(c => c.CreationTime).FirstOrDefault(); if (paremtMailTableContent == null) { MessageBox.Show(@"В письме не обнаружена ссылка на исходное письмо!", @"Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var parentMail = ThisAddIn.thisApplication.GetNamespace("MAPI").GetItemFromID(paremtMailTableContent.EntryId); var parentMailFolder = parentMail.Parent as Outlook.MAPIFolder; if (parentMailFolder != null) { // // Установили текущую папку ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder = parentMailFolder; ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder.Display(); Application.DoEvents(); Thread.Sleep(500); } if (ThisAddIn.thisApplication.ActiveExplorer().IsItemSelectableInView(parentMail)) { ThisAddIn.thisApplication.ActiveExplorer().ClearSelection(); ThisAddIn.thisApplication.ActiveExplorer().AddToSelection(parentMail); } else { if (MessageBox.Show( @"Невозможно отобразить письмо в текущем режиме. Разверните все свернутые группы используя опцию меню 'Развернуть все группы'. Отобразить письмо в новом окне?", @"Внимание!", MessageBoxButtons.YesNo) == DialogResult.Yes) { parentMail.Display(); } } Marshal.ReleaseComObject(parentMail); if (parentMailFolder != null) { Marshal.ReleaseComObject(parentMailFolder); } } catch (Exception ex) { this.InfoListBox.Items.Add("DisplayParentEmail " + ex.Message); } }