在 office 插件中将 ItemId (EwsId) 转换为 EntryId
Convert ItemId (EwsId) into EntryId in office addin
我有一个办公室插件 (js),我需要这个 EntryId
属性 来识别邮件(我在 VSTO 插件中使用这个 EntryId
,BC 需要它)
搜索后我尝试了 ConvertId operation 但我总是得到 This request is invaild
响应。
事实证明,使用makeEwsRequestAsync call时不支持ConvertId
。
所以我考虑过使用 GetItem
获取消息 headers 但没有返回 PR_ENTRYID header:
<?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
的方法是什么?
我解决了,最后使用 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 值部分的,这里是 how。
我有一个办公室插件 (js),我需要这个 EntryId
属性 来识别邮件(我在 VSTO 插件中使用这个 EntryId
,BC 需要它)
搜索后我尝试了 ConvertId operation 但我总是得到 This request is invaild
响应。
事实证明,使用makeEwsRequestAsync call时不支持ConvertId
。
所以我考虑过使用 GetItem
获取消息 headers 但没有返回 PR_ENTRYID header:
<?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
的方法是什么?
我解决了,最后使用 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 值部分的,这里是 how。