locked
Public folders returned when quering for folders - how can we avoid that (only get user's private folders) RRS feed

  • Question

  • We're experience a problem reading out contacts from exchange 2007 using EWS. The main problem is that we get contacts from public folders returned and we only want the user's public contacts.


    Basically what we do is:

    Readout the list of contact folders.

    For each folder
        read out list of contacts


    When reading out folders we query EWS to return all folders where folder class is IPF.Contact and on all levels in the hierarchy. What we get back is a list of personal contact folders and some public folders related to Microsoft Dynamics CRM.

    The request for reading out contact folders is this:

    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header>
            <RequestServerVersion
                xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
                Version="Exchange2007_SP1" />
        </soapenv:Header>
        <soapenv:Body>
            <FindFolder
                xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
                Traversal="Deep">
                <FolderShape>
                    <BaseShape
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</BaseShape>
                </FolderShape>
                <Restriction>
                    <IsEqualTo
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
                        <FieldURI FieldURI="folder:FolderClass" />
                        <FieldURIOrConstant>
                            <Constant Value="IPF.Contact" />
                        </FieldURIOrConstant>
                    </IsEqualTo>
                </Restriction>
                <ParentFolderIds>
                    <DistinguishedFolderId
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
                        Id="root">
                        <Mailbox>
                            <EmailAddress>jer@domain.com</EmailAddress>
                        </Mailbox>
                    </DistinguishedFolderId>
                </ParentFolderIds>
            </FindFolder>
        </soapenv:Body>
    </soapenv:Envelope>

    The question is simply, how do we issue a query to EWS that will only return a user's private folder(s) and no public ones?
    • Edited by Mads Brenoe Friday, September 18, 2009 8:16 AM
    Thursday, September 17, 2009 12:40 PM

All replies

  • Given that you are using DistinguishedFolderId "root" as the base for your search, you should not be getting back any public folders.  There is a "parallel" root for PFs called publicFoldersRoot which is not contained under root.  Just as a matter of practice, I would suggest you use msgFolderRoot instead as that corresponds to the IPM subtree which is what people typically consider their "mailbox". 

    Are you sure that the contacts that are being returned are indeed from a public folder?  Could you post one of the contact's ItemIds that you believe to be from a public folder?
    David Sterling | Microsoft Exchange Web Services | http://www.microsoft.com/MSPress/books/10724.aspx
    Thursday, September 17, 2009 1:47 PM
  • This is an example of the FindItem request that returns some contacts that should not be there (according to the user). I have been informed that the user has approx. 250 contacts and this returns more than 500, so it's coming from a folder the user doesn't want/expect (what I have been informed is a Public folder).

    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header>
            <RequestServerVersion
                xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
                Version="Exchange2007_SP1" />
        </soapenv:Header>
        <soapenv:Body>
            <FindItem
                xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
                Traversal="Shallow">
                <ItemShape>
                    <BaseShape
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</BaseShape>
                </ItemShape>
                <ParentFolderIds>
                    <FolderId
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwAuAAAAAADUvVAZDoY5TIiWeU/afC0hAQAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAA="
                        ChangeKey="AwAAABQAAADkaAnCRljWRKpc/g48wz6XABTSvg==" />
                </ParentFolderIds>
            </FindItem>
        </soapenv:Body>
    </soapenv:Envelope>

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Header>
            <t:ServerVersionInfo MajorVersion="8"
                MinorVersion="1" MajorBuildNumber="359" MinorBuildNumber="2"
                Version="Exchange2007_SP1" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
        </soap:Header>
        <soap:Body>
            <m:FindItemResponse
                xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
                xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
                <m:ResponseMessages>
                    <m:FindItemResponseMessage ResponseClass="Success">
                        <m:ResponseCode>NoError</m:ResponseCode>
                        <m:RootFolder TotalItemsInView="567"
                            IncludesLastItemInRange="true">
                            <t:Items>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKMAAA="
                                        ChangeKey="EQAAABYAAAB5+B1fR5DTRLBfSJzirIq3AAAAuhJs" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKNAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATErA==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKOAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATErQ==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKPAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATErg==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKQAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATErw==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKRAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATEsA==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKSAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATEsQ==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKTAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATEsg==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKUAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATEsw==" />
                                </t:Contact>
                                <t:Contact>
                                    <t:ItemId
                                        Id="AAMkADMwYTU5MDEyLTI1ZDAtNDFkYS04MGNkLTYzMjk5MWU5ZTNiNwBGAAAAAADUvVAZDoY5TIiWeU/afC0hBwAYzVOJMwAYRqlNb6rw70JqAAAF5AAsAAAYzVOJMwAYRqlNb6rw70JqAAAGdCKVAAA="
                                        ChangeKey="EQAAABQAAADkaAnCRljWRKpc/g48wz6XAATEtA==" />
                                </t:Contact>

                  many more contacts...

                            </t:Items>
                        </m:RootFolder>
                    </m:FindItemResponseMessage>
                </m:ResponseMessages>
            </m:FindItemResponse>
        </soap:Body>
    </soap:Envelope>


    Friday, September 18, 2009 8:30 AM
  • None of those contacts are public folder contact - they are all from the store.  So, a few more questions:

    1.  How are they verifying that there are truly only 250 contacts in their mailbox?
    2.  You could use a tool such as MFCMAPI to bind to the mailbox and verify the number of contacts in the contacts folder.
    3.  Add a sortby clause (display name) and request the display name as part of the response shape to ensure that you aren't getting back duplicate contacts for some odd reason.


    David Sterling | Microsoft Exchange Web Services | http://www.microsoft.com/MSPress/books/10724.aspx
    Friday, September 18, 2009 4:04 PM