Outlook 加载项 - 将数据存储和查找为隐藏的 StorageItem

Outlook add-in - Store and look up data as hidden StorageItem

我想在 Outlook 中创建一个 "local database",通过以隐藏形式存储一些辅助数据。

调查对象模型后,我发现了 StorageItem 对象,看起来很有希望。

我设法存储了一些行,并且还通过它们的独特主题查找它们,但是,我无法遍历 StorageItems。它在对象模型中说,没有可用于 StorageItem 对象的直接迭代器,但我可以从同一文件夹查询 table,它将包含 StorageItems。

table 最终将包含 5 件物品,其中 none 看起来很像我存储的物品。

这是我目前用于插入具有一些自定义属性的 StorageItems 的代码:

public static void InsertStorageItem(String UniqueID, String Name, String Address) 
{
    Outlook.NameSpace ns = null;
    Outlook.Folder tasksFolder = null;

    ns = outlookApp.Session;
    tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks) as Outlook.Folder;

    Outlook.StorageItem OIEDBTask = tasksFolder.GetStorage(UniqueID, Microsoft.Office.Interop.Outlook.OlStorageIdentifierType.olIdentifyBySubject);

    if (OIEDBTask.Size == 0)
    {
        OIEDBTask.UserProperties.Add("uniqueid", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
        OIEDBTask.UserProperties.Add("name", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
        OIEDBTask.UserProperties.Add("address", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
    }

    //assign values to custom properties
    OIEDBTask.UserProperties["uniqueid"].Value = UniqueID;
    OIEDBTask.UserProperties["name"].Value = Name;
    OIEDBTask.UserProperties["address"].Value = Address;

    OIEDBTask.Save();
}

下面是我想查询数据的方式:

public static dynamic QueryStorageItem() 
{
    List<dynamic> QueryResults = new List<dynamic>();
    Outlook.NameSpace ns = null;
    Outlook.Folder tasksFolder = null;
    Outlook.Table ResultTable = null;

    ns = outlookApp.Session;
    tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks) as Outlook.Folder;

    String Filter = "[LastModificationTime] > '5/1/2005'";  //tried removing the filter, but it didn't help. the comparison date is very old, so it should always give back some data
    ResultTable = tasksFolder.GetTable(Filter, Outlook.OlTableContents.olHiddenItems);

    while(!ResultTable.EndOfTable)  //tried a do-while structure also, didn't work.
    {
        Outlook.Row resultRow = ResultTable.GetNextRow();
        QueryResults.Add(resultRow.GetValues()); //the GetValues() function will give me an array with 5 objects in it, that are very different than my StorageItems
    }

    return QueryResults;
}

主要思想是,使用 StorageItems 的设置属性,使用 Outlook 提供的过滤:例如,尝试查找所有 StorageItems,其中 地址是某个值。 自然地,我会写一个类似的过滤器字符串:

String Filter = "[address] = 'certain value'";

这是行不通的,在阅读了一些内容之后,我得出的结论是,它可能行不通,因为它们是自定义 UserProperties,过滤应该只对内置属性起作用Outlook 项目,例如 LastModificationTime 等。

然而,即使没有过滤,我从GetTable函数中得到的数据集也没有用。 (所以我无法遍历行,它们不代表我插入的任何数据甚至结构)

有人可以指导更好的解决方案吗?

我的主要作用是,存储一些用户不可见的辅助数据。如果这不是解决方案,那么我将不得不创建任务而不是 StorageItems。

Storage(也称为关联)项目只是从 MAPI 的角度来看的常规消息(如果您单击 IMAPIFolder 按钮并转到“相关内容”选项卡),只是 OOM 决定以非常不同的方式公开它们。 Storage OOM 中的项目并非真正设计用于搜索 - 这个想法是您 create/open 通过主题或消息 class 您的私人项目并且不关心或触摸其他存储项目你什么都不知道。

我能想到的一个技巧是使用地址本身构造消息 class(例如“IPM.Note.user@domain.demo”)并指定该消息 class打开存储项目。

如果您确实要搜索关联的 table 内容,扩展 MAPI(C++ 或 Delphi)或 Redemption (I am also its author) are probably your only choices. Redemption exposes associated items in the same way it exposes the regular items, i.e. RDOFolder.HiddentItems vs RDOFolder.Items. You can then search using RDOItems.Find/FindNext/Restrict/MAPITable.ExecSQL.