Exemplo n.º 1
0
  /**
   * Determines the set of {@link Message}s to be deleted from this <code>Conversation</code>.
   * Assembles a new {@link PendingDelete} object encapsulating the data on the items to be deleted.
   *
   * <p>A message will be deleted unless:
   *
   * <ul>
   *   <li>The caller lacks {@link ACL#RIGHT_DELETE} permission on the <code>Message</code>.
   *   <li>The caller has specified a {@link MailItem.TargetConstraint} that explicitly excludes the
   *       <code>Message</code>.
   *   <li>The caller has specified the maximum change number they know about, and the
   *       (modification/content) change number on the <code>Message</code> is greater.
   * </ul>
   *
   * As a result of all these constraints, no messages may actually be deleted.
   *
   * @throws ServiceException The following error codes are possible:
   *     <ul>
   *       <li><code>mail.MODIFY_CONFLICT</code> - if the caller specified a max change number and a
   *           modification check, and the modified change number of the <code>Message</code> is
   *           greater
   *       <li><code>service.FAILURE</code> - if there's a database failure fetching the message
   *           list
   *     </ul>
   */
  @Override
  PendingDelete getDeletionInfo() throws ServiceException {
    PendingDelete info = new PendingDelete();
    info.rootId = mId;
    info.itemIds.add(getType(), mId);

    if (mData.size == 0) return info;
    List<Message> msgs = getMessages();
    TargetConstraint tcon = mMailbox.getOperationTargetConstraint();

    boolean excludeModify = false, excludeAccess = false;
    for (Message child : msgs) {
      // silently skip explicitly excluded messages, PERMISSION_DENIED messages, and MODIFY_CONFLICT
      // messages
      if (!TargetConstraint.checkItem(tcon, child)) continue;
      else if (!child.canAccess(ACL.RIGHT_DELETE)) excludeAccess = true;
      else if (!child.checkChangeID()) excludeModify = true;
      else info.add(child.getDeletionInfo());
    }

    int totalDeleted = info.itemIds.size();
    if (totalDeleted == 1) {
      // if all messages have been excluded, some for "error" reasons, throw an exception
      if (excludeAccess)
        throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
      if (excludeModify) throw MailServiceException.MODIFY_CONFLICT();
    }
    if (totalDeleted != msgs.size() + 1) info.incomplete = true;
    return info;
  }