2

I'm attempting to retrieve a list of emails by a particular sender on an exchange server using PHP EWS.

My code sample related specifically to the restriction (search) construction:

$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';

This type of restriction results in zero results.

I notice that when I search without restrictions, the result returned contains the sender information (but it is nested). eg:

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

How do I cater for the nested information in the restriction?

Other search expression examples: https://github.com/jamesiarmes/php-ews/wiki/Search-Expression:-Simple-Conditions

UnderDog
  • 305
  • 1
  • 4
  • 14
Paul
  • 804
  • 2
  • 13
  • 31

1 Answers1

4

Based on the MSDN docs, message:Sender has the following definition:

Property Value

Type: Microsoft.Exchange.WebServices.Data.EmailAddress

An e-mail address.

So instead of using the qualified name "Bob Smith" (Outlook may recognize it, but EWS has no clue), use the email address ('bsmith@foo.com').

Additionally, while the code above should work, it will likely throw an error since Constant never gets defined. Try this instead:

$request->Restriction->IsEqualTo->FieldURIOrConstant = new EWSType_FieldURIOrConstantType();
$request->Restriction->IsEqualTo->FieldURIOrConstant->Constant = new EWSType_ConstantValueType();
$request->Restriction->IsEqualTo->FieldURIOrConstant->Constant->Value = 'bsmith@foo.com';
Mr Griever
  • 4,014
  • 3
  • 23
  • 41