【问题标题】:Match EWS Conversation* to Outlook Add-in Conversation*将 EWS 对话* 与 Outlook 加载项对话* 匹配
【发布时间】:2014-04-27 14:01:15
【问题描述】:

几年前我为 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 只是给我原始值(考虑到 XML 介质,我认为传输目的的 Base64 较少)。

如果有人对此熟悉或之前做过,我将不胜感激。

旁注:

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

【问题讨论】:

    标签: exchange-server outlook-addin exchangewebservices


    【解决方案1】:

    刚刚发现(我认为)。

    故障

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

    对话 ID

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

    对话索引

    结果证明这只是使用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();
       /* ... */
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2012-03-12
      相关资源
      最近更新 更多