Search in sources :

Example 11 with Color

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

the class DbTag method saveMetadata.

public static void saveMetadata(Tag tag) throws ServiceException {
    Mailbox mbox = tag.getMailbox();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    try {
        stmt = conn.prepareStatement("UPDATE " + getTagTableName(mbox) + " SET color = ?, policy = ?, listed = ?, sequence = ? WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "id = ?");
        int pos = 1;
        Color color = tag.getRgbColor();
        if (color != null && color.getMappedColor() != MailItem.DEFAULT_COLOR) {
            stmt.setLong(pos++, color.getValue());
        } else {
            stmt.setNull(pos++, Types.BIGINT);
        }
        RetentionPolicy rp = tag.getRetentionPolicy();
        if (rp != null && rp.isSet()) {
            stmt.setString(pos++, RetentionPolicyManager.toMetadata(rp, true).toString());
        } else {
            stmt.setNull(pos++, Types.VARCHAR);
        }
        stmt.setBoolean(pos++, tag.isListed());
        stmt.setInt(pos++, tag.getModifiedSequence());
        pos = DbMailItem.setMailboxId(stmt, mbox, pos);
        stmt.setInt(pos++, tag.getId());
        stmt.executeUpdate();
    } catch (SQLException e) {
        throw ServiceException.FAILURE("updating counts for tag " + tag.getName(), e);
    } finally {
        DbPool.closeStatement(stmt);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) SQLException(java.sql.SQLException) Color(com.zimbra.common.mailbox.Color) PreparedStatement(java.sql.PreparedStatement) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 12 with Color

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

the class DbTag method asUnderlyingData.

private static UnderlyingData asUnderlyingData(ResultSet rs) throws SQLException, ServiceException {
    UnderlyingData data = new UnderlyingData();
    data.id = rs.getInt(1);
    data.type = MailItem.Type.TAG.toByte();
    data.folderId = Mailbox.ID_FOLDER_TAGS;
    data.name = rs.getString(2);
    data.size = rs.getInt(4);
    data.unreadCount = rs.getInt(5);
    boolean listed = rs.getBoolean(6);
    String policy = rs.getString(8);
    RetentionPolicy rp = policy == null ? null : RetentionPolicyManager.retentionPolicyFromMetadata(new Metadata(policy), true);
    long c = rs.getLong(3);
    Color color = rs.wasNull() ? null : Color.fromMetadata(c);
    // FIXME: if Tag weren't a subclass of MailItem, this step wouldn't be necessary
    data.metadata = Tag.encodeMetadata(color, 1, 1, rp, listed);
    data.modMetadata = rs.getInt(7);
    data.modContent = data.modMetadata;
    return data;
}
Also used : UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) Color(com.zimbra.common.mailbox.Color) Metadata(com.zimbra.cs.mailbox.Metadata) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 13 with Color

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

the class ContactAction method handleContact.

private ItemActionResult handleContact(Map<String, Object> context, Element request, String operation) throws ServiceException, SoapFaultException {
    Element action = request.getElement(MailConstants.E_ACTION);
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    // figure out which items are local and which ones are remote, and proxy accordingly
    ArrayList<Integer> local = new ArrayList<Integer>();
    HashMap<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
    partitionItems(zsc, action.getAttribute(MailConstants.A_ID), local, remote);
    ItemActionResult successes = proxyRemoteItems(action, remote, request, context);
    if (!local.isEmpty()) {
        ItemActionResult localResults;
        if (operation.equals(OP_UPDATE)) {
            // duplicating code from ItemAction.java for now...
            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 flags = action.getAttribute(MailConstants.A_FLAGS, null);
            String[] tags = TagUtil.parseTags(action, mbox, octxt);
            Color color = getColor(action);
            ParsedContact pc = null;
            if (!action.listElements(MailConstants.E_ATTRIBUTE).isEmpty()) {
                Contact cn = local.size() == 1 ? mbox.getContactById(octxt, local.get(0)) : null;
                Pair<Map<String, Object>, List<Attachment>> cdata = CreateContact.parseContact(action, zsc, octxt, cn);
                pc = new ParsedContact(cdata.getFirst(), cdata.getSecond());
            }
            localResults = ContactActionHelper.UPDATE(zsc, octxt, mbox, local, iidFolder, flags, tags, color, pc).getResult();
        } else {
            throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
        }
        successes.appendSuccessIds(localResults.getSuccessIds());
    }
    return successes;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) ArrayList(java.util.ArrayList) ItemId(com.zimbra.cs.service.util.ItemId) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Color

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

the class CreateFolder 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_FOLDER);
    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);
    String url = t.getAttribute(MailConstants.A_URL, null);
    String folderId = t.getAttribute(MailConstants.A_FOLDER, null);
    ItemId iidParent = folderId != null ? new ItemId(folderId, zsc) : null;
    boolean fetchIfExists = t.getAttributeBool(MailConstants.A_FETCH_IF_EXISTS, false);
    boolean syncToUrl = t.getAttributeBool(MailConstants.A_SYNC, true);
    ACL acl = FolderAction.parseACL(t.getOptionalElement(MailConstants.E_ACL), MailItem.Type.of(view), mbox.getAccount());
    Folder folder;
    boolean alreadyExisted = false;
    try {
        Folder.FolderOptions fopt = new Folder.FolderOptions();
        fopt.setColor(rgb != null ? new Color(rgb) : new Color(color)).setUrl(url);
        fopt.setDefaultView(MailItem.Type.of(view)).setFlags(Flag.toBitmask(flags));
        if (iidParent != null) {
            folder = mbox.createFolder(octxt, name, iidParent.getId(), fopt);
        } else {
            folder = mbox.createFolder(octxt, name, fopt);
        }
        if (!folder.getUrl().equals("") && syncToUrl) {
            try {
                mbox.synchronizeFolder(octxt, folder.getId());
            } catch (ServiceException e) {
                // if the synchronization fails, roll back the folder create
                rollbackFolder(folder);
                throw e;
            } catch (RuntimeException e) {
                // if the synchronization fails, roll back the folder create
                rollbackFolder(folder);
                throw ServiceException.FAILURE("could not synchronize with remote feed", e);
            }
        }
    } catch (ServiceException se) {
        if (se.getCode() == MailServiceException.ALREADY_EXISTS && fetchIfExists) {
            if (iidParent != null) {
                folder = mbox.getFolderByName(octxt, iidParent.getId(), name);
            } else {
                folder = mbox.getFolderByPath(octxt, name);
            }
            alreadyExisted = true;
        } else {
            throw se;
        }
    }
    // set the folder ACL as a separate operation, when appropriate
    if (acl != null && !alreadyExisted) {
        try {
            mbox.setPermissions(octxt, folder.getId(), acl);
        } catch (ServiceException e) {
            try {
                // roll back folder creation
                mbox.delete(null, folder.getId(), MailItem.Type.FOLDER);
            } catch (ServiceException nse) {
                ZimbraLog.soap.warn("error ignored while rolling back folder create", nse);
            }
            throw e;
        }
    }
    Element response = zsc.createElement(MailConstants.CREATE_FOLDER_RESPONSE);
    if (folder != null)
        ToXML.encodeFolder(response, ifmt, octxt, folder);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) ACL(com.zimbra.cs.mailbox.ACL) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 15 with Color

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

the class CreateSearchFolder 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);
    CreateSearchFolderRequest req = zsc.elementToJaxb(request);
    NewSearchFolderSpec spec = req.getSearchFolder();
    Byte color = spec.getColor() != null ? spec.getColor() : MailItem.DEFAULT_COLOR;
    Color itemColor = spec.getRgb() != null ? new Color(spec.getRgb()) : new Color(color);
    ItemId iidParent = new ItemId(spec.getParentFolderId(), zsc);
    SearchFolder search = mbox.createSearchFolder(octxt, iidParent.getId(), spec.getName(), spec.getQuery(), spec.getSearchTypes(), spec.getSortBy(), Flag.toBitmask(spec.getFlags()), itemColor);
    Element response = zsc.createElement(MailConstants.CREATE_SEARCH_FOLDER_RESPONSE);
    if (search != null)
        ToXML.encodeSearchFolder(response, ifmt, search);
    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) Color(com.zimbra.common.mailbox.Color) Element(com.zimbra.common.soap.Element) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) CreateSearchFolderRequest(com.zimbra.soap.mail.message.CreateSearchFolderRequest) ItemId(com.zimbra.cs.service.util.ItemId) NewSearchFolderSpec(com.zimbra.soap.mail.type.NewSearchFolderSpec)

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