I found a possible solution.
There is an unnamed extended EWS property "0x6656"
in public folder in Exchange 2013 (I used OutlookSpy - selected public folder mailbox, click on EMAPIFolder).
There is, for example, 4e1f53e4-0f2d-46eb-873f-b4857d9d395a@myDomain.local
The value is the same for every folder in one public folder mailbox. The GUID (before @
) is the ExchangeMailboxGuid
- this can be read together with public folder mailbox from Active Directory and then pair public folders with mailbox.
The problem is that I was not able to read this property using managed EWS (I'm not able to read any unnamed Extended properties). I used this definition:
var ExchangeMailboxGuid = new ExtendedPropertyDefinition(0x6656, MapiPropertyType.String);
Maybe I can try unmanaged EWS, but it is more complicated.
As a temporary solution I combined EWS and remote PowerShell. Here is my pseudocode:
if (folderId == null) // It is root public folder
{
var mailboxGuid = GetMailboxId();
// public folder root
var ewsFolderId = EwsAdapter.GetPublicFolderId(folderId);
// get all root public folders from all public folder mailboxes
var tempFindFolderResults = FindFolders(ewsFolderId);
var powerShellConnection = new powerShellConnection(ConnectionConfiguration);
// get all root public folders with info which mailbox is owner
var PublicFolderMailboxes = powerShellConnection.GetPublicFolders();
foreach (var publicFolderMailbox in PublicFolderMailboxes)
{
if (publicFolderMailbox.Attributes["ExchangeMailboxGuid"].Value == mailboxGuid)
{
foreach (var tempFindFolderResult in tempFindFolderResults)
{
if (tempFindFolderResult.DisplayName == publicFolderMailbox.Attributes["Name"].Value)
{
// add only folder from selected public folder mailbox
findFolderResults.Add(tempFindFolderResult);
}
}
}
}
}
else // it is public subfolder - standard handling
{
var ewsFolderId = EwsAdapterHelper.GetPublicFolderId(folderId);
findFolderResults = FindFolders(ewsFolderId);
}
Here's the PowerShell command I use in the method GetPublicFolders
:
Get-PublicFolder -GetChildren
Edit: I think EWS doesn't fully support Exchange 2013 Public Folders -
- how to get public folders from any "Public Folder Mailbox" and
- save public folder in root level to any "Public Folder Mailbox" (Not only Primary Public Folder Mailbox).