use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class ImapSession method handleModify.
private void handleModify(int changeId, Change chg, AddedItems added) {
if (chg.what instanceof Tag && (chg.why & Change.NAME) != 0) {
mFolder.handleTagRename(changeId, (Tag) chg.what, chg);
} else if (chg.what instanceof Folder && ((Folder) chg.what).getId() == mFolderId) {
Folder folder = (Folder) chg.what;
if ((chg.why & Change.FLAGS) != 0 && (folder.getFlagBitmask() & Flag.BITMASK_DELETED) != 0) {
// mailbox accessed by sending a untagged BYE response."
if (handler != null) {
handler.close();
}
} else if ((chg.why & (Change.FOLDER | Change.NAME)) != 0) {
mFolder.handleFolderRename(changeId, folder, chg);
}
} else if (chg.what instanceof Message || chg.what instanceof Contact) {
MailItem item = (MailItem) chg.what;
boolean inFolder = mIsVirtual || item.getFolderId() == mFolderId;
if (!inFolder && (chg.why & Change.FOLDER) == 0) {
return;
}
mFolder.handleItemUpdate(changeId, chg, added);
}
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class FilterListener method notify.
@Override
public void notify(ChangeNotification notification) {
if (notification.mods.modified != null && EVENTS.contains(notification.op)) {
for (PendingModifications.Change change : notification.mods.modified.values()) {
if (change.what instanceof Folder) {
if ((change.why & Change.PARENT) == 0 && (change.why & Change.NAME) == 0) {
continue;
}
Folder folder = (Folder) change.what;
Folder oldFolder = (Folder) change.preModifyObj;
if (oldFolder == null) {
ZimbraLog.filter.warn("Cannot determine the old folder name for %s.", folder.getName());
continue;
}
updateFilterRules(notification.mailboxAccount, folder, oldFolder.getPath());
} else if (change.what instanceof Tag) {
if ((change.why & Change.NAME) == 0) {
continue;
}
Tag tag = (Tag) change.what;
Tag oldTag = (Tag) change.preModifyObj;
if (oldTag == null) {
ZimbraLog.filter.warn("Cannot determine the old tag name for %s.", tag.getName());
continue;
}
updateFilterRules(notification.mailboxAccount, tag, oldTag.getName());
}
}
}
if (notification.mods.deleted != null) {
for (Map.Entry<ModificationKey, Change> entry : notification.mods.deleted.entrySet()) {
MailItem.Type type = (MailItem.Type) entry.getValue().what;
if (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT) {
Folder oldFolder = (Folder) entry.getValue().preModifyObj;
if (oldFolder == null) {
ZimbraLog.filter.warn("Cannot determine the old folder name for %s.", entry.getKey());
continue;
}
updateFilterRules(notification.mailboxAccount, (Folder) null, oldFolder.getPath());
} else if (type == MailItem.Type.TAG) {
Tag oldTag = (Tag) entry.getValue().preModifyObj;
updateFilterRules(notification.mailboxAccount, oldTag);
}
}
}
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class SetRetentionPolicyTest method redoTag.
/**
* Verifies serializing, deserializing, and replaying for tag.
*/
@Test
public void redoTag() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
// Create folder.
Tag tag = mbox.createTag(null, "tag", (byte) 0);
assertEquals(0, tag.getRetentionPolicy().getKeepPolicy().size());
assertEquals(0, tag.getRetentionPolicy().getPurgePolicy().size());
// Create RedoableOp.
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy("123")), Arrays.asList(Policy.newUserPolicy("45m")));
SetRetentionPolicy redoPlayer = new SetRetentionPolicy(mbox.getId(), MailItem.Type.TAG, tag.getId(), rp);
// Serialize, deserialize, and redo.
byte[] data = redoPlayer.testSerialize();
redoPlayer = new SetRetentionPolicy();
redoPlayer.setMailboxId(mbox.getId());
redoPlayer.testDeserialize(data);
redoPlayer.redo();
tag = mbox.getTagById(null, tag.getId());
assertEquals(1, tag.getRetentionPolicy().getKeepPolicy().size());
assertEquals(1, tag.getRetentionPolicy().getPurgePolicy().size());
assertEquals("45m", tag.getRetentionPolicy().getPurgePolicy().get(0).getLifetime());
assertEquals("123", tag.getRetentionPolicy().getKeepPolicy().get(0).getId());
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class TagActionTest method permissions.
@Test
public void permissions() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Tag tag1 = mbox.createTag(null, name1, (byte) 0);
Element request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
Element action = request.addElement(MailConstants.E_ACTION);
action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_COLOR).addAttribute(MailConstants.A_COLOR, 4);
action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name1));
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
action.addAttribute(MailConstants.A_TAG_NAMES, (String) null).addAttribute(MailConstants.A_ID, tag1.getId());
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name2));
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class DbMailItem method getUnreadMessages.
public static List<UnderlyingData> getUnreadMessages(MailItem relativeTo) throws ServiceException {
if (relativeTo instanceof Tag) {
return DbTag.getUnreadMessages((Tag) relativeTo);
}
Mailbox mbox = relativeTo.getMailbox();
ArrayList<UnderlyingData> result = new ArrayList<UnderlyingData>();
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String relation;
if (relativeTo instanceof VirtualConversation) {
relation = "id = ?";
} else if (relativeTo instanceof Conversation) {
relation = "parent_id = ?";
} else if (relativeTo instanceof Folder) {
relation = "folder_id = ?";
} else {
relation = "id = ?";
}
stmt = conn.prepareStatement("SELECT " + DB_FIELDS + " FROM " + getMailItemTableName(relativeTo.getMailbox(), " mi") + " WHERE " + IN_THIS_MAILBOX_AND + "unread > 0 AND " + relation + " AND type NOT IN " + NON_SEARCHABLE_TYPES);
if (relativeTo.getUnreadCount() > RESULTS_STREAMING_MIN_ROWS) {
Db.getInstance().enableStreaming(stmt);
}
int pos = 1;
pos = setMailboxId(stmt, mbox, pos);
if (relativeTo instanceof VirtualConversation) {
stmt.setInt(pos++, ((VirtualConversation) relativeTo).getMessageId());
} else {
stmt.setInt(pos++, relativeTo.getId());
}
rs = stmt.executeQuery();
while (rs.next()) {
UnderlyingData data = constructItem(rs);
if (Mailbox.isCachedType(MailItem.Type.of(data.type))) {
throw ServiceException.INVALID_REQUEST("folders and tags must be retrieved from cache", null);
}
result.add(data);
}
return result;
} catch (SQLException e) {
throw ServiceException.FAILURE("fetching unread messages for item " + relativeTo.getId(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
Aggregations