use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method testKeep.
@Test
public void testKeep() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test keep";
String id = TestUtil.addMessage(mbox, subject);
String query = "in:inbox subject:\"" + subject + "\"";
String[] ruleNames = new String[] { KEEP_RULE_NAME };
// Test keep in inbox by id.
Set<String> affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
// Test keep in inbox by query.
affectedIds = runRules(ruleNames, null, "in:inbox");
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
// Move message to folder1.
ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
mbox.moveMessage(id, folder1.getId());
// Test keep in folder1 by id.
affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(0, affectedIds.size());
query = "in:" + FOLDER1_NAME + " subject:\"" + subject + "\"";
TestUtil.getMessage(mbox, query);
// Test keep in folder1 by query.
affectedIds = runRules(ruleNames, null, "in:" + FOLDER1_NAME);
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
}
use of com.zimbra.client.ZMailbox 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.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method setUp.
@Before
public void setUp() throws Exception {
String prefix = NAME_PREFIX + "-" + testInfo.getMethodName() + "-";
USER_NAME = prefix + "user";
USER_NAME2 = prefix + "user2";
cleanUp();
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(USER_NAME2);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZMailbox mbox2 = TestUtil.getZMailbox(USER_NAME2);
originalRules = mbox.getIncomingFilterRules();
originalBatchSize = TestUtil.getAccountAttr(USER_NAME, Provisioning.A_zimbraFilterBatchSize);
originalSleepInterval = TestUtil.getAccountAttr(USER_NAME, Provisioning.A_zimbraFilterSleepInterval);
saveNewRules();
// Speed up the test.
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraFilterSleepInterval, "0");
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method assertMoved.
private void assertMoved(String sourceFolderName, String destFolderName, String subject) throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<ZMessage> messages = TestUtil.search(mbox, "in:" + sourceFolderName + " subject:\"" + subject + "\"");
Assert.assertEquals(0, messages.size());
messages = TestUtil.search(mbox, "in:" + destFolderName + " subject:\"" + subject + "\"");
Assert.assertEquals(1, messages.size());
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method saveNewRules.
private void saveNewRules() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// if subject contains "tag", tag
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "tag"));
actions.add(new ZTagAction(TAG_NAME));
rules.add(new ZFilterRule(TAG_RULE_NAME, true, false, conditions, actions));
// if subject contains "flag", flag
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "flag"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule(FLAG_RULE_NAME, true, false, conditions, actions));
// if subject contains "mark read", mark read
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "mark read"));
actions.add(new ZMarkAction(MarkOp.READ));
rules.add(new ZFilterRule(MARK_READ_RULE_NAME, true, false, conditions, actions));
// if subject contains "keep", keep
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "keep"));
actions.add(new ZKeepAction());
rules.add(new ZFilterRule(KEEP_RULE_NAME, true, false, conditions, actions));
// if subject contains "folder1", file into folder1
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder1"));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
rules.add(new ZFilterRule(FOLDER1_RULE_NAME, true, false, conditions, actions));
// if the subject contains "folder1 and flag", file into folder1 and flag
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder1 and flag"));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule(FOLDER1_AND_FLAG_RULE_NAME, true, false, conditions, actions));
// if subject contains "folder2", file into folder2
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder2"));
actions.add(new ZFileIntoAction(FOLDER2_PATH));
rules.add(new ZFilterRule(FOLDER2_RULE_NAME, true, false, conditions, actions));
// if subject contains "folder3", file into folder3. This one uses the
// folder name without the leading slash.
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder3"));
actions.add(new ZFileIntoAction(FOLDER3_NAME));
rules.add(new ZFilterRule(FOLDER3_RULE_NAME, true, false, conditions, actions));
// if subject contains "discard", discard
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "discard"));
actions.add(new ZDiscardAction());
rules.add(new ZFilterRule(DISCARD_RULE_NAME, true, false, conditions, actions));
// If subject contains "redirect", redirect to user2. This rule should
// be ignored when applied to existing messages.
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "redirect"));
actions.add(new ZRedirectAction(TestUtil.getAddress(USER_NAME2)));
rules.add(new ZFilterRule(REDIRECT_RULE_NAME, true, false, conditions, actions));
// Save rules
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
mbox.saveIncomingFilterRules(new ZFilterRules(rules));
}
Aggregations