Exchange Web Service Search for Custom folder name
<p>I need to find the folder named "Archived", which will be at the parent level, NOT A SUBFOLDER. If the "Archived" folder is a subfolder, I don't want that to return in the result set. This is what I have coded, but this returns the sub folders as well.</p>

<pre><code>HashMap&lt;String, FolderId&gt; folderIdList = new HashMap&lt;String, FolderId&gt;();

FolderId readFromId = null; // Folder to read emails from - Inbox
FolderId moveToId = null;   // Folder to move emails to after processing - Archived

FolderView view = new FolderView(Integer.MAX_VALUE);

view.setPropertySet(new PropertySet(BasePropertySet.IdOnly));
view.getPropertySet().add(FolderSchema.DisplayName);
view.setTraversal(FolderTraversal.Deep);

try {
    FindFoldersResults findFolderResults = service.findFolders(
        new FolderId(WellKnownFolderName.MsgFolderRoot, userMailbox), view);

    // find specific folder
    for (Folder folder : findFolderResults) {
        System.out.println(folder.getDisplayName());

        // look for the desired folder name
        if (folder.getDisplayName().equalsIgnoreCase("Inbox")) {
            // get the id
            readFromId = folder.getId();
        }
            // add the folder id to map
            folderIdList.put(UtilConstants.READ_FROM, folder.getId());

        } else if (folder.getDisplayName().equalsIgnoreCase("Archived")) {
            // get the id
            moveToId = folder.getId();
        } else {
            // add the folder id to map
            folderIdList.put(UtilConstants.MOVE_TO, folder.getId());
        }
    }
} catch (Exception e) {
    log.error("Error while getting the folder id's for folders " +
        readFrom + ", " + moveTo + "" + e.getMessage());
    throw e;
}

return folderIdList;
</code></pre>

<p><a href="https://i.stack.imgur.com/BBLsJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BBLsJ.jpg" alt="enter image description here"></a></p>

<p><strong>Image transcription</strong>:</p>

<pre><code>Folder Name - Archived
Folder Id - AAMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMmI4M2ZkNzVhMgAuAAAAAAAoHfw6vz/jR685bS6+CozVAQBBPVBF5/AsS73+rEIOWaRMAAARBHT4AAA=
Child Folder Count - 1
Parent Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDAAAAA==
------------------------------------------------------------------------------------------
Folder Name - Inbox
Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDAAAAA==
Child Folder Count - 0
Parent Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBCAAAAA==
------------------------------------------------------------------------------------------
Folder Name - Calendar
Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDQAAAA==
Child Folder Count - 0
Parent Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDAAAAA==
------------------------------------------------------------------------------------------
Folder Name - Contacts
Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDgAAAA==
Child Folder Count - 7
Parent Folder Id - AQMkADJlZDRmYmRiLWUzMmEtNGMzOC1hMWQ4LWUyMgBiODNmZDc1YTIALgAAAygd/Dq/P+NHrzltLr4KjNUBAEE9UEXn8CxLv6sQg5ZpEwAAAIBDAAAAA==
</code></pre>