microsoft.exchange.webservices.data.core.enumeration.service.DeleteMode Java Examples

The following examples show how to use microsoft.exchange.webservices.data.core.enumeration.service.DeleteMode. 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: Item.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences)
    throws ServiceLocalException, Exception {
  this.throwIfThisIsNew();
  this.throwIfThisIsAttachment();

  // If sendCancellationsMode is null, use the default value that's
  // appropriate for item type.
  if (sendCancellationsMode == null) {
    sendCancellationsMode = this.getDefaultSendCancellationsMode();
  }

  // If affectedTaskOccurrences is null, use the default value that's
  // appropriate for item type.
  if (affectedTaskOccurrences == null) {
    affectedTaskOccurrences = this.getDefaultAffectedTaskOccurrences();
  }

  this.getService().deleteItem(this.getId(), deleteMode,
      sendCancellationsMode, affectedTaskOccurrences);
}
 
Example #2
Source File: Conversation.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Deletes item in the specified conversation.
 * Calling this method results in a call to EWS.
 *
 * @param contextFolderId The Id of the folder item must belong
 *                        to in order to be deleted. If contextFolderId is
 *                        null, item across the entire mailbox are deleted.
 * @param deleteMode      The deletion mode.
 * @throws Exception
 * @throws IndexOutOfBoundsException
 * @throws ServiceResponseException
 */
public void deleteItems(FolderId contextFolderId, DeleteMode deleteMode)
    throws ServiceResponseException, IndexOutOfBoundsException, Exception {
  HashMap<ConversationId, Date> m = new HashMap<ConversationId, Date>();
  m.put(this.getId(), this.getGlobalLastDeliveryTime());

  List<HashMap<ConversationId, Date>> f = new ArrayList<HashMap<ConversationId, Date>>();
  f.add(m);

  this.getService().deleteItemsInConversations(
      f,
      contextFolderId,
      deleteMode).getResponseAtIndex(0).throwIfNecessary();
}
 
Example #3
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void removeFolder(String folderName) throws FileSystemException {
	try {
		FolderId folderId = getFolderIdByFolderName(folderName);
		Folder folder = Folder.bind(exchangeService, folderId);
		folder.delete(DeleteMode.HardDelete);
	} catch (Exception e) {
		throw new FileSystemException(e);
	}
}
 
Example #4
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteFile(Item f) throws FileSystemException {
	 try {
		f.delete(DeleteMode.MoveToDeletedItems);
	} catch (Exception e) {
		throw new FileSystemException("Could not delete",e);
	}
}
 
Example #5
Source File: Folder.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   Indicates whether meeting cancellation messages should be
 *                                sent.
 * @param affectedTaskOccurrences Indicate which occurrence of a recurring task should be
 *                                deleted.
 * @throws Exception the exception
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) throws Exception {
  try {
    this.throwIfThisIsNew();
  } catch (InvalidOperationException e) {
    LOG.error(e);
  }

  this.getService().deleteFolder(this.getId(), deleteMode);
}
 
Example #6
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Deletes an item. Calling this method results in a call to EWS.
 *
 * @param itemId                  the item id
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @throws Exception the exception
 */
public void deleteItem(ItemId itemId, DeleteMode deleteMode, SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) throws Exception {
  List<ItemId> itemIdArray = new ArrayList<ItemId>();
  itemIdArray.add(itemId);

  EwsUtilities.validateParam(itemId, "itemId");
  this.internalDeleteItems(itemIdArray, deleteMode,
      sendCancellationsMode, affectedTaskOccurrences,
      ServiceErrorHandling.ThrowOnError);
}
 
Example #7
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Deletes multiple item in a single call to EWS.
 *
 * @param itemIds                 the item ids
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @param errorHandling           the error handling
 * @return A ServiceResponseCollection providing deletion results for each
 * of the specified item Ids.
 * @throws Exception the exception
 */
private ServiceResponseCollection<ServiceResponse> internalDeleteItems(
    Iterable<ItemId> itemIds, DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences,
    ServiceErrorHandling errorHandling) throws Exception {
  DeleteItemRequest request = new DeleteItemRequest(this, errorHandling);

  request.getItemIds().addRange(itemIds);
  request.setDeleteMode(deleteMode);
  request.setSendCancellationsMode(sendCancellationsMode);
  request.setAffectedTaskOccurrences(affectedTaskOccurrences);

  return request.execute();
}
 
Example #8
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Deletes a folder. Calling this method results in a call to EWS.
 *
 * @param folderId   The folder id
 * @param deleteMode The delete mode
 * @throws Exception the exception
 */
public void deleteFolder(FolderId folderId, DeleteMode deleteMode)
    throws Exception {
  EwsUtilities.validateParam(folderId, "folderId");

  DeleteFolderRequest request = new DeleteFolderRequest(this,
      ServiceErrorHandling.ThrowOnError);

  request.getFolderIds().add(folderId);
  request.setDeleteMode(deleteMode);

  request.execute();
}
 
Example #9
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Empties a folder. Calling this method results in a call to EWS.
 *
 * @param folderId         The folder id
 * @param deleteMode       The delete mode
 * @param deleteSubFolders if set to "true" empty folder should also delete sub folder.
 * @throws Exception the exception
 */
public void emptyFolder(FolderId folderId, DeleteMode deleteMode, boolean deleteSubFolders) throws Exception {
  EwsUtilities.validateParam(folderId, "folderId");

  EmptyFolderRequest request = new EmptyFolderRequest(this,
      ServiceErrorHandling.ThrowOnError);

  request.getFolderIds().add(folderId);
  request.setDeleteMode(deleteMode);
  request.setDeleteSubFolders(deleteSubFolders);
  request.execute();
}
 
Example #10
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 #11
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 #12
Source File: ConversationAction.java    From ews-java-api with MIT License 4 votes vote down vote up
/**
 * DeleteType
 */
public void setDeleteType(DeleteMode value) {
  this.deleteType = value;
}
 
Example #13
Source File: ExchangeService.java    From ews-java-api with MIT License 4 votes vote down vote up
/**
 * Applies one time conversation action on item in specified folder inside
 * the conversation.
 *
 * @param actionType          The action
 * @param idTimePairs         The id time pairs.
 * @param contextFolderId     The context folder id.
 * @param destinationFolderId The destination folder id.
 * @param deleteType          Type of the delete.
 * @param isRead              The is read.
 * @param errorHandlingMode   The error handling mode.
 * @throws Exception
 */
private ServiceResponseCollection<ServiceResponse> applyConversationOneTimeAction(
    ConversationActionType actionType,
    Iterable<HashMap<ConversationId, Date>> idTimePairs,
    FolderId contextFolderId, FolderId destinationFolderId,
    DeleteMode deleteType, Boolean isRead,
    ServiceErrorHandling errorHandlingMode) throws Exception {
  EwsUtilities.ewsAssert(
      actionType == ConversationActionType.Move || actionType == ConversationActionType.Delete
      || actionType == ConversationActionType.SetReadState || actionType == ConversationActionType.Copy,
      "ApplyConversationOneTimeAction", "Invalid actionType");

  EwsUtilities.validateParamCollection(idTimePairs.iterator(),
      "idTimePairs");
  EwsUtilities.validateMethodVersion(this,
      ExchangeVersion.Exchange2010_SP1, "ApplyConversationAction");

  ApplyConversationActionRequest request = new ApplyConversationActionRequest(
      this, errorHandlingMode);

  for (HashMap<ConversationId, Date> idTimePair : idTimePairs) {
    ConversationAction action = new ConversationAction();

    action.setAction(actionType);
    action.setConversationId(idTimePair.keySet().iterator().next());
    action
        .setContextFolderId(contextFolderId != null ? new FolderIdWrapper(
            contextFolderId)
            : null);
    action
        .setDestinationFolderId(destinationFolderId != null ? new FolderIdWrapper(
            destinationFolderId)
            : null);
    action.setConversationLastSyncTime(idTimePair.values().iterator()
        .next());
    action.setIsRead(isRead);
    action.setDeleteType(deleteType);

    request.getConversationActions().add(action);
  }

  return request.execute();
}
 
Example #14
Source File: ExchangeService.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes multiple item in a single call to EWS.
 *
 * @param itemIds                 the item ids
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @return A ServiceResponseCollection providing deletion results for each
 * of the specified item Ids.
 * @throws Exception the exception
 */
public ServiceResponseCollection<ServiceResponse> deleteItems(
    Iterable<ItemId> itemIds, DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) throws Exception {
  EwsUtilities.validateParamCollection(itemIds.iterator(), "itemIds");

  return this.internalDeleteItems(itemIds, deleteMode,
      sendCancellationsMode, affectedTaskOccurrences,
      ServiceErrorHandling.ReturnErrors);
}
 
Example #15
Source File: Conversation.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * This is not supported in this object.
 * Deletes the object.
 *
 * @param deleteMode              The deleteMode
 *                                The deletion mode.
 * @param sendCancellationsMode   The sendCancellationsMode
 *                                Indicates whether meeting cancellation messages should be sent.
 * @param affectedTaskOccurrences The affectedTaskOccurrences
 *                                Indicate which occurrence of a recurring task should be deleted.
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) {
  throw new UnsupportedOperationException();
}
 
Example #16
Source File: ExchangeService.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes the item in the specified conversation. Calling this method
 * results in a call to EWS.
 *
 * @param idLastSyncTimePairs The pairs of Id of conversation whose item should be deleted
 *                            and the date and time conversation was last synced (Items
 *                            received after that date will not be deleted). conversation
 *                            was last synced (Items received after that dateTime will not
 *                            be copied).
 * @param contextFolderId     The Id of the folder that contains the conversation.
 * @param deleteMode          The deletion mode
 * @throws Exception
 */
public ServiceResponseCollection<ServiceResponse> deleteItemsInConversations(
    Iterable<HashMap<ConversationId, Date>> idLastSyncTimePairs,
    FolderId contextFolderId, DeleteMode deleteMode) throws Exception {
  return this.applyConversationOneTimeAction(
      ConversationActionType.Delete, idLastSyncTimePairs,
      contextFolderId, null, deleteMode, null,
      ServiceErrorHandling.ReturnErrors);
}
 
Example #17
Source File: Folder.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Empties the folder. Calling this method results in a call to EWS.
 *
 * @param deletemode       the delete mode
 * @param deleteSubFolders Indicates whether sub-folder should also be deleted.
 * @throws Exception
 */
public void empty(DeleteMode deletemode, boolean deleteSubFolders)
    throws Exception {
  this.throwIfThisIsNew();
  this.getService().emptyFolder(this.getId(),
      deletemode, deleteSubFolders);
}
 
Example #18
Source File: RemoveFromCalendar.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              The deletion mode.
 * @param sendCancellationsMode   Indicates whether meeting cancellation messages should be
 *                                sent.
 * @param affectedTaskOccurrences Indicate which occurrence of a recurring task should be
 *                                deleted.
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) {
  throw new UnsupportedOperationException();
}
 
Example #19
Source File: SuppressReadReceipt.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) {
  throw new UnsupportedOperationException();
}
 
Example #20
Source File: PostReply.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @throws InvalidOperationException the invalid operation exception
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences)
    throws InvalidOperationException {
  throw new InvalidOperationException("Deleting this type of object isn't authorized.");
}
 
Example #21
Source File: ResponseObject.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Deletes the object.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 */
@Override
protected void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) {
  throw new UnsupportedOperationException();
}
 
Example #22
Source File: ConversationAction.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * DeleteType
 *
 * @return deleteType
 */
protected DeleteMode getDeleteType() {
  return this.deleteType;
}
 
Example #23
Source File: Folder.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Deletes the folder. Calling this method results in a call to EWS.
 *
 * @param deleteMode the delete mode
 * @throws Exception the exception
 */
public void delete(DeleteMode deleteMode) throws Exception {
  this.internalDelete(deleteMode, null, null);
}
 
Example #24
Source File: Appointment.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Deletes this appointment. Calling this method results in a call to EWS.
 *
 * @param deleteMode            the delete mode
 * @param sendCancellationsMode the send cancellations mode
 * @throws Exception the exception
 */
public void delete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode) throws Exception {
  this.internalDelete(deleteMode, sendCancellationsMode, null);
}
 
Example #25
Source File: Task.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Deletes the current occurrence of a recurring task. After the current
 * occurrence isdeleted, the task represents the next occurrence. Developers
 * should call Load to retrieve the new property values of the task. Calling
 * this method results in a call to EWS.
 *
 * @param deleteMode the delete mode
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
public void deleteCurrentOccurrence(DeleteMode deleteMode)
    throws ServiceLocalException, Exception {
  this.internalDelete(deleteMode, null,
      AffectedTaskOccurrence.SpecifiedOccurrenceOnly);
}
 
Example #26
Source File: Item.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Deletes the item. Calling this method results in a call to EWS.
 *
 * @param deleteMode the delete mode
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
public void delete(DeleteMode deleteMode) throws ServiceLocalException,
    Exception {
  this.internalDelete(deleteMode, null, null);
}
 
Example #27
Source File: ServiceObject.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Internal delete.
 *
 * @param deleteMode              the delete mode
 * @param sendCancellationsMode   the send cancellations mode
 * @param affectedTaskOccurrences the affected task occurrences
 * @throws Exception the exception
 */
protected abstract void internalDelete(DeleteMode deleteMode,
    SendCancellationsMode sendCancellationsMode,
    AffectedTaskOccurrence affectedTaskOccurrences) throws Exception;
 
Example #28
Source File: DeleteRequest.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Gets the delete mode.e
 *
 * @param deleteMode the new delete mode
 */
public void setDeleteMode(DeleteMode deleteMode) {
  this.deleteMode = deleteMode;
}
 
Example #29
Source File: DeleteRequest.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Gets the delete mode.
 *
 * @return the delete mode
 */
public DeleteMode getDeleteMode() {
  return this.deleteMode;
}