From 1acddc49546229162c6bc6e52e76ce07eed64db9 Mon Sep 17 00:00:00 2001 From: mguessan Date: Thu, 4 Sep 2014 07:03:47 +0000 Subject: [PATCH] EWS: improve folder paged search git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2318 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ews/EwsExchangeSession.java | 15 ++++++++------- .../davmail/exchange/ews/FindFolderMethod.java | 15 ++++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 792eedd9..9aa58fb3 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -779,10 +779,8 @@ public class EwsExchangeSession extends ExchangeSession { FolderId folderId = getFolderId(folderPath); FindItemMethod findItemMethod; do { - int fetchCount = PAGE_SIZE; - // search items in folder, do not retrieve all properties - findItemMethod = new FindItemMethod(folderQueryTraversal, BaseShape.ID_ONLY, folderId, resultCount, fetchCount); + findItemMethod = new FindItemMethod(folderQueryTraversal, BaseShape.ID_ONLY, folderId, resultCount, PAGE_SIZE); for (String attribute : attributes) { findItemMethod.addAdditionalProperty(Field.get(attribute)); } @@ -812,7 +810,7 @@ public class EwsExchangeSession extends ExchangeSession { } resultCount = results.size(); if (resultCount > 0 && LOGGER.isDebugEnabled()) { - LOGGER.debug("Folder " + folderPath + " - Search items current count: " + resultCount + " fetchCount: " + fetchCount + LOGGER.debug("Folder " + folderPath + " - Search items current count: " + resultCount + " fetchCount: " + PAGE_SIZE + " highest uid: " + results.get(resultCount - 1).get(Field.get("imapUid").getResponseName()) + " lowest uid: " + results.get(0).get(Field.get("imapUid").getResponseName())); } @@ -1131,12 +1129,14 @@ public class EwsExchangeSession extends ExchangeSession { protected void appendSubFolders(List folders, String parentFolderPath, FolderId parentFolderId, Condition condition, boolean recursive) throws IOException { + int resultCount = 0; FindFolderMethod findFolderMethod; do { findFolderMethod = new FindFolderMethod(FolderQueryTraversal.SHALLOW, - BaseShape.ID_ONLY, parentFolderId, FOLDER_PROPERTIES, (SearchExpression) condition); + BaseShape.ID_ONLY, parentFolderId, FOLDER_PROPERTIES, (SearchExpression) condition, resultCount, PAGE_SIZE); executeMethod(findFolderMethod); for (EWSMethod.Item item : findFolderMethod.getResponseItems()) { + resultCount++; Folder folder = buildFolder(item); if (parentFolderPath.length() > 0) { if (parentFolderPath.endsWith("/")) { @@ -1151,7 +1151,7 @@ public class EwsExchangeSession extends ExchangeSession { } folders.add(folder); if (recursive && folder.hasChildren) { - appendSubFolders(folders, folder.folderPath, folder.folderId, condition, recursive); + appendSubFolders(folders, folder.folderPath, folder.folderId, condition, true); } } } while (!(findFolderMethod.includesLastItemInRange)); @@ -2331,7 +2331,8 @@ public class EwsExchangeSession extends ExchangeSession { parentFolderId, FOLDER_PROPERTIES, new TwoOperandExpression(TwoOperandExpression.Operator.IsEqualTo, - Field.get("folderDisplayName"), folderName) + Field.get("folderDisplayName"), folderName), + 0, 1 ); executeMethod(findFolderMethod); EWSMethod.Item item = findFolderMethod.getResponseItem(); diff --git a/src/java/davmail/exchange/ews/FindFolderMethod.java b/src/java/davmail/exchange/ews/FindFolderMethod.java index 7ad6e3dd..73f0dd6c 100644 --- a/src/java/davmail/exchange/ews/FindFolderMethod.java +++ b/src/java/davmail/exchange/ews/FindFolderMethod.java @@ -32,15 +32,18 @@ public class FindFolderMethod extends EWSMethod { * @param baseShape base shape * @param parentFolderId parent folder id * @param additionalProperties folder properties + * @param offset start offset + * @param maxCount maximum result count */ - public FindFolderMethod(FolderQueryTraversal traversal, BaseShape baseShape, FolderId parentFolderId, Set additionalProperties) { + public FindFolderMethod(FolderQueryTraversal traversal, BaseShape baseShape, FolderId parentFolderId, + Set additionalProperties, int offset, int maxCount) { super("Folder", "FindFolder"); this.traversal = traversal; this.baseShape = baseShape; this.parentFolderId = parentFolderId; this.additionalProperties = additionalProperties; - // force paging mode - this.maxCount = 10000; + this.offset = offset; + this.maxCount = maxCount; } /** @@ -51,10 +54,12 @@ public class FindFolderMethod extends EWSMethod { * @param parentFolderId parent folder id * @param additionalProperties folder properties * @param searchExpression search expression + * @param offset start offset + * @param maxCount maximum result count */ public FindFolderMethod(FolderQueryTraversal traversal, BaseShape baseShape, FolderId parentFolderId, - Set additionalProperties, SearchExpression searchExpression) { - this(traversal, baseShape, parentFolderId, additionalProperties); + Set additionalProperties, SearchExpression searchExpression, int offset, int maxCount) { + this(traversal, baseShape, parentFolderId, additionalProperties, offset, maxCount); this.searchExpression = searchExpression; } }