use of com.zimbra.cs.mailbox.MailItem.TargetConstraint 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();
}
use of com.zimbra.cs.mailbox.MailItem.TargetConstraint in project zm-mailbox by Zimbra.
the class SetItemTags method redo.
@Override
public void redo() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
OperationContext octxt = getOperationContext();
if (mTags == null && mTagBitmask != 0) {
mTags = TagUtil.tagBitmaskToNames(mbox, octxt, mTagBitmask);
}
TargetConstraint tcon = null;
if (mConstraint != null) {
try {
tcon = TargetConstraint.parseConstraint(mbox, mConstraint);
} catch (ServiceException e) {
mLog.warn(e);
}
}
mbox.setTags(octxt, mIds, type, mFlags, mTags, tcon);
}
use of com.zimbra.cs.mailbox.MailItem.TargetConstraint in project zm-mailbox by Zimbra.
the class MoveItem method redo.
@Override
public void redo() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
TargetConstraint tcon = null;
if (mConstraint != null)
try {
tcon = TargetConstraint.parseConstraint(mbox, mConstraint);
} catch (ServiceException e) {
mLog.warn(e);
}
// No extra checking needed because Mailbox.move() is already idempotent.
mbox.move(getOperationContext(), mIds, type, mDestId, tcon);
}
use of com.zimbra.cs.mailbox.MailItem.TargetConstraint in project zm-mailbox by Zimbra.
the class Mailbox method setTags.
public void setTags(OperationContext octxt, int[] itemIds, MailItem.Type type, int flags, String[] tags, TargetConstraint tcon) throws ServiceException {
if (flags == MailItem.FLAG_UNCHANGED && tags == MailItem.TAG_UNCHANGED) {
return;
}
SetItemTags redoRecorder = new SetItemTags(mId, itemIds, type, flags, tags, tcon);
boolean success = false;
try {
beginTransaction("setTags", octxt, redoRecorder);
setOperationTargetConstraint(tcon);
MailItem[] items = getItemById(itemIds, type);
for (MailItem item : items) {
checkItemChangeID(item);
}
Flag unreadFlag = getFlagById(Flag.ID_UNREAD);
Tag.NormalizedTags ntags = tags == MailItem.TAG_UNCHANGED ? null : new Tag.NormalizedTags(this, tags, true, true);
for (MailItem item : items) {
if (item == null) {
continue;
}
int iflags = flags;
Tag.NormalizedTags itags = ntags;
if ((iflags & MailItem.FLAG_UNCHANGED) != 0) {
iflags = item.getFlagBitmask();
}
if (itags == null) {
itags = new Tag.NormalizedTags(item.getTags());
}
// special-case "unread" -- it's passed in with the flags, but the server process it separately
boolean iunread = (iflags & Flag.BITMASK_UNREAD) > 0;
iflags &= ~Flag.BITMASK_UNREAD;
item.setTags(iflags, itags);
if (unreadFlag.canTag(item)) {
item.alterUnread(iunread);
}
}
success = true;
} finally {
endTransaction(success);
}
}
use of com.zimbra.cs.mailbox.MailItem.TargetConstraint in project zm-mailbox by Zimbra.
the class Mailbox method trainSpamFilter.
private <T extends MailItem> T trainSpamFilter(OperationContext octxt, T item, Folder target, String opDescription) {
if (currentChange().getRedoPlayer() != null) {
// on replayed operation
return item;
}
TargetConstraint tcon = getOperationTargetConstraint();
try {
List<? extends MailItem> items = item instanceof Conversation ? ((Conversation) item).getMessages() : Arrays.asList((MailItem) item);
List<Folder> trashAliases = getTrashAliases(octxt);
for (MailItem candidate : items) {
// if it's not a move into or out of Spam, no training is necessary
// (moves from Spam to Trash also do not train the filter)
boolean fromSpam = candidate.inSpam();
boolean toSpam = target.inSpam();
if (!fromSpam && !toSpam) {
continue;
}
if (fromSpam && (toSpam || target.inTrash() || inFolder(trashAliases, target))) {
continue;
}
if (!TargetConstraint.checkItem(tcon, item) || !item.canAccess(ACL.RIGHT_READ)) {
continue;
}
try {
SpamReport report = new SpamReport(toSpam, opDescription, target.getPath());
Folder source = item.getFolder();
if (!source.equals(target)) {
report.setSourceFolderPath(source.getPath());
}
SpamHandler.getInstance().handle(octxt, this, candidate.getId(), candidate.getType(), report);
} catch (Exception e) {
ZimbraLog.mailop.info("could not train spam filter: " + MailItem.getMailopContext(candidate), e);
}
}
} catch (ServiceException e) {
ZimbraLog.mailop.info("could not train spam filter: " + MailItem.getMailopContext(item), e);
}
return item;
}
Aggregations