1

Using the query below, I created a search folder under the root folder. It works, but it also includes emails from the drafts folder.

Is there a straightforward way to exclude the drafts folder when creating this search folder?

<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
        xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
    </soap:Header>
    <soap:Body>
      <m:CreateFolder>
        <m:ParentFolderId>
          <t:DistinguishedFolderId Id="searchfolders" />
        </m:ParentFolderId>
        <m:Folders>
          <t:SearchFolder>
            <t:DisplayName> My_Search_Folder </t:DisplayName>
            <t:PermissionSet>
              <t:Permissions />
            </t:PermissionSet>
            <t:SearchParameters Traversal="Deep">
              <t:Restriction>
                <t:Contains ContainmentMode="FullString" ContainmentComparison="IgnoreCase">
                  <t:FieldURI FieldURI="item:Categories" />
                  <t:Constant Value="My_CATEGORY" />
                </t:Contains>
              </t:Restriction>
              <t:BaseFolderIds>
                <t:DistinguishedFolderId Id="root" />
              </t:BaseFolderIds>
            </t:SearchParameters>
          </t:SearchFolder>
        </m:Folders>
      </m:CreateFolder>
    </soap:Body>
  </soap:Envelope>
Rayhan Muktader
  • 2,038
  • 2
  • 15
  • 32

1 Answers1

1

You can't have a Folder Exception with a Search filter in EWS as all restrictions are Item based. So instead of Starting the Search at the root add each Subfolder into you SearchFolder defination Eg Inbox,SentItems etc instead.

The other option is add a Restriction that will exclude any messages that is currently Unsent by using a BitMask exclude https://msdn.microsoft.com/en-us/library/office/dd633708(v=exchg.80).aspx on the PR_MessageFlags property https://msdn.microsoft.com/en-us/library/cc839733(v=office.12).aspx eg

        <m:Restriction>
          <t:Excludes>
            <t:ExtendedFieldURI PropertyTag="3591" PropertyType="Integer" />
            <t:Bitmask Value="8" />
          </t:Excludes>
        </m:Restriction>
This won't exclude messages in the Drafts folder but will exclude any message in any folder that has the Bitwise MSGFLAG_UNSENT set in the PR_MessageFlags property.
Glen Scales
  • 20,495
  • 1
  • 20
  • 23