Java Code Examples for microsoft.exchange.webservices.data.search.filter.SearchFilter#IsEqualTo

The following examples show how to use microsoft.exchange.webservices.data.search.filter.SearchFilter#IsEqualTo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 7 votes vote down vote up
@Override
public Iterator<Item> listFiles(String folder) throws FileSystemException {
	try {
		FolderId folderId = findFolder(basefolderId,folder);
		ItemView view = new ItemView(getMaxNumberOfMessagesToList());
		view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
		FindItemsResults<Item> findResults;
		if ("NDR".equalsIgnoreCase(getFilter())) {
			SearchFilter searchFilterBounce = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR");
			findResults = exchangeService.findItems(folderId,searchFilterBounce, view);
		} else {
			findResults = exchangeService.findItems(folderId, view);
		}
		if (findResults.getTotalCount() == 0) {
			return null;
		} else {
			return findResults.getItems().iterator();
		}
	} catch (Exception e) {
		throw new FileSystemException("Cannot list messages in folder ["+folder+"]", e);
	}
}
 
Example 2
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Retrieves a collection of all Conversations in the specified Folder.
 *
 * @param view     The view controlling the number of conversations returned.
 * @param filter   The search filter. Only search filter class supported
 *                 SearchFilter.IsEqualTo
 * @param folderId The Id of the folder in which to search for conversations.
 * @throws Exception
 */
private Collection<Conversation> findConversation(
    ConversationIndexedItemView view, SearchFilter.IsEqualTo filter,
    FolderId folderId) throws Exception {
  EwsUtilities.validateParam(view, "view");
  EwsUtilities.validateParamAllowNull(filter, "filter");
  EwsUtilities.validateParam(folderId, "folderId");
  EwsUtilities.validateMethodVersion(this,
      ExchangeVersion.Exchange2010_SP1, "FindConversation");

  FindConversationRequest request = new FindConversationRequest(this);
  request.setIndexedItemView(view);
  request.setConversationViewFilter(filter);
  request.setFolderId(new FolderIdWrapper(folderId));

  return request.execute().getConversations();
}
 
Example 3
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
public FolderId findFolder(FolderId baseFolderId, String folderName) throws Exception {
	FindFoldersResults findFoldersResultsIn;
	FolderId result;
	FolderView folderViewIn = new FolderView(10);
	if (StringUtils.isNotEmpty(folderName)) {
		log.debug("searching folder ["+folderName+"]");
		SearchFilter searchFilterIn = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName);
		if (baseFolderId==null) {
			findFoldersResultsIn = exchangeService.findFolders(WellKnownFolderName.MsgFolderRoot, searchFilterIn, folderViewIn);
		} else {
			findFoldersResultsIn = exchangeService.findFolders(baseFolderId, searchFilterIn, folderViewIn);
		}
		if (findFoldersResultsIn.getTotalCount() == 0) {
			if(log.isDebugEnabled()) log.debug("no folder found with name [" + folderName + "] in basefolder ["+baseFolderId+"]");
			return null;
		} 
		if (findFoldersResultsIn.getTotalCount() > 1) {
			if (log.isDebugEnabled()) {
				for (Folder folder:findFoldersResultsIn.getFolders()) {
					log.debug("found folder ["+folder.getDisplayName()+"]");
				}
			}
			throw new ConfigurationException("multiple folders found with name ["+ folderName + "]");
		}
	} else {
		//findFoldersResultsIn = exchangeService.findFolders(baseFolderId, folderViewIn);
		return baseFolderId;
	}
	if (findFoldersResultsIn.getFolders().isEmpty()) {
		result=baseFolderId;
	} else {
		result=findFoldersResultsIn.getFolders().get(0).getId();
	}
	return result;
}
 
Example 4
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean exists(Item f) throws FileSystemException {
	try {
		ItemView view = new ItemView(1);
		view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
		SearchFilter searchFilter =  new SearchFilter.IsEqualTo(ItemSchema.Id, f.getId().toString());
		FindItemsResults<Item> findResults;
		findResults = exchangeService.findItems(basefolderId,searchFilter, view);
		return findResults.getTotalCount()!=0;
	} catch (Exception e) {
		throw new FileSystemException(e);
	}
}
 
Example 5
Source File: ConsumeEWS.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Fills the internal message queue if such queue is empty. This is due to
 * the fact that per single session there may be multiple messages retrieved
 * from the email server (see FETCH_SIZE).
 */
protected void fillMessageQueueIfNecessary(ProcessContext context) throws ProcessException {
    if (this.messageQueue.isEmpty()) {
        ExchangeService service = this.initializeIfNecessary(context);
        boolean deleteOnRead = context.getProperty(SHOULD_DELETE_MESSAGES).getValue().equals("true");
        boolean markAsRead = context.getProperty(SHOULD_MARK_READ).getValue().equals("true");

        try {
            //Get Folder
            Folder folder = getFolder(service);

            ItemView view = new ItemView(messageQueue.remainingCapacity());
            view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

            SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
            FindItemsResults<Item> findResults = service.findItems(folder.getId(), sf, view);

            if(findResults == null || findResults.getItems().size()== 0){
                return;
            }

            service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);

            for (Item item : findResults) {
                EmailMessage ewsMessage = (EmailMessage) item;
                messageQueue.add(parseMessage(ewsMessage));

                if(deleteOnRead){
                    ewsMessage.delete(DeleteMode.HardDelete);
                } else if(markAsRead){
                    ewsMessage.setIsRead(true);
                    ewsMessage.update(ConflictResolutionMode.AlwaysOverwrite);
                }
            }

            service.close();
        } catch (Exception e) {
            throw new ProcessException("Failed retrieving new messages from EWS.", e);
        }
    }
}
 
Example 6
Source File: FindConversationRequest.java    From ews-java-api with MIT License 4 votes vote down vote up
/**
 * Gets or sets the search filter.
 */
protected SearchFilter.IsEqualTo getConversationViewFilter() {

  return this.searchFilter;
}
 
Example 7
Source File: ConsumeEWS.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Fills the internal message queue if such queue is empty. This is due to
 * the fact that per single session there may be multiple messages retrieved
 * from the email server (see FETCH_SIZE).
 */
protected void fillMessageQueueIfNecessary(ProcessContext context) throws ProcessException {
    if (this.messageQueue.isEmpty()) {
        ExchangeService service = this.initializeIfNecessary(context);
        boolean deleteOnRead = context.getProperty(SHOULD_DELETE_MESSAGES).getValue().equals("true");
        boolean markAsRead = context.getProperty(SHOULD_MARK_READ).getValue().equals("true");
        String includeHeaders = context.getProperty(INCLUDE_EMAIL_HEADERS).getValue();
        String excludeHeaders = context.getProperty(EXCLUDE_EMAIL_HEADERS).getValue();

        List<String> includeHeadersList = null;
        List<String> excludeHeadersList = null;

        if (!StringUtils.isEmpty(includeHeaders)) {
            includeHeadersList = Arrays.asList(includeHeaders.split(","));
        }

        if (!StringUtils.isEmpty(excludeHeaders)) {
            excludeHeadersList = Arrays.asList(excludeHeaders.split(","));
        }

        try {
            //Get Folder
            Folder folder = getFolder(service);

            ItemView view = new ItemView(messageQueue.remainingCapacity());
            view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

            SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
            FindItemsResults<Item> findResults = service.findItems(folder.getId(), sf, view);

            if(findResults == null || findResults.getItems().size()== 0){
                return;
            }

            service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);

            for (Item item : findResults) {
                EmailMessage ewsMessage = (EmailMessage) item;
                messageQueue.add(parseMessage(ewsMessage,includeHeadersList,excludeHeadersList));

                if(deleteOnRead){
                    ewsMessage.delete(DeleteMode.HardDelete);
                } else if(markAsRead){
                    ewsMessage.setIsRead(true);
                    ewsMessage.update(ConflictResolutionMode.AlwaysOverwrite);
                }
            }

            service.close();
        } catch (Exception e) {
            throw new ProcessException("Failed retrieving new messages from EWS.", e);
        }
    }
}
 
Example 8
Source File: FindConversationRequest.java    From ews-java-api with MIT License 2 votes vote down vote up
public void setConversationViewFilter(SearchFilter.IsEqualTo value) {
  this.searchFilter = value;

}