Search in sources :

Example 6 with Color

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

the class CreateMountpoint method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    Element t = request.getElement(MailConstants.E_MOUNT);
    String name = t.getAttribute(MailConstants.A_NAME);
    String view = t.getAttribute(MailConstants.A_DEFAULT_VIEW, null);
    String flags = t.getAttribute(MailConstants.A_FLAGS, null);
    byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
    String rgb = t.getAttribute(MailConstants.A_RGB, null);
    ItemId iidParent = new ItemId(t.getAttribute(MailConstants.A_FOLDER), zsc);
    boolean fetchIfExists = t.getAttributeBool(MailConstants.A_FETCH_IF_EXISTS, false);
    boolean reminderEnabled = t.getAttributeBool(MailConstants.A_REMINDER, false);
    Account target = null;
    String ownerId = t.getAttribute(MailConstants.A_ZIMBRA_ID, null);
    if (ownerId == null) {
        String ownerName = t.getAttribute(MailConstants.A_OWNER_NAME);
        target = Provisioning.getInstance().get(AccountBy.name, ownerName, zsc.getAuthToken());
        // prevent directory harvest attack, mask no such account as permission denied
        if (target == null)
            throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
        ownerId = target.getId();
        if (ownerId.equalsIgnoreCase(zsc.getRequestedAccountId()))
            throw ServiceException.INVALID_REQUEST("cannot mount your own folder", null);
    }
    Element remote = fetchRemoteFolder(zsc, context, ownerId, (int) t.getAttributeLong(MailConstants.A_REMOTE_ID, -1), t.getAttribute(MailConstants.A_PATH, null));
    int remoteId = new ItemId(remote.getAttribute(MailConstants.A_ID), zsc).getId();
    String remoteUuid = remote.getAttribute(MailConstants.A_UUID, null);
    if (view == null)
        view = remote.getAttribute(MailConstants.A_DEFAULT_VIEW, null);
    Mountpoint mpt;
    try {
        Color itemColor = rgb != null ? new Color(rgb) : new Color(color);
        mpt = mbox.createMountpoint(octxt, iidParent.getId(), name, ownerId, remoteId, remoteUuid, MailItem.Type.of(view), Flag.toBitmask(flags), itemColor, reminderEnabled);
    } catch (ServiceException se) {
        if (se.getCode() == MailServiceException.ALREADY_EXISTS && fetchIfExists) {
            Folder folder = mbox.getFolderByName(octxt, iidParent.getId(), name);
            if (folder instanceof Mountpoint)
                mpt = (Mountpoint) folder;
            else
                throw se;
        } else {
            throw se;
        }
    }
    Element response = zsc.createElement(MailConstants.CREATE_MOUNTPOINT_RESPONSE);
    if (mpt != null) {
        Element eMount = ToXML.encodeMountpoint(response, ifmt, octxt, mpt);
        // transfer folder counts and subfolders to the serialized mountpoint from the serialized target folder
        ToXML.transferMountpointContents(eMount, remote);
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 7 with Color

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

the class CreateTag method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    Element t = request.getElement(MailConstants.E_TAG);
    String name = t.getAttribute(MailConstants.A_NAME);
    String rgb = t.getAttribute(MailConstants.A_RGB, null);
    Tag tag;
    if (rgb != null) {
        Color color = new Color(rgb);
        tag = mbox.createTag(octxt, name, color);
    } else {
        byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
        tag = mbox.createTag(octxt, name, color);
    }
    Element response = zsc.createElement(MailConstants.CREATE_TAG_RESPONSE);
    if (tag != null)
        ToXML.encodeTag(response, ifmt, octxt, tag);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) Tag(com.zimbra.cs.mailbox.Tag)

Example 8 with Color

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

the class ItemAction method handleCommon.

protected String handleCommon(Map<String, Object> context, Element request, String opAttr, 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 = !opAttr.startsWith("!");
    String opStr = getOperation(opAttr);
    // 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 "";
    }
    // 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
    StringBuilder successes = 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);
        String localResults;
        // set additional parameters (depends on op type)
        if (opStr.equals(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(OP_FLAG)) {
            localResults = ItemActionHelper.FLAG(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(OP_PRIORITY)) {
            localResults = ItemActionHelper.PRIORITY(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(OP_READ)) {
            localResults = ItemActionHelper.READ(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
        } else if (opStr.equals(OP_COLOR)) {
            Color color = getColor(action);
            localResults = ItemActionHelper.COLOR(octxt, mbox, responseProto, local, type, tcon, color).getResult();
        } else if (opStr.equals(OP_HARD_DELETE)) {
            localResults = ItemActionHelper.HARD_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(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(OP_DUMPSTER_DELETE)) {
            localResults = ItemActionHelper.DUMPSTER_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(OP_TRASH)) {
            localResults = handleTrashOperation(octxt, request, mbox, responseProto, local, type, tcon);
        } else if (opStr.equals(OP_MOVE)) {
            localResults = handleMoveOperation(zsc, octxt, request, action, mbox, responseProto, local, type, tcon);
        } else if (opStr.equals(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(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(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(OP_UPDATE)) {
            String folderId = action.getAttribute(MailConstants.A_FOLDER, null);
            ItemId iidFolder = new ItemId(folderId == null ? "-1" : folderId, zsc);
            if (!iidFolder.belongsTo(mbox)) {
                throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
            } else if (folderId != null && 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(OP_LOCK)) {
            localResults = ItemActionHelper.LOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(OP_UNLOCK)) {
            localResults = ItemActionHelper.UNLOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
        } else if (opStr.equals(OP_INHERIT)) {
            mbox.alterTag(octxt, ArrayUtil.toIntArray(local), type, Flag.FlagInfo.NO_INHERIT, false, tcon);
            localResults = Joiner.on(",").join(local);
        } else if (opStr.equals(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 {
            throw ServiceException.INVALID_REQUEST("unknown operation: " + opStr, null);
        }
        successes.append(successes.length() > 0 ? "," : "").append(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());
    }
    return successes.toString();
}
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 9 with Color

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

the class TagTest method itemDelete.

@Test
public void itemDelete() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // precreate some but not all of the tags
    mbox.createTag(null, tag2, (byte) 4);
    mbox.createTag(null, tag3, new Color(0x8800FF));
    DbTag.debugConsistencyCheck(mbox);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD).setTags(new String[] { tag1, tag2 });
    int msgId = mbox.addMessage(null, ThreaderTest.getRootMessage(), dopt, null).getId();
    checkThreeTagCounts("add an unread message", mbox, 1, 1, 1, 1, 0, 0);
    dopt.setFlags(0).setTags(new String[] { tag1, tag3 });
    int msgId2 = mbox.addMessage(null, new ParsedMessage(ThreaderTest.getSecondMessage(), false), dopt, null).getId();
    checkItemTags(mbox, msgId2, 0, tag1, tag3);
    checkThreeTagCounts("add a read message", mbox, 2, 1, 1, 1, 1, 0);
    mbox.delete(null, msgId, MailItem.Type.MESSAGE);
    checkThreeTagCounts("delete the unread message explicitly", mbox, 1, 0, 0, 0, 1, 0);
    mbox.emptyFolder(null, Mailbox.ID_FOLDER_INBOX, true);
    checkThreeTagCounts("delete the read message by emptying its folder", mbox, 0, 0, 0, 0, 0, 0);
    dopt.setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_DELETED).setTags(new String[] { tag1, tag2 });
    int msgId3 = mbox.addMessage(null, ThreaderTest.getRootMessage(), dopt, null).getId();
    checkItemTags(mbox, msgId3, Flag.BITMASK_UNREAD | Flag.BITMASK_DELETED, tag1, tag2);
    checkThreeTagCounts("add an unread \\Deleted message", mbox, 0, 0, 0, 0, 0, 0);
    dopt.setFlags(Flag.BITMASK_UNREAD).setTags(new String[] { tag1, tag3 });
    int msgId4 = mbox.addMessage(null, new ParsedMessage(ThreaderTest.getSecondMessage(), false), dopt, null).getId();
    checkItemTags(mbox, msgId4, Flag.BITMASK_UNREAD, tag1, tag3);
    checkThreeTagCounts("add an unread non-\\Deleted message", mbox, 1, 1, 0, 0, 1, 1);
    mbox.delete(null, msgId3, MailItem.Type.MESSAGE);
    checkThreeTagCounts("delete the unread \\Deleted message explicitly", mbox, 1, 1, 0, 0, 1, 1);
    mbox.alterTag(null, msgId4, MailItem.Type.MESSAGE, Flag.FlagInfo.DELETED, true, null);
    checkItemTags(mbox, msgId4, Flag.BITMASK_UNREAD | Flag.BITMASK_DELETED, tag1, tag3);
    checkThreeTagCounts("mark the remaining message as \\Deleted", mbox, 0, 0, 0, 0, 0, 0);
    mbox.emptyFolder(null, Mailbox.ID_FOLDER_INBOX, true);
    checkThreeTagCounts("delete that remaining message by emptying its folder", mbox, 0, 0, 0, 0, 0, 0);
    Message msg5 = mbox.addMessage(null, ThreaderTest.getRootMessage(), dopt, null);
    checkThreeTagCounts("add the conversation root", mbox, 1, 1, 0, 0, 1, 1);
    dopt.setConversationId(msg5.getConversationId()).setFlags(0);
    Message msg6 = mbox.addMessage(null, new ParsedMessage(ThreaderTest.getSecondMessage(), false), dopt, null);
    checkThreeTagCounts("add the conversation reply", mbox, 2, 1, 0, 0, 2, 1);
    mbox.setTags(null, msg6.getId(), MailItem.Type.MESSAGE, Flag.BITMASK_UNREAD, new String[] { tag2, tag3 });
    checkThreeTagCounts("retag reply and mark unread", mbox, 1, 1, 1, 1, 2, 2);
    mbox.alterTag(null, msg5.getId(), MailItem.Type.MESSAGE, Flag.FlagInfo.UNREAD, false, null);
    checkThreeTagCounts("mark root read", mbox, 1, 0, 1, 1, 2, 1);
    mbox.delete(null, msg6.getConversationId(), MailItem.Type.CONVERSATION);
    checkThreeTagCounts("delete the entire conversation", mbox, 0, 0, 0, 0, 0, 0);
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Color(com.zimbra.common.mailbox.Color) Test(org.junit.Test)

Example 10 with Color

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

the class TagTest method color.

@Test
public void color() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // color specified as byte
    Tag tag = mbox.createTag(null, tag1, (byte) 2);
    Assert.assertEquals("tag color 2", 2, tag.getColor());
    mbox.purge(MailItem.Type.TAG);
    tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals("tag color 2", 2, tag.getColor());
    DbTag.debugConsistencyCheck(mbox);
    // color specified as rgb
    Color color = new Color(0x668822);
    mbox.setColor(null, new int[] { tag.getId() }, MailItem.Type.TAG, color);
    tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals("tag color " + color, color, tag.getRgbColor());
    mbox.purge(MailItem.Type.TAG);
    tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals("tag color " + color, color, tag.getRgbColor());
    DbTag.debugConsistencyCheck(mbox);
    // color specified as default
    mbox.setColor(null, new int[] { tag.getId() }, MailItem.Type.TAG, MailItem.DEFAULT_COLOR_RGB);
    tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals("default tag color", MailItem.DEFAULT_COLOR, tag.getColor());
    Assert.assertEquals("default tag color", MailItem.DEFAULT_COLOR_RGB, tag.getRgbColor());
    mbox.purge(MailItem.Type.TAG);
    tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals("default tag color", MailItem.DEFAULT_COLOR, tag.getColor());
    Assert.assertEquals("default tag color", MailItem.DEFAULT_COLOR_RGB, tag.getRgbColor());
    DbTag.debugConsistencyCheck(mbox);
}
Also used : Color(com.zimbra.common.mailbox.Color) DbTag(com.zimbra.cs.db.DbTag) Test(org.junit.Test)

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