我正在尝试检索用户创建的所有自定义文件夹的列表,以便我可以进行全局高级搜索。我只想要其中包含 MailItems 对象的自定义文件夹,因此我想从列表中排除几个文件夹(例如 RSS 提要、快速步骤设置、建议的联系人),这些文件夹在 Outlook 商店中是标准的。
首先,这个问题与下面提出的问题非常相似,但所选答案并未针对自定义文件夹——仅针对所有文件夹。
有人知道如何检索仅包含 mailitem 对象的自定义文件夹列表吗? 我创建了一个相当大的 if 块来过滤掉不需要的文件夹,但我需要一种更通用的方法,因为这将部署在用户计算机上,并且谁知道人们如何处理他们的 Outlook 文件夹?
if (
// remove specific search folders from cope
subfolder.Name == "Quick Step Settings" || subfolder.Name == "News Feed" || subfolder.Name == "Conversation History" || subfolder.Name == "Conversation Action Settings" ||
// remove unwanted default folders from returning expiring items
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderConflicts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJournal).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderRssFeeds).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSuggestedContacts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSyncIssues).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderServerFailures).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderLocalFailures).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).FolderPath ||
// eliminate certain custom folders with unwanted default types
subfolder.DefaultItemType == Outlook.OlItemType.olContactItem || subfolder.DefaultItemType == Outlook.OlItemType.olJournalItem
|| subfolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem || subfolder.DefaultItemType == Outlook.OlItemType.olDistributionListItem
|| subfolder.DefaultItemType == Outlook.OlItemType.olDistributionListItem
)
{
addFolder = false;
}