php-ews(jamesiarmes\PhpEws)获取对话项的唯一正文

sulc1iza  于 2023-02-18  发布在  PHP
关注(0)|答案(1)|浏览(135)

我正在使用php-ews来读取邮箱项目,以便将电子邮件作为支持票证处理。
由于一些是/可能是对话的一部分,我想使用UniqueBody属性来获取消息的最新/唯一部分。
请求示例:

$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemType = new ItemType();
$request->ItemType->UniqueBody = true;
$request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();
$item = new ItemIdType();
$item->Id = 'MessageId';
$request->ItemIds->ItemId[] = $item;
$response = $client->GetItem($request);

但是,这会导致UniqueBody响应为空。
我感觉UniqueBody的request值不正确,但是我找不到任何文档、示例或其他PHP解决方案。
有人知道怎么用吗?
先谢谢你,
巴兹

nfs0ujit

nfs0ujit1#

好吧,头脑清醒了,我在课堂上做了一些挖掘,找到了解决办法。
添加此参考:

use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfPathsToElementType;

然后添加ItemShape-〉AdditionalProperties

$request->ItemShape->AdditionalProperties = new NonEmptyArrayOfPathsToElementType();            
$request->ItemShape->AdditionalProperties->FieldURI = new PathToUnindexedFieldType();
$request->ItemShape->AdditionalProperties->FieldURI->FieldURI = UnindexedFieldURIType::ITEM_UNIQUE_BODY;

制作方法:

$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemShape->AdditionalProperties = new NonEmptyArrayOfPathsToElementType();            
$request->ItemShape->AdditionalProperties->FieldURI = new PathToUnindexedFieldType();
$request->ItemShape->AdditionalProperties->FieldURI->FieldURI = UnindexedFieldURIType::ITEM_UNIQUE_BODY;
$request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();
$item = new ItemIdType();
$item->Id = 'MessageId';
$request->ItemIds->ItemId[] = $item;
$response = $client->GetItem($request);

响应现在包含HTML格式的UniqueBody

$response->ResponseMessages->GetItemResponseMessage[0]->Items->Message[0]->UniqueBody

结果:

<html><body><div>
<div>
<div>
<div>
<div dir="ltr">
<div dir="ltr">Second message.</div>
<div dir="ltr">Kind regards</div>
<div dir="ltr">Me&nbsp;</div></div></div></div></div></div>
</body></html>

相关问题