gpt4 book ai didi

java - Exchange Web 服务搜索自定义文件夹名称

转载 作者:行者123 更新时间:2023-11-30 02:48:35 25 4
gpt4 key购买 nike

我需要找到名为“Archived”的文件夹,该文件夹位于父级别,而不是子文件夹。如果“Archived”文件夹是子文件夹,我不希望它返回到结果集中。这是我编码的内容,但这也会返回子文件夹。

HashMap<String, FolderId> folderIdList = new HashMap<String, FolderId>();

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;

enter image description here

图像转录:

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==

最佳答案

I need to find the folder name "Archived" which will be at the Parent level

如果是这种情况,您不应该使用深度遍历,因为这将返回层次结构中的所有文件夹,而不仅仅是顶层的文件夹。我还建议您使用 SearchFilter 这样它只返回您想要的文件夹,这将简化您的代码,例如:

String folderSearchName = "Archived";

FolderView fvFolderView = new FolderView(1);
fvFolderView.Traversal = FolderTraversal.Shallow;

SearchFilter fsFolderSearch = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderSearchName);

FolderId SearchRoot = new FolderId(WellKnownFolderName.MsgFolderRoot, "user@domain.com");

FindFoldersResults folderSearchResults = service.FindFolders(SearchRoot, fsFolderSearch, fvFolderView);
if (folderSearchResults.Folders.Count == 1)
{
Console.WriteLine(folderSearchResults.Folders[0].DisplayName);
}

关于java - Exchange Web 服务搜索自定义文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39398727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com