Search in sources :

Example 11 with ZTag

use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doGetAllTags.

private void doGetAllTags() throws ServiceException {
    if (verboseOpt()) {
        StringBuilder sb = new StringBuilder();
        for (String tagName : mMbox.getAllTagNames()) {
            ZTag tag = mMbox.getTagByName(tagName);
            if (sb.length() > 0)
                sb.append(",\n");
            sb.append(tag.dump());
        }
        stdout.format("[%n%s%n]%n", sb.toString());
    } else {
        if (mMbox.getAllTagNames().size() == 0)
            return;
        String hdrFormat = "%10.10s  %10.10s  %10.10s  %s%n";
        stdout.format(hdrFormat, "Id", "Unread", "Color", "Name");
        stdout.format(hdrFormat, "----------", "----------", "----------", "----------");
        for (String tagName : mMbox.getAllTagNames()) {
            ZTag tag = mMbox.getTagByName(tagName);
            stdout.format("%10.10s  %10d  %10.10s  %s%n", tag.getId(), tag.getUnreadCount(), tag.getColor().name(), tag.getName());
        }
    }
}
Also used : ZTag(com.zimbra.client.ZTag)

Example 12 with ZTag

use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.

the class TestFilter method testBase64Subject.

/**
     * Confirms that a message with a base64-encoded subject can be filtered correctly
     * (bug 11219).
     */
public void testBase64Subject() throws Exception {
    // if subject contains "Cortes de luz", tag with testBase64Subject and stop
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "Cortes de luz"));
    actions.add(new ZTagAction(TAG1_NAME));
    rules.add(new ZFilterRule("testBase64Subject", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    String address = TestUtil.getAddress(USER_NAME);
    TestUtil.addMessageLmtp("=?UTF-8?B?W2l0dnNmLUluY2lkZW5jaWFzXVs0OTc3Ml0gW2luY2lkZW5jaWFzLXZpbGxhbnVldmFdIENvcnRlcyBkZSBsdXosIGTDrWEgMjUvMDkvMjAwNi4=?=", address, address);
    List<ZMessage> messages = TestUtil.search(mMbox, "Cortes de luz");
    assertEquals("Unexpected number of messages", 1, messages.size());
    List<ZTag> tags = mMbox.getTags(messages.get(0).getTagIds());
    assertEquals("Unexpected number of tags", 1, tags.size());
    assertEquals("Tag didn't match", TAG1_NAME, tags.get(0).getName());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZTag(com.zimbra.client.ZTag) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 13 with ZTag

use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.

the class TestImap method testStoreTags.

@Test
public void testStoreTags() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    ZTag tag = mbox.getTag(tagName);
    if (tag == null) {
        tag = mbox.createTag(tagName, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo2"), true);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(2, data.size());
    Iterator<Long> it = data.keySet().iterator();
    Long seq = it.next();
    assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
    seq = it.next();
    assertFalse("flag unexpectedly set on second message", data.get(seq).getFlags().isSet(tagName));
    connection.store(seq + "", "+FLAGS", tagName);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE in INBOX", data.get(seq).getFlags().isSet(tagName));
    mbox.addMessage(folder.getId(), "u", "", System.currentTimeMillis(), simpleMessage("bar"), true);
    info = connection.select(folderName);
    assertFalse(folderName + " contains unexpected flag " + tagName, info.getFlags().isSet(tagName));
    data = connection.fetch("*", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertFalse("flag unexpectedly set on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    connection.store(seq + "", "+FLAGS", tagName);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    info = connection.select(folderName);
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    String tagName2 = "T2";
    connection.store(seq + "", "+FLAGS", tagName2);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
    info = connection.select(folderName);
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName2));
    //should not have created T2 as a visible tag
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String tagName3 = "T3";
    connection.store(seq + "", "FLAGS", tagName3);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName3));
    info = connection.select(folderName);
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName3));
    assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName));
    assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
    //should not have created T2 or T3 as a visible tag
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    connection.store(seq + "", "-FLAGS", tagName3);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flags unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isEmpty());
    info = connection.select("INBOX");
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZTag(com.zimbra.client.ZTag) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 14 with ZTag

use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.

the class TestUtil method deleteTestData.

/**
     * Delete all messages, tags and folders in the user's mailbox whose subjects contain the given substring. For
     * messages, the subject must contain subjectString as a separate word. Tags and folders can have the string
     * anywhere in the name.
     */
public static void deleteTestData(String userName, String subjectSubstring) throws ServiceException {
    ZMailbox mbox = getZMailbox(userName);
    deleteMessages(mbox, "is:anywhere " + subjectSubstring);
    // Workaround for bug 15160 (is:anywhere is busted)
    deleteMessages(mbox, "in:trash " + subjectSubstring);
    deleteMessages(mbox, "in:junk " + subjectSubstring);
    deleteMessages(mbox, "in:sent " + subjectSubstring);
    // Workaround for bug 31370
    deleteMessages(mbox, "subject: " + subjectSubstring);
    // Delete tags
    for (ZTag tag : mbox.getAllTags()) {
        if (tag.getName().contains(subjectSubstring)) {
            mbox.deleteTag(tag.getId());
        }
    }
    // Delete folders
    for (ZFolder folder : mbox.getAllFolders()) {
        if (folder.getName().contains(subjectSubstring)) {
            mbox.deleteFolder(folder.getId());
        }
    }
    // Delete contacts
    for (ZContact contact : mbox.getAllContacts(null, ContactSortBy.nameAsc, false, null)) {
        String fullName = contact.getAttrs().get("fullName");
        if (fullName != null && fullName.contains(subjectSubstring)) {
            mbox.deleteContact(contact.getId());
        }
    }
    // Delete data sources
    List<ZDataSource> dataSources = mbox.getAllDataSources();
    for (ZDataSource ds : dataSources) {
        if (ds.getName().contains(subjectSubstring)) {
            mbox.deleteDataSource(ds);
        }
    }
    // Delete appointments
    List<String> ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_APPOINTMENT);
    if (!ids.isEmpty()) {
        mbox.deleteItem(StringUtil.join(",", ids), null);
    }
    // Delete documents
    ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_DOCUMENT);
    if (!ids.isEmpty()) {
        mbox.deleteItem(StringUtil.join(",", ids), null);
    }
    ZMailbox adminMbox = getZMailboxAsAdmin(userName);
    adminMbox.emptyDumpster();
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZTag(com.zimbra.client.ZTag) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) ZContact(com.zimbra.client.ZContact)

Example 15 with ZTag

use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.

the class TestUtil method verifyTag.

/**
     * Verifies that a message is tagged.
     */
public static void verifyTag(ZMailbox mbox, ZMessage msg, String tagName) throws Exception {
    List<ZTag> tags = mbox.getTags(msg.getTagIds());
    for (ZTag tag : tags) {
        if (tag.getName().equals(tagName)) {
            return;
        }
    }
    Assert.fail("Message not tagged with " + tagName);
}
Also used : ZTag(com.zimbra.client.ZTag)

Aggregations

ZTag (com.zimbra.client.ZTag)15 ZMailbox (com.zimbra.client.ZMailbox)8 Test (org.junit.Test)8 ZMessage (com.zimbra.client.ZMessage)5 ZFilterAction (com.zimbra.client.ZFilterAction)4 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)4 ZFilterCondition (com.zimbra.client.ZFilterCondition)4 ZFilterRule (com.zimbra.client.ZFilterRule)4 ZFilterRules (com.zimbra.client.ZFilterRules)4 ZFolder (com.zimbra.client.ZFolder)4 ArrayList (java.util.ArrayList)4 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)3 MessageData (com.zimbra.cs.mailclient.imap.MessageData)3 Flags (com.zimbra.cs.mailclient.imap.Flags)2 Date (java.util.Date)2 ZContact (com.zimbra.client.ZContact)1 ZDataSource (com.zimbra.client.ZDataSource)1 ZAttachmentExistsCondition (com.zimbra.client.ZFilterCondition.ZAttachmentExistsCondition)1 ZDateCondition (com.zimbra.client.ZFilterCondition.ZDateCondition)1 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)1