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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations