use of com.zimbra.cs.redolog.op.SetItemTags 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);
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);
}
}
Aggregations