首页 > 解决方案 > 在 office addin 中将 ItemId (EwsId) 转换为 EntryId

问题描述

我有一个办公室插件(js),我需要这个EntryId属性来识别邮件(我EntryId在 VSTO 插件中使用它,BC 需要它)

搜索后我尝试了ConvertId 操作,但我总是得到This request is invaild响应。

事实证明,使用makeEwsRequestAsync 调用ConvertId时不支持。

因此,我考虑使用获取消息标GetItem头但未返回 PR_ENTRYID 标头:

        <?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="https://www.w3.org/2001/XMLSchema"
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <soap:Header>
                <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
            </soap:Header>
            <soap:Body>
                <GetItemInfo xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
                    <ItemShape>
                        <t:BaseShape>AllProperties</t:BaseShape>
                    </ItemShape>
                    <ItemIds><t:ItemId Id="${itemId}"/></ItemIds>
                </GetItemInfo>
            </soap:Body>
        </soap:Envelope>

tl;dr:那么在 Office Addin中转换EwsId为的方法是什么?EntryId

标签: javascriptapiexchangewebservicesoffice-addins

解决方案


我解决了它,最终使用以下GetItem操作ExtendedFieldURI

    import xpath from 'xpath';
    import { DOMParser } from 'xmldom';
    import { Buffer } from 'buffer';

    private getEntryIdFromItemId(itemId: string): Promise<string>
    {
        const request = `<?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="https://www.w3.org/2001/XMLSchema"
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <soap:Header>
                <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
            </soap:Header>
            <soap:Body>
                <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
                    <ItemShape>
                        <t:BaseShape>IdOnly</t:BaseShape>
                        <t:AdditionalProperties>
                          <t:ExtendedFieldURI PropertyTag="0x0FFF" PropertyType="Binary" />
                        </t:AdditionalProperties>
                    </ItemShape>
                    <ItemIds><t:ItemId Id="${itemId}"/></ItemIds>
                </GetItem>
            </soap:Body>
        </soap:Envelope>`;
        return new Promise((resolve, reject) => {
            Office.context.mailbox.makeEwsRequestAsync(request, async (asyncResult) => {
                if(asyncResult.status == Office.AsyncResultStatus.Failed)
                {
                    reject();
                    return;
                }

                const doc = new DOMParser().parseFromString(asyncResult.value);
                const entryId = xpath.select("//*[local-name()='Value']", doc)[0] as Node;
                const entryIdHex = new Buffer(entryId.textContent!, "base64").toString("hex").toUpperCase();
                resolve(entryIdHex);
            });
        });
    }

还必须将返回的 base64 值转换为十六进制值,因为那是 Outlook 客户端使用的。

如果您想知道我是如何计算 0x0FFF 值部分的,这里是如何计算的。


推荐阅读