Search in sources :

Example 16 with Color

use of com.zimbra.common.mailbox.Color in project zm-mailbox by Zimbra.

the class ItemAction method handleCommon.

protected ItemActionResult handleCommon(Map<String, Object> context, Element request, MailItem.Type type) throws ServiceException {
    Element action = request.getElement(MailConstants.E_ACTION);
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    SoapProtocol responseProto = zsc.getResponseProtocol();
    // determine the requested operation
    boolean flagValue = !isOperationFlagged(request);
    String opStr = getOperation(request);
    // figure out which items are local and which ones are remote, and proxy accordingly
    List<Integer> local = new ArrayList<Integer>();
    Map<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
    partitionItems(zsc, action.getAttribute(MailConstants.A_ID), local, remote);
    if (remote.isEmpty() && local.isEmpty()) {
        return ItemActionResult.create(opStr);
    }
    // for moves/copies, make sure that we're going to receive notifications from the target folder
    Account remoteNotify = forceRemoteSession(zsc, context, octxt, opStr, action);
    // handle referenced items living on other servers
    ItemActionResult result = proxyRemoteItems(action, remote, request, context);
    // handle referenced items living on this server
    if (!local.isEmpty()) {
        String constraint = action.getAttribute(MailConstants.A_TARGET_CONSTRAINT, null);
        TargetConstraint tcon = TargetConstraint.parseConstraint(mbox, constraint);
        ItemActionResult localResults;
        // set additional parameters (depends on op type)
        if (opStr.equals(MailConstants.OP_TAG)) {
            String tagName = action.getAttribute(MailConstants.A_TAG_NAMES, null);
            if (tagName == null) {
                if (action.getAttribute(MailConstants.A_TAG) == null) {
                    throw ServiceException.INVALID_REQUEST("missing required attribute: " + MailConstants.A_TAG_NAMES, null);
                }
                tagName = TagUtil.tagIdToName(mbox, octxt, (int) action.getAttributeLong(MailConstants.A_TAG));
            }
            localResults = ItemActionHelper.TAG(octxt, mbox, responseProto, local, type, tagName, flagValue, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_FLAG)) {
            localResults = ItemActionHelper.FLAG(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_PRIORITY)) {
            localResults = ItemActionHelper.PRIORITY(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_READ)) {
            localResults = ItemActionHelper.READ(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_COLOR)) {
            Color color = getColor(action);
            localResults = ItemActionHelper.COLOR(octxt, mbox, responseProto, local, type, tcon, color).getResult();
        } else if (opStr.equals(MailConstants.OP_HARD_DELETE)) {
            localResults = ItemActionHelper.HARD_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_RECOVER)) {
            ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER), zsc);
            localResults = ItemActionHelper.RECOVER(octxt, mbox, responseProto, local, type, tcon, iidFolder).getResult();
        } else if (opStr.equals(MailConstants.OP_DUMPSTER_DELETE)) {
            localResults = ItemActionHelper.DUMPSTER_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_TRASH)) {
            localResults = handleTrashOperation(octxt, request, mbox, responseProto, local, type, tcon);
        } else if (opStr.equals(MailConstants.OP_MOVE)) {
            localResults = handleMoveOperation(zsc, octxt, request, action, mbox, responseProto, local, type, tcon);
        } else if (opStr.equals(MailConstants.OP_COPY)) {
            ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER), zsc);
            localResults = ItemActionHelper.COPY(octxt, mbox, responseProto, local, type, tcon, iidFolder).getResult();
        } else if (opStr.equals(MailConstants.OP_SPAM)) {
            String defaultFolder = (flagValue ? Mailbox.ID_FOLDER_SPAM : Mailbox.ID_FOLDER_INBOX) + "";
            ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER, defaultFolder), zsc);
            localResults = ItemActionHelper.SPAM(octxt, mbox, responseProto, local, type, flagValue, tcon, iidFolder).getResult();
        } else if (opStr.equals(MailConstants.OP_RENAME)) {
            String name = action.getAttribute(MailConstants.A_NAME);
            ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER, "-1"), zsc);
            localResults = ItemActionHelper.RENAME(octxt, mbox, responseProto, local, type, tcon, name, iidFolder).getResult();
        } else if (opStr.equals(MailConstants.OP_UPDATE)) {
            String folderId = action.getAttribute(MailConstants.A_FOLDER, null);
            ItemId iidFolder = null;
            if (folderId != null) {
                iidFolder = new ItemId(folderId, zsc);
                if (!iidFolder.belongsTo(mbox)) {
                    throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
                } else if (iidFolder.getId() <= 0) {
                    throw MailServiceException.NO_SUCH_FOLDER(iidFolder.getId());
                }
            }
            String name = action.getAttribute(MailConstants.A_NAME, null);
            String flags = action.getAttribute(MailConstants.A_FLAGS, null);
            String[] tags = TagUtil.parseTags(action, mbox, octxt);
            Color color = getColor(action);
            localResults = ItemActionHelper.UPDATE(octxt, mbox, responseProto, local, type, tcon, name, iidFolder, flags, tags, color).getResult();
        } else if (opStr.equals(MailConstants.OP_LOCK)) {
            localResults = ItemActionHelper.LOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_UNLOCK)) {
            localResults = ItemActionHelper.UNLOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(MailConstants.OP_INHERIT)) {
            mbox.alterTag(octxt, ArrayUtil.toIntArray(local), type, Flag.FlagInfo.NO_INHERIT, false, tcon);
            localResults = new ItemActionResult(local);
        } else if (opStr.equals(MailConstants.OP_MUTE) && type == MailItem.Type.CONVERSATION) {
            // note that "mute" ignores the tcon value
            localResults = ItemActionHelper.TAG(octxt, mbox, responseProto, local, type, Flag.FlagInfo.MUTED.toString(), flagValue, null).getResult();
            if (flagValue) {
                // when marking muted, items are also marked read
                ItemActionHelper.READ(octxt, mbox, responseProto, local, type, flagValue, null).getResult();
            }
        } else if (opStr.equals(MailConstants.OP_RESET_IMAP_UID)) {
            mbox.resetImapUid(octxt, local);
            localResults = new ItemActionResult(local);
        } else {
            throw ServiceException.INVALID_REQUEST("unknown operation: " + opStr, null);
        }
        result.appendSuccessIds(localResults.getSuccessIds());
        if (opStr.equals(MailConstants.OP_HARD_DELETE)) {
            ((DeleteActionResult) result).appendNonExistentIds(localResults);
        } else if (opStr.equals(MailConstants.OP_COPY)) {
            ((CopyActionResult) result).appendCreatedIds(localResults);
        }
    }
    // for moves/copies, make sure that we received notifications from the target folder
    if (remoteNotify != null) {
        proxyRequest(zsc.createElement(MailConstants.NO_OP_REQUEST), context, remoteNotify.getId());
    }
    // check if default calendar is deleted, if yes, reset default calendar id
    Integer defaultCalId = mbox.getAccount().getPrefDefaultCalendarId();
    if (defaultCalId != null && (opStr.equals(MailConstants.OP_TRASH) || opStr.equals(MailConstants.OP_HARD_DELETE)) && result.mSuccessIds.contains(defaultCalId.toString())) {
        ZimbraLog.mailbox.info("Default calendar deleted, so setting default calendar back to \"Calendar\"");
        mbox.resetDefaultCalendarId();
    }
    return result;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) SoapProtocol(com.zimbra.common.soap.SoapProtocol) ArrayList(java.util.ArrayList) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 17 with Color

use of com.zimbra.common.mailbox.Color in project zm-mailbox by Zimbra.

the class ItemAction method getColor.

public static Color getColor(Element action) throws ServiceException {
    String rgb = action.getAttribute(MailConstants.A_RGB, null);
    byte c = (byte) action.getAttributeLong(MailConstants.A_COLOR, -1);
    if (rgb == null && c < 0) {
        // it will default to ORANGE
        return new Color(-1);
    } else if (rgb == null) {
        return new Color(c);
    } else {
        return new Color(rgb);
    }
}
Also used : Color(com.zimbra.common.mailbox.Color)

Example 18 with Color

use of com.zimbra.common.mailbox.Color in project zm-mailbox by Zimbra.

the class MailboxUpgrade method upgradeTo1_8.

/**
 * bug 41850: revert tag colors back to mapped value.
 */
public static void upgradeTo1_8(Mailbox mbox) throws ServiceException {
    OperationContext octxt = new OperationContext(mbox);
    for (Tag tag : mbox.getTagList(octxt)) {
        Color color = tag.getRgbColor();
        if (!color.hasMapping()) {
            Byte value = UPGRADE_TO_1_8_COLORS.get(color.getValue());
            if (value != null) {
                Color newcolor = new Color(value);
                mbox.setColor(octxt, new int[] { tag.getId() }, tag.getType(), newcolor);
            }
        }
    }
}
Also used : Color(com.zimbra.common.mailbox.Color) DbTag(com.zimbra.cs.db.DbTag)

Aggregations

Color (com.zimbra.common.mailbox.Color)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)11 Element (com.zimbra.common.soap.Element)9 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)9 OperationContext (com.zimbra.cs.mailbox.OperationContext)8 ItemId (com.zimbra.cs.service.util.ItemId)7 ServiceException (com.zimbra.common.service.ServiceException)5 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)5 HashMap (java.util.HashMap)5 Account (com.zimbra.cs.account.Account)4 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 ArrayList (java.util.ArrayList)4 ZMailbox (com.zimbra.client.ZMailbox)3 SoapProtocol (com.zimbra.common.soap.SoapProtocol)2 DbTag (com.zimbra.cs.db.DbTag)2 Folder (com.zimbra.cs.mailbox.Folder)2 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)2 UnderlyingData (com.zimbra.cs.mailbox.MailItem.UnderlyingData)2 Metadata (com.zimbra.cs.mailbox.Metadata)2 ParsedContact (com.zimbra.cs.mime.ParsedContact)2