jamesiarmes / php-ews

PHP Exchange Web Services
http://jamesarmes.com/php-ews/
MIT License
567 stars 302 forks source link

Accessing a well known subfolder of the root folder #573

Closed lstrojil closed 4 years ago

lstrojil commented 4 years ago

Hi,

I would like to get a list of emails from a specific subfolder of a mailbox.

Currently, I am using the following code to open the Inbox:

    // Search in the user's inbox.
    $folder_id = new DistinguishedFolderIdType();
    $folder_id->Id = DistinguishedFolderIdNameType::INBOX;
    $folder_id->Mailbox = new StdClass;
    $folder_id->Mailbox->EmailAddress = 'xxx@yyy.zzz';

    $request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;

    $response = `$client->FindItem($request);

I know that I can do a DEEP traversal and find emails in subfolders, but I cannot do that. I can search for the ID of the folder by using the folder search calls, but I do not know how I use that generated object to pass it to the request.

jamesiarmes\PhpEws\Type\FolderType Object
--
  | (
  | [PermissionSet] =>
  | [UnreadCount] => 5
  | [ChildFolderCount] => 0
  | [DisplayName] => Iamalive
  | [EffectiveRights] => jamesiarmes\PhpEws\Type\EffectiveRightsType Object
  | (
  | [CreateAssociated] => 1
  | [CreateContents] => 1
  | [CreateHierarchy] => 1
  | [Delete] => 1
  | [Modify] => 1
  | [Read] => 1
  | [ViewPrivateItems] => 1
  | )
  |  
  | [ExtendedProperty] =>
  | [FolderClass] => IPF.Note
  | [FolderId] => jamesiarmes\PhpEws\Type\FolderIdType Object
  | (
  | [ChangeKey] => AQAAABYAAAD/xlJSPOSDSZLXIt9rew8vAABdKqMH
  | [Id] => AAMkADEyM2M2NzU0LTVjMDMtNDQzYS05NmE1LWIwNTVlNjhkOTkxYgAuAAAAAABhtW07FlyqQYq4iSYmMa0AAQD/xlJSPOSDSZLXIt9rew8vAAA0y9npAAA=
  | )
  |  
  | [ManagedFolderInformation] =>
  | [ParentFolderId] => jamesiarmes\PhpEws\Type\FolderIdType Object
  | (
  | [ChangeKey] => AQAAAA==
  | [Id] => AAMkADEyM2M2NzU0LTVjMDMtNDQzYS05NmE1LWIwNTVlNjhkOTkxYgAuAAAAAABhtW07FlyqQYq4iSYmMa0AAQD/xlJSPOSDSZLXIt9rew8vAAAAAAEIAAA=
  | )
  |  
  | [TotalCount] => 5
  | )

How do I pass the discovered folder to the request that lists all messages?

lstrojil commented 4 years ago

Ok, my bad, of course I found the answer as soon as I posted the question. :-)

Assigning the object directly to ParentFolderIds of the Request does the trick:

    $request->ParentFolderIds = FindSubFolders($client,'Iamalive');;