public static void AddCategoryToMailItem(Outlook.MailItem mi, String tag, Outlook.Application application) { CategoryUtils.EnsureCategoryExists(tag, application); String categoriesString = mi.Categories; if (null == categoriesString || "".Equals(categoriesString)) { mi.Categories = tag;// adding first category mi.Save(); } else { // some categories already assigned String[] cats = categoriesString.Split(','); bool categoryAlreadyAssociated = false; foreach (String cat in cats) { if (cat.Equals(tag)) { categoryAlreadyAssociated = true; } } if (categoryAlreadyAssociated) { // don't change anything } else { mi.Categories = categoriesString + "," + tag; mi.Save(); } } }
public static void RemoveTagFromEmail(String tag, Outlook.MailItem mi, Outlook.Application application, TagBarHelper explorerTagBarHelper) { Backend.UntagEmail(mi.EntryID, tag); CategoryUtils.RemoveCategoryFromMailITem(tag, mi); /* The email might be opened in more than one place - the inspector and any number of explorers, so find all the ones * are showing the mailItem and remove the tag there. */ RemoveTagFromExplorerEmailIfMatch(mi.EntryID, tag, application, explorerTagBarHelper); foreach (Outlook.Inspector inspector in application.Inspectors) { RemoveTagFromInspectorEmailIfMatch(inspector, mi.EntryID, tag); } }
public static void AddTagToEmail(String tag, Outlook.MailItem mi, Outlook.Application application, TagBarHelper explorerTagBarHelper) { Backend.TagEmail(mi.EntryID, tag); Backend.TagPerson(Utils.NormalizeName(mi.SenderName), tag); CategoryUtils.AddCategoryToMailItem(mi, tag, application); /* The email might be opened in more than one place - the inspector and any number of explorers, so find all the ones * are showing the mailItem and add the tag there. */ AddTagToExplorerEmailIfMatch(mi.EntryID, tag, application, explorerTagBarHelper); foreach (Outlook.Inspector inspector in application.Inspectors) { AddTagToInspectorEmailIfMatch(inspector, mi.EntryID, tag); } }
public static void CreateNewTag(String tag, Outlook.Application application, TagBar explorerTagBar) { CategoryUtils.AddCategory(tag, application); Backend.AddTag(tag); List <String> latestTags = Utils.GetLatestTagList(); /* * There might be more than one TagBar in play - one in the explorer and any number of inspectors. * Find them all and update their tagList */ explorerTagBar.LoadTagList(latestTags); Dictionary <Outlook.Inspector, InspectorWrapper> .KeyCollection keys = InspectorWrapper.inspectorWrappersValue.Keys; foreach (Outlook.Inspector inspector in keys) { InspectorWrapper iWrapper = InspectorWrapper.inspectorWrappersValue[inspector]; iWrapper.getTagBar().LoadTagList(latestTags); } }