Search in sources :

Example 1 with SetItemTags

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);
    }
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) SetItemTags(com.zimbra.cs.redolog.op.SetItemTags) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Aggregations

DbMailItem (com.zimbra.cs.db.DbMailItem)1 DbTag (com.zimbra.cs.db.DbTag)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 NormalizedTags (com.zimbra.cs.mailbox.Tag.NormalizedTags)1 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 CreateTag (com.zimbra.cs.redolog.op.CreateTag)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 SetItemTags (com.zimbra.cs.redolog.op.SetItemTags)1