0
votes

I'm using PHP-EWS (https://github.com/jamesiarmes/php-ews) inside a cakePHP application. The goal is to read E-Mails from a "Public Folder" from the exchange server.

The Problem is I can only read the first "Dimension" of public folders and can't find a way to get the subdirectorys.

The folder I have to read from is 4 levels deep.

 $this->connect();

// start building the find folder request 
$request = new FindFolderType();
$request->Traversal = FolderQueryTraversalType::SHALLOW;
$request->FolderShape = new FolderResponseShapeType();
$request->FolderShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;

// configure the view
$request->IndexedPageFolderView = new IndexedPageViewType();
$request->IndexedPageFolderView->BasePoint = 'Beginning';
$request->IndexedPageFolderView->Offset = 0;

// set the starting folder
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new    DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::PUBLIC_FOLDERS_ROOT;

// request 
$response = $this->ews->FindFolder($request);

If I change "Traversal" to DEEP I get the error .

DEEP TRAVERSAL queries are not allowed for public folders.

I also tried to change

$request->IndexedPageFolderView->BasePoint

To things like "end" "second", it didn't change anything so I could not figure out what it does and how to use it.

I can't get the subdirectory Folder id (for changing the start point) either because it gets never selected.

Thank you for your help.

1

1 Answers

1
votes

Very good question. Unfortunately the library that you've chosen is out of date and unmaintained. I personally would suggest you use my more up to date one, garethp/php-ews.

I don't know if this is the best solution, but what I would suggest is to get the first level folder, then the second and so on. So if you know the directory structure of your folders, and it looked something like this

- Folder 1
    - Subfolder 1
        - Subfolder 2
            - Subfolder 3 (Target)
- Folder 2
- Folder 3

Then first you'd get Folder 1, which would be a child of DistinguishedFolderIdNameType::PUBLIC_FOLDERS_ROOT. Then you would get Subfolder 1 which would be a child of Folder 1, then get Subfolder 2, then Subfolder 3. I can't advise you on how you would manage that with the library you're currently using, but with mine it would look something like

$api = MailAPI::withUsernameAndPassword($host, $username, $password);
$folder1 = $api->getFolderByDisplayName('Folder1', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);
$subFolder1 = $api->getFolderByDisplayName('Subfolder1', $folder1->getFolderId());
$subFolder2 = $api->getFolderByDisplayName('Subfolder2', $subfolder1->getFolderId());
$subFolder3 = $api->getFolderByDisplayName('Subfolder3', $subfolder2->getFolderId());
$api->setFolderId($subFolder3->getFolderId());

Obviously that's a lot of calls, so if you're using that folder ID often, I would save the FolderID to a database for quicker retrieval later