javascript - 在 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
解决方案
我解决了它,最终使用以下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 值部分的,这里是如何计算的。
推荐阅读
- javascript - 当图像位于 document.write 函数中时,如何设置图像样式?
- android - 如果前置摄像头挡住它,Android 会重塑或移动视图
- mysql - MySQL 中的并行写入。如何使用 Python mysql.connector 将流条目写入 MySQL 数据库中的 100 个不同表
- vba - 对象'_Global'的方法'Union'失败 - 它在我单步执行时有效,但在调用时无效
- mongodb - 无法在 nodejs+mongodb 的 cron 作业中执行 $merge 聚合
- python - 从 json 对象中获取数组到列表中
- excel - 如何将值从工作表复制到另一个工作表?
- python - Pandas 无法将对象转换为字符串或整数
- sql - FireDAC 无法处理超过 30 个字符的参数名称
- json - 将 FileManager 或 App 目标中的文件共享到 WidgetExtension 目标