Exemple #1
0
        private static bool IsMailItemHasFlaggedPreviousMail(Outlook.MailItem mailItem)
        {
            bool answer = false;

            if (mailItem is Outlook.MailItem)
            {
                Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
                Debug.Assert(folder != null);
                Outlook.Store store = folder.Store;

                if ((store != null) && (store.IsConversationEnabled == true))
                {
                    Outlook.Conversation conv = mailItem.GetConversation();
                    if (conv != null)
                    {
                        Outlook.SimpleItems simpleItems = conv.GetRootItems();
                        foreach (object item in simpleItems)
                        {
                            if (item is Outlook.MailItem)
                            {
                                bool result = IsMailItemOrAnyItsChildrenFlagged(item as Outlook.MailItem, conv);
                                if (result == true)
                                {
                                    answer = true;
                                }
                            }
                        }
                    }
                }
            }

            return(answer);
        }
Exemple #2
0
        private string getConversationCategories(Outlook.MailItem mail)
        {
            string convCats = "";

            Outlook.Conversation conv = mail.GetConversation();
            if (conv == null)
            {
                return("");
            }

            Outlook.SimpleItems simpleItems = conv.GetRootItems();
            foreach (object item in simpleItems)
            {
                if (item is Outlook.MailItem)
                {
                    Outlook.MailItem smail = item as Outlook.MailItem;
                    if (smail.Categories == null)
                    {
                        continue;
                    }
                    string[] scats = smail.Categories.Split(ThisAddIn.CATEGORY_SEPERATOR[0]);
                    foreach (string scat in scats)
                    {
                        string tscat = scat.Trim();
                        if (!tscat.StartsWith("!") && !tscat.StartsWith("@") && !tscat.StartsWith("#"))
                        {
                            convCats += ThisAddIn.CATEGORY_SEPERATOR + tscat;
                        }
                    }
                }
            }

            return(convCats);
        }
Exemple #3
0
        public void FindLastInConversation(Outlook.MailItem mailItem)
        {
            if (mailItem is Outlook.MailItem)
            {
                // Determine the store of the mail item.
                Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
                Outlook.Store  store  = folder.Store;
                if (store.IsConversationEnabled)
                {
                    // Obtain a Conversation object.
                    Outlook.Conversation conv = mailItem.GetConversation();

                    // Check for null Conversation.
                    if (conv != null)
                    {
                        // Obtain Table that contains rows
                        Outlook.Table table = conv.GetTable();
                        int           count = table.GetRowCount();
                        Logger.Log("Conversation Items Count: " + count.ToString());

                        table.MoveToStart();

                        if (!table.EndOfTable)
                        {
                            // lastRow conatins the last item from the conversation
                            Outlook.Row lastRow = table.GetNextRow();

                            //Logger.Log(lastRow["Subject"] + " Modified: " + lastRow["LastModificationTime"]);
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void updateEntireConversation(Outlook.MailItem mail)
        {
            string persTags = getPersistantCategories(mail.Categories);

            Outlook.Conversation conv = mail.GetConversation();
            if (conv == null)
            {
                return;
            }

            Outlook.SimpleItems simpleItems = conv.GetRootItems();
            foreach (object item in simpleItems)
            {
                if (item is Outlook.MailItem smail)
                {
                    string cats = persTags;
                    cats            += getSenderCategory(smail.SenderName);
                    cats            += getAttachmentCategories(mail.Attachments);
                    smail.Categories = getUniqueTags(cats);
                    smail.Save();
                }

                Outlook.SimpleItems OlChildren = conv.GetChildren(item);
                foreach (object rci in OlChildren)
                {
                    if (rci is Outlook.MailItem icr)
                    {
                        string cats = persTags;
                        cats          += getSenderCategory(icr.SenderName);
                        cats          += getAttachmentCategories(mail.Attachments);
                        icr.Categories = getUniqueTags(cats);
                        icr.Save();
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Function searches for email duplicates from a specific email
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private IEnumerable <Outlook.MailItem> search(Outlook.MailItem filter)
        {
            if (filter.Parent == deletedMailsFolder)
            {
                yield break;
            }

            Dictionary <string, Outlook.MailItem> mailsFound = new Dictionary <string, Outlook.MailItem>()
            {
                { filter.EntryID, filter }
            };

            // Obtain a Conversation object.
            Outlook.Conversation conv = filter.GetConversation();

            // Obtain Table that contains rows
            // for each item in Conversation.
            Outlook.Table table = conv.GetTable();

            //break if there just one
            if (table.GetRowCount() == 1)
            {
                yield break;
            }

            Debug.WriteLine("Conversation Items Count: " + table.GetRowCount().ToString());

            // Obtain root items and enumerate Conversation.
            Outlook.SimpleItems simpleItems = conv.GetRootItems();
            foreach (object item in simpleItems)
            {
                // enumerate only MailItem type.
                if (item is Outlook.MailItem)
                {
                    Outlook.MailItem m        = item as Outlook.MailItem;
                    Outlook.Folder   inFolder = m.Parent as Outlook.Folder;
                    string           msg      = m.Subject + " in folder " + inFolder.Name;

                    Debug.WriteLine(msg);

                    if (!mailsFound.ContainsKey(m.EntryID) && MailItemEquals(m, filter) && inFolder != deletedMailsFolder)
                    {
                        mailsFound.Add(m.EntryID, m);
                    }
                }
                // Call EnumerateConversation
                // to access child nodes of root items.
                EnumerateConversation(item, conv, filter, ref mailsFound);
            }

            if (mailsFound.Count > 1)
            {
                //delete duplicates //O(((n-1)n)/2)
                var mf = mailsFound.ToArray();
                for (int i = 0; i < mf.Length - 1; i++)
                {
                    for (int j = i + 1; j < mf.Length; j++)
                    {
                        if (app.Session.CompareEntryIDs(mf[i].Key, mf[j].Key))
                        {
                            mailsFound.Remove(mf[j].Key);
                        }
                    }
                }

                List <Outlook.MailItem> mGelesen      = new List <Outlook.MailItem>(); //List for readed emails
                List <Outlook.MailItem> mNichtGelesen = new List <Outlook.MailItem>(); //List for unreaded
                foreach (Outlook.MailItem m in mailsFound.Values)
                {
                    if (m.UnRead)
                    {
                        mNichtGelesen.Add(m);
                    }
                    else
                    {
                        mGelesen.Add(m);
                    }
                }
                if (mGelesen.Count > 0) // if there are readed emails, move the new unreaded to trash
                {
                    foreach (Outlook.MailItem m in mNichtGelesen)
                    {
                        m.Move(deletedMailsFolder); //move to deleted folder
                        yield return(m);
                    }
                }
                else
                {                                                 //no email were already readed
                    bool first = false;
                    foreach (Outlook.MailItem m in mNichtGelesen) //delete just n-1
                    {
                        if (first)
                        {
                            m.Move(deletedMailsFolder); //move to deleted folder
                        }
                        yield return(m);

                        first = true;
                    }
                }
                //clear readed mails too
                bool first2 = false;
                foreach (Outlook.MailItem m in mGelesen) //delete just n-1
                {
                    if (first2)
                    {
                        m.Move(deletedMailsFolder); //move to deleted folder
                    }
                    yield return(m);

                    first2 = true;
                }
            }
        }