2017-09-06 111 views
0
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties); 
itempropertyset.setRequestedBodyType(BodyType.Text); 

ItemView view = new ItemView(10); 
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Descending); 
view.setPropertySet(new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived)); 
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)); 
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, searchFilter, view); 

service.loadPropertiesForItems(findResults, itempropertyset); 
System.out.println("Total number of items found: " + findResults.getTotalCount()); 

for (Item item : findResults) { 
    System.out.println(item.getSubject()); 
    System.out.println(item.getBody()); 
} 

當前在應用程序中,我連接到我們的交換機,我的要求是讀取未讀郵件並獲取附件。EWS Java Api搜索過濾器被忽略

但是,搜索過濾器不起作用,我可以將Operator更改爲「或」,我可以將SortDirection從升序更改爲降序,但它沒有區別。我的搜索過濾器目前設置爲未讀,但會帶回隨機電子郵件。 ItemView設置爲10,但帶回了157封電子郵件。

從println的:Total number of items found: 157

什麼,我做錯了什麼建議? 親切的問候

回答

0

解決了這個問題,從searchFilterCollection更改爲searchFilter並添加視圖,這也解決了日期排序問題。

FindItemsResults<Item> findResults 
         = service.findItems(WellKnownFolderName.Inbox, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false), view);