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());
}
}
}
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());
}
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));
}
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();
}
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);
}
Aggregations