exchange-server - 将 EWS 对话*与 Outlook 插件对话*匹配

标签 exchange-server outlook-addin exchangewebservices

几年前我为 Outlook 编写了一个加载项,它根据条目的 ConversationIndex 将条目添加到数据库中。/ConversationId特性。这非常有效,并且在与消息交互的所有客户端中保持统一(例如,“Bob”可以看到“Mary”已经处理了此消息,因为带有 ConversationIndex 的条目已经存在)。

我现在正在尝试将这部分移动到服务(并通过 EWS API 连接),但我没有好运将这些属性与来自 Outlook 的值进行匹配。例如:

Outlook 加载项将为我指定的特定电子邮件提供以下值:

ConversationID:     6B6369F5023EA646AA7BC161274BDAE8
ConversationIndex:  0101CF3C7EEC6B6369F5023EA646AA7BC161274BDAE8

但是,从 EWS API 我得到以下信息:
ConversationID:     AAQkADFhZThkNmJmLTlkODItNDQyZS1hM2YxLTQ2NWNkMTllYjhjOQAQAGtjafUCPqZGqnvBYSdL2ug=
ConversationIndex:  new byte[]{1,1,207,60,126,236,107,99,105,245,2,62,166,70,170,123,193,97,39,75,218,232}

我将第一个识别为 Base64 编码的字符串,但是我解码的内容看起来不像我识别(或可以破译)的任何东西。有没有人熟悉这一点,或者谁能帮助使这两个值保持一致?我只能想象这些属性来自交换服务器是某种方式,但客户端可能会执行一些清理,而 EWS API 只是给我原始值(减去 Base64,因为我假设给定 XML 介质的传输目的)。

如果有人熟悉这一点或在我之前做过这件事,我将不胜感激。

边注:

可能有更好的方法来识别电子邮件,但现在我坚持尝试保持这两个同义词。修改 Outlook 加载项并不是一个真正的选项,一旦我将 1:1 翻译迁移到服务器(并删除加载项),我就可以灵活地改变它的工作方式。但是现在我需要它们并排运行。我需要能够从 web 服务器和反之亦然看到在 Outlook 中进行的进程。

最佳答案

刚刚发现(我认为)。

分解

通过更多的谷歌搜索和更多的努力,我相信我能够使用以下方法使它们 1:1 对齐:

session ID

这显然是由几个属性组成的组合值。幸运的是,我找到了 Woodman 发布的重新实现 original algorithm 的方法。 Outlook 使用 here .通过一些小的修改(使用 EWS 而不是 Outlook),我能够让它工作。

session 索引

结果证明这只是使用 BitConverter 的问题。 (并删除连字符)。十分简单。

最后结果:

public static class EwsEmailMessageExtensions
{
    private const int c_ulConvIndexIDOffset = 6;
    private const int c_ulConvIndexIDLength = 16;
    private static ExtendedPropertyDefinition PidTagConversationIndexTracking = new ExtendedPropertyDefinition(0x3016, MapiPropertyType.Boolean);

    // HUGE props to Woodman
    // https://stackoverflow.com/a/21625224/298053
    public static string GetOutlookConversationId(this EmailMessage emailMessage)
    {
        Boolean convTracking;
        if (!emailMessage.TryGetProperty(PidTagConversationIndexTracking, out convTracking))
        {
            convTracking = true;
        }

        var convIndex = emailMessage.ConversationIndex;
        byte[] idBytes;
        if (convTracking && convIndex != null && convIndex.Length > 0)
        {
            // get Id from Conversation index
            idBytes = new byte[c_ulConvIndexIDLength];
            Array.Copy(convIndex, c_ulConvIndexIDOffset, idBytes, 0, c_ulConvIndexIDLength);
        }
        else
        {
            // get Id from Conversation topic
            var topic = emailMessage.ConversationTopic;
            if (string.IsNullOrEmpty(topic))
            {
                return string.Empty;
            }

            if (topic.Length >= 265)
            {
                topic = topic.Substring(0, 256);
            }
            topic = topic.ToUpper();

            using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
            {
                idBytes = md5.ComputeHash(Encoding.Unicode.GetBytes(topic));
            }
        }

        return BitConverter.ToString(idBytes).Replace("-", string.Empty);
    }

    public static String GetOutlookConversationIndex(this EmailMessage emailMessage)
    {
        var convIndex = emailMessage.ConversationIndex;
        return BitConverter.ToString(convIndex).Replace("-", String.Empty);
    }
}

用法:

// Prep
ExchangeService service = new ExchangeService(...);
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
Item item = /* inbox.FindItems(...).First() */

// Implmentation
EmailMessage emailMessage = item as EmailMessage;
if (emailMessage != null)
{
   String conversationId = emailMessage.GetOutlookConversationId();
   String conversationIndex = emailMessage.GetOutlookConversationIndex();
   /* ... */
}

关于exchange-server - 将 EWS 对话*与 Outlook 插件对话*匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22537817/

相关文章:

powershell - 搜索邮箱SearchQuery不起作用

c# - 在 Outlook 2007 中获取当前用户的电子邮件地址

c# - 如何可靠地知道什么对象是当前(聚焦)outlook 窗口。即 explorer 类型或 Inspector 类型

C# VSTO 加载项 - 将纯文本电子邮件转换为 HTML

c# - Exchange Web 服务 : More Complex SearchFilters

c# - Exchange Web 服务托管 API : Accessing other users items

C# fileattachment 内容到字符串

asp.net - 多个用户的 EWS 通知中心

office365 - 使用 Office 365 API 的身份验证问题

ssl - Nginx 作为交换代理