use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestImap method testStoreTagsDirty.
@Test
public void testStoreTagsDirty() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
final String tagName2 = "T2";
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);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(1, 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));
ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
req.setResponseHandler(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
Flags flags = (Flags) res.getData();
assertTrue(flags.isSet(tagName2));
}
}
});
req.sendCheckStatus();
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestPurge method testTagRetentionPolicy.
@Test
public void testTagRetentionPolicy() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZTag tag = mbox.createTag(NAME_PREFIX + "-testTagRetentionPolicy", null);
// Set user keep policy for folder.
TagActionSelector action = new TagActionSelector(tag.getId(), "retentionpolicy");
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
action.setRetentionPolicy(rp);
TagActionRequest req = new TagActionRequest(action);
TagActionResponse res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
// Make sure that the retention policy is now set.
tag = mbox.getTagById(tag.getId());
rp = tag.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(0, rp.getPurgePolicy().size());
Policy p = rp.getKeepPolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("30d", p.getLifetime());
// Turn off keep policy and set purge policy.
action = new TagActionSelector(tag.getId(), "retentionpolicy");
rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
action.setRetentionPolicy(rp);
req = new TagActionRequest(action);
res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
// Make sure that the retention policy is now set.
tag = mbox.getTagById(tag.getId());
rp = tag.getRetentionPolicy();
Assert.assertEquals(0, rp.getKeepPolicy().size());
Assert.assertEquals(1, rp.getPurgePolicy().size());
p = rp.getPurgePolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("45d", p.getLifetime());
// Start a new session and make sure that the retention policy is still returned.
mbox = TestUtil.getZMailbox(USER_NAME);
tag = mbox.getTagById(tag.getId());
Assert.assertTrue(tag.getRetentionPolicy().isSet());
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestImap method testAppendTags.
@Test
public void testAppendTags() throws Exception {
Flags flags = Flags.fromSpec("afs");
//new tag; does not exist in mbox
String tag1 = "APPENDTAG1";
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag1));
} finally {
msg.dispose();
}
//should not have created a visible tag
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);
//now create a visible tag, add it to a message in inbox then try append to message in different folder
String tag2 = "APPENDTAG2";
ZTag tag = mbox.getTag(tag2);
if (tag == null) {
tag = mbox.createTag(tag2, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals(tag2, tags.get(0).getName());
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tag2, info.getFlags().isSet(tag2));
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
info = connection.select(folderName);
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));
msg = message(10);
flags = Flags.fromSpec("afs");
flags.set(tag2);
try {
AppendResult res = connection.append(folderName, flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag2));
} finally {
msg.dispose();
}
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestFilterExisting method testTag.
@Test
public void testTag() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZTag tag = mbox.createTag(TAG_NAME, null);
String subject = NAME_PREFIX + " test tag";
String id = TestUtil.addMessage(mbox, subject);
ZMessage msg = mbox.getMessageById(id);
// Run flag rule and make sure the message is not tagged.
Set<String> affectedIds = runRules(new String[] { FLAG_RULE_NAME }, id, null);
Assert.assertEquals(0, affectedIds.size());
Assert.assertFalse(msg.hasTags());
// Run tag rule and make sure the message is tagged.
affectedIds = runRules(new String[] { TAG_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(id));
mbox.noOp();
msg = mbox.getMessageById(id);
Assert.assertEquals(tag.getId(), msg.getTagIds());
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestFilter method testAttachment.
@Test
public void testAttachment() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// If attachment exists, set tag1. If attachment doesn't exist, set tag2.
ZTag tag1 = mMbox.createTag(NAME_PREFIX + " testAttachment1", null);
ZTag tag2 = mMbox.createTag(NAME_PREFIX + " testAttachment2", null);
conditions.add(new ZAttachmentExistsCondition(true));
actions.add(new ZTagAction(tag1.getName()));
rules.add(new ZFilterRule("testAttachment1", true, false, conditions, actions));
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZAttachmentExistsCondition(false));
actions.add(new ZTagAction(tag2.getName()));
rules.add(new ZFilterRule("testAttachment2", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message with an attachment.
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " testAttachment1";
String msgContent = new MessageBuilder().withSubject(subject).withAttachment("attach this", "attach.txt", "text/plain").create();
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
// Check the tag states.
Set<String> tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tag1.getId()));
// Add a message with no attachment.
subject = NAME_PREFIX + " testAttachment2";
msgContent = new MessageBuilder().withSubject(subject).create();
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
// Check the tag states.
tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tag2.getId()));
}
Aggregations