2013-04-15 17 views
2

我試圖使用PHP EWS檢索交換服務器上特定發件人的電子郵件列表。具體到限制(搜索)相關發件人的限制(搜索)

我的代碼示例結構:

$request->Restriction = new EWSType_RestrictionType(); 
$request->Restriction->IsEqualTo = new EWSType_IsEqualToType(); 

$request->Restriction->IsEqualTo->FieldURI = new EWSType_PathToUnindexedFieldType(); 
$request->Restriction->IsEqualTo->FieldURI->FieldURI = 'message:Sender'; 

$request->Restriction->IsEqualTo->FieldURIOrConstant = new EWSType_FieldURIOrConstantType(); 
$request->Restriction->IsEqualTo->FieldURIOrConstant->Constant->Value = 'Bob Smith'; 

在零個結果這種類型的限制的結果。

我注意到,當我搜索沒有限制時,返回的結果包含發件人信息(但它是嵌套的)。例如:

[Sender] => stdClass Object 
    (
    [Mailbox] => stdClass Object 
     (
     [Name] => Bob Smith 
    ) 
) 

如何滿足限制中的嵌套信息?

其它搜索表達式的例子:https://github.com/jamesiarmes/php-ews/wiki/Search-Expression:-Simple-Conditions

回答

3

基於該MSDN文檔,消息:發送具有以下定義:

屬性值

類型:Microsoft.Exchange.WebServices.Data。電子郵件地址

電子郵件地址。

因此,請使用電子郵件地址('[email protected]'),而不是使用限定名稱「Bob Smith」(Outlook可能會識別它,但EWS不知道)。

此外,雖然上面的代碼應該可以工作,但它可能會拋出一個錯誤,因爲常量永遠不會被定義。試試這個:

$request->Restriction->IsEqualTo->FieldURIOrConstant = new EWSType_FieldURIOrConstantType(); 
$request->Restriction->IsEqualTo->FieldURIOrConstant->Constant = new EWSType_ConstantValueType(); 
$request->Restriction->IsEqualTo->FieldURIOrConstant->Constant->Value = '[email protected]'; 
+0

哇!感謝堆馬特!這真的很好。真的很感謝! – Paul