public static void oznaczCalaKonwersacjeKategoria(MailItem email, string category) { Conversation conv = email.GetConversation(); SimpleItems simpleItems = conv.GetRootItems(); foreach (object item in simpleItems) { if (item is MailItem) { MailItem mail = item as MailItem; string existingCategories = mail.Categories; if (string.IsNullOrEmpty(existingCategories)) { mail.Categories = category; } else { mail.Categories = existingCategories + ", " + category; } mail.Categories = RemoveUnnecessaryCategories(mail.Categories, category); mail.Save(); } getNextItemFromConversation(item, conv, category); } }
public static void check(MailItem newEmail) { try { Conversation conv = newEmail.GetConversation(); SimpleItems simpleItems = conv.GetRootItems(); //bool isTemplate = false; foreach (object item in simpleItems) { try { if (item is MailItem) { Main.counter++; MailItem mail = item as MailItem; bool checkTemplate = checkTemplateConversation(mail); //DO TESTOWANIA /*Folder inFolder = mail.Parent as Folder; * string msg = mail.Subject + " in folder " + inFolder.Name + " Sender: " + mail.SenderName + " Date: " + mail.ReceivedTime;*/ /*MessageBox.Show(counter + ". " + msg + * "\nTemplate was sent: " + isTemplate + * "\nTemplate was filled: " + checkTemplate);*/ /*if (checkIfTemplateWasSend) * isTemplate = true;*/ if (checkTemplate) { checkIfFitToTemplate = checkTemplate; } } EnumerateConversation(item, conv); } catch (Exception e) { MessageBox.Show(e.Message); } } } catch (Exception ex) { MessageBox.Show("Exception in check: \n" + ex.Message); } }
private void GetAttachmentsFromConversation(MailItem mailItem) { if (mailItem == null) { return; } if (mailItem.Attachments.CountNonEmbeddedAttachments() > 0) { return; } System.Collections.Generic.Stack <MailItem> st = new System.Collections.Generic.Stack <MailItem>(); // Determine the store of the mail item. Outlook.Folder folder = mailItem.Parent as Outlook.Folder; Outlook.Store store = folder.Store; if (store.IsConversationEnabled == true) { // Obtain a Conversation object. Outlook.Conversation conv = mailItem.GetConversation(); // Check for null Conversation. if (conv != null) { // Obtain Table that contains rows // for each item in the conversation. Outlook.Table table = conv.GetTable(); _logger.Debug("Conversation Items Count: " + table.GetRowCount().ToString()); _logger.Debug("Conversation Items from Root:"); // Obtain root items and enumerate the conversation. Outlook.SimpleItems simpleItems = conv.GetRootItems(); foreach (object item in simpleItems) { // In this example, enumerate only MailItem type. // Other types such as PostItem or MeetingItem // can appear in the conversation. if (item is Outlook.MailItem) { Outlook.MailItem mail = item as Outlook.MailItem; Outlook.Folder inFolder = mail.Parent as Outlook.Folder; string msg = mail.Subject + " in folder [" + inFolder.Name + "] EntryId [" + (mail.EntryID.ToString() ?? "NONE") + "]"; _logger.Debug(msg); _logger.Debug(mail.Sender); _logger.Debug(mail.ReceivedByEntryID); if (mail.EntryID != null && (mail.Sender != null || mail.ReceivedByEntryID != null)) { st.Push(mail); } } // Call EnumerateConversation // to access child nodes of root items. EnumerateConversation(st, item, conv); } } } while (st.Count > 0) { MailItem it = st.Pop(); if (it.Attachments.CountNonEmbeddedAttachments() > 0) { //_logger.Debug(it.Attachments.CountNonEmbeddedAttachments()); try { if (mailItem.IsMailItemSignedOrEncrypted()) { if (MessageBox.Show(null, "Es handelt sich um eine signierte Nachricht. Soll diese für die Anhänge ohne Zertifikat dupliziert werden?", "Nachricht duplizieren?", MessageBoxButtons.YesNo) == DialogResult.Yes) { mailItem.Close(OlInspectorClose.olDiscard); mailItem = mailItem.Copy(); mailItem.Unsign(); mailItem.Save(); mailItem.Close(OlInspectorClose.olDiscard); mailItem.Save(); } else { st.Clear(); break; } } mailItem.CopyAttachmentsFrom(it); mailItem.Save(); } catch (System.Exception ex) { //mailItem.Close(OlInspectorClose.olDiscard); MessageBox.Show(ex.Message); } st.Clear(); } } st.Clear(); Marshal.ReleaseComObject(mailItem); }
public List <bool> selectCorrectEmailType(MailItem newEmail) { try { bool correctCategory = false; List <bool> categoryList = new List <bool>(); categoryList.Add(false); categoryList.Add(false); categoryList.Add(false); int i = 0; Conversation conv = newEmail.GetConversation(); Debug.WriteLine("Conversation Items from Root:"); SimpleItems simpleItems = conv.GetRootItems(); foreach (object item in simpleItems) { try { if (item is MailItem) { MailItem mail = item as MailItem; Folder inFolder = mail.Parent as Folder; string msg = mail.Subject + " in folder " + inFolder.Name + " Sender: " + mail.SenderName + " Date: " + mail.ReceivedTime; if (mail.ReceivedTime > getInflowDate().AddDays(-7) && mail.SenderName.Equals(adminMail)) { msg += " ++correctCategory++"; correctCategory = true; } if (mail.ReceivedTime > getInflowDate()) { msg += " TYP: INFLOW"; categoryList[0] = true; } if (mail.SenderName.Equals(adminMail) && mail.ReceivedTime > getInflowDate()) { msg += " TYP: IN HANDS"; categoryList[1] = true; } Debug.WriteLine(msg); OurDebug.AppendInfo(msg); i++; } EnumerateConversation(item, conv, i, categoryList, ref correctCategory); } catch (Exception e) { Debug.WriteLine("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Exception in read children and set categories"); OurDebug.AppendInfo("Exception in read children and set categories" + e.StackTrace); } } if (categoryList[0] || categoryList[1]) { Debug.WriteLine("INFLOW: " + categoryList[0] + " INHANDS: " + categoryList[1] + " OUTFLOW: " + categoryList[2] + " correctCategory: " + correctCategory); Debug.WriteLine("----------------------------------------------"); OurDebug.AppendInfo("INFLOW: " + categoryList[0] + " INHANDS: " + categoryList[1] + " OUTFLOW: " + categoryList[2] + " correctCategory: " + correctCategory); OurDebug.AppendInfo("----------------------------------------------"); return(categoryList); } if ((!categoryList[0] && !categoryList[1]) && correctCategory) { categoryList[2] = true; } Debug.WriteLine("INFLOW: " + categoryList[0] + " INHANDS: " + categoryList[1] + " OUTFLOW: " + categoryList[2] + " correctCategory: " + correctCategory); Debug.WriteLine("----------------------------------------------"); OurDebug.AppendInfo("INFLOW: " + categoryList[0] + " INHANDS: " + categoryList[1] + " OUTFLOW: " + categoryList[2] + " correctCategory: " + correctCategory); OurDebug.AppendInfo("----------------------------------------------"); return(categoryList); } catch (Exception e) { OurDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Blad w liczbie konwersacji; funkcja getConversationAmount()\n", e.Message, "\n", e.StackTrace); Debug.WriteLine("Blad w liczbie konwersacji; funkcja getConversationAmount()"); return(null); } }