我正在从Exchange服务器使用EWS获取未读邮件。下面是输出。
stdClass Object ( [ResponseMessages] => stdClass Object
( [FindItemResponseMessage] => stdClass Object
( [ResponseCode] => NoError
[ResponseClass] => Success
[RootFolder] => stdClass Object
( [Items] => stdClass Object
( [Message] => stdClass Object
( [ItemId] => stdClass Object
( [Id] => AAMkADllYWVjYjE3LWMzNWItNDczYy05YzllLWEzMzM2YWUzNDY3NQBGAAAAAAA3RNrc1+NeRYdPKpmLrF8OBwDmmObTCfhpSqYuvnMiDlrXAAAAFjg7AADmmObTCfhpSqYuvnMiDlrXAAD0o9sFAAA=
[ChangeKey] => CQAAABYAAADmmObTCfhpSqYuvnMiDlrXAAD0o+gX
)
[Subject] => CR-1167-Approved
[Sensitivity] => Normal
[Size] => 2992
[DateTimeSent] => 2016-09-22T10:55:12Z
[DateTimeCreated] => 2016-09-22T10:55:13Z
[HasAttachments] => [IsAssociated] => [From] => stdClass Object
( [Mailbox] => stdClass Object
( [Name] => Basudev Kumar Sadhu (Assistant Manager, Technology)
[MailboxType] => OneOff
)
)
[IsRead] =>
) )
[IndexedPagingOffset] => 1
[IncludesLastItemInRange] => 1
[TotalItemsInView] => 1
) ) ) )
现在我想从这个输出中解析一个值。我想从此输出中捕获主题和名称。
以下是我用来阅读邮件的原始代码。
<?php
require_once ('../mail3/php-ews-master/ExchangeWebServices.php');
require_once ('../mail3/php-ews-master/EWS_Exception.php');
require_once ('../mail3/php-ews-master/EWSType.php');
require_once ('../mail3/php-ews-master/NTLMSoapClient.php');
function __autoload($class_name)
{
// Start from the base path and determine the location from the class name,
$base_path = '../mail3/php-ews-master';
$include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php';
return (file_exists($include_file) ? require_once $include_file : false);
}
//$message_id = ''; // Id of the email message
$ews = new ExchangeWebServices("webmail.bkash.com", "cr.tool", "BanglaDesh!@34",ExchangeWebServices::VERSION_2010);
$request = new EWSType_FindItemType();
$itemProperties = new EWSType_ItemResponseShapeType();
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
$itemProperties->BodyType = EWSType_BodyTypeResponseType::TEXT;
$request->ItemShape = $itemProperties;
$fieldType = new EWSType_PathToUnindexedFieldType();
$fieldType->FieldURI = 'message:IsRead';
$constant = new EWSType_FieldURIOrConstantType();
$constant->Constant = new EWSType_ConstantValueType();
$constant->Constant->Value = "0";
$IsEqTo = new EWSType_IsEqualToType();
$IsEqTo->FieldURIOrConstant = $constant;
$IsEqTo->Path = $fieldType;
$request->Restriction = new EWSType_RestrictionType();
$request->Restriction->IsEqualTo = new EWSType_IsEqualToType();
$request->Restriction->IsEqualTo->FieldURI = $fieldType;
$request->Restriction->IsEqualTo->FieldURIOrConstant = $constant;
$request->IndexedPageItemView = new EWSType_IndexedPageViewType();
$request->IndexedPageItemView->BasePoint = 'Beginning';
$request->IndexedPageItemView->Offset = 0;
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$result = new EWSType_FindItemResponseMessageType();
$result = $ews->FindItem($request);
if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success'){
$count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
if($count > 0) {
echo $count . " email(s)";
print_r($result);
} else {
echo 'No email(s)';
}
}
?>
答案 0 :(得分:1)
我建议使用该库garethp/php-ews
的版本,其中包含许多examples
,包括如何get a list of mail items。
使用它,您的代码看起来大致像
Selenium WebDriver