OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
869 stars 560 forks source link

FindItemsResults.getTotalCount returns -1 #568

Open mirner opened 8 years ago

mirner commented 8 years ago

We have an account that has messages in it, but code below returns "-1"

FindItemsResults findResults = exchangeService.findItems(folder.getId(), unreadFilter, unreadView); findResults.getTotalCount();

Some accounts do it more often than others. The only "fix" we have found is to connect via web or outlook and move all emails to a different folder.

kolmanpav commented 7 years ago

We have same problems:

I have this code in Java 1.8.0_51 (ews-java-api 2.0) - connected to EWS Office365: int emailsCount = getEmails(0, 1, folderId).getTotalCount();

definition of function: private FindItemsResults getEmails(int start, int count, FolderId folderId) { ItemView view = new ItemView(count); view.setOffset(start); try { return service.findItems(folderId, view); } catch (Exception e) { throw new RuntimeException("Error while finding items (emails) from '" + start + "' to '" + (start + count) + "'!!", e); } }

If I set value less than totalCount of emails into the second parametr of my getEmails function then I get result into emailsCount variable == -1.

Example: I have 3 emails in my selected folder in my email box.

I invoke method: getEmails(0, 1, folderId).getTotalCount() and I get -1. I invoke method: getEmails(0, 2, folderId).getTotalCount() and I get -1 I invoke method: getEmails(0, 3, folderId).getTotalCount() and I get 3

Thanks for fix of this bug

Shiftuia commented 6 years ago

And this bug is still here. I get -1 after catching ServiceRequestExeption with null definition

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. null microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74) microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158) microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:504) microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:523) microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:98) microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:114)