Search in sources :

Example 1 with Tag

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);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Message(com.zimbra.cs.mailbox.Message) DirtyMessage(com.zimbra.cs.imap.ImapFolder.DirtyMessage) Tag(com.zimbra.cs.mailbox.Tag) Folder(com.zimbra.cs.mailbox.Folder) Contact(com.zimbra.cs.mailbox.Contact)

Example 2 with Tag

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);
            }
        }
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) PendingModifications(com.zimbra.cs.session.PendingModifications) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) Tag(com.zimbra.cs.mailbox.Tag) Change(com.zimbra.cs.session.PendingModifications.Change) Folder(com.zimbra.cs.mailbox.Folder) Map(java.util.Map)

Example 3 with Tag

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());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Tag(com.zimbra.cs.mailbox.Tag) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 4 with Tag

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());
    }
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Element(com.zimbra.common.soap.Element) Tag(com.zimbra.cs.mailbox.Tag) Test(org.junit.Test)

Example 5 with Tag

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);
    }
}
Also used : SQLException(java.sql.SQLException) UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) VirtualConversation(com.zimbra.cs.mailbox.VirtualConversation) Conversation(com.zimbra.cs.mailbox.Conversation) Folder(com.zimbra.cs.mailbox.Folder) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) Mailbox(com.zimbra.cs.mailbox.Mailbox) ResultSet(java.sql.ResultSet) Tag(com.zimbra.cs.mailbox.Tag) VirtualConversation(com.zimbra.cs.mailbox.VirtualConversation)

Aggregations

Tag (com.zimbra.cs.mailbox.Tag)26 Mailbox (com.zimbra.cs.mailbox.Mailbox)13 Folder (com.zimbra.cs.mailbox.Folder)10 Test (org.junit.Test)10 Element (com.zimbra.common.soap.Element)8 Account (com.zimbra.cs.account.Account)7 MailItem (com.zimbra.cs.mailbox.MailItem)7 ServiceException (com.zimbra.common.service.ServiceException)6 OperationContext (com.zimbra.cs.mailbox.OperationContext)6 Message (com.zimbra.cs.mailbox.Message)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 ArrayList (java.util.ArrayList)4 Flag (com.zimbra.cs.mailbox.Flag)3 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)3 ItemId (com.zimbra.cs.service.util.ItemId)3 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)3 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)2 Contact (com.zimbra.cs.mailbox.Contact)2 Conversation (com.zimbra.cs.mailbox.Conversation)2 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)2