use of com.zimbra.client.ZFilterAction.ZFileIntoAction in project zm-mailbox by Zimbra.
the class TestFilter method testBackslashEscape.
public void testBackslashEscape() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
String folderName = NAME_PREFIX + " testBackslashEscape";
TestUtil.createFolder(mMbox, folderName);
// if subject contains "a \ b", file into folder
ZFilterCondition condition = new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a \\ b");
ZFilterAction action = new ZFileIntoAction(folderName);
conditions.add(condition);
actions.add(action);
rules.add(new ZFilterRule(folderName, true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and confirm it gets filed into the correct folder
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " a \\ b y z";
TestUtil.addMessageLmtp(subject, address, address);
TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
}
use of com.zimbra.client.ZFilterAction.ZFileIntoAction in project zm-mailbox by Zimbra.
the class TestFilter method getTestIncomingRules.
private ZFilterRules getTestIncomingRules() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
// if subject contains "folder1", file into folder1 and tag with tag1
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder1"));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
actions.add(new ZTagAction(TAG1_NAME));
rules.add(new ZFilterRule("testMatchMultipleFilters1", true, false, conditions, actions));
// if from contains "multiplefilters", file into folder 2, tag with tag2 and flag
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("from", HeaderOp.CONTAINS, "multiplefilters"));
actions.add(new ZFileIntoAction(FOLDER2_PATH));
actions.add(new ZTagAction(TAG2_NAME));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testMatchMultipleFilters2", true, false, conditions, actions));
// if subject contains bug5455, flag, file into folder1, tag with tag1, file into folder2
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "bug5455"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
actions.add(new ZTagAction(TAG1_NAME));
actions.add(new ZFileIntoAction(FOLDER2_PATH));
rules.add(new ZFilterRule("testBug5455", true, false, conditions, actions));
// if subject contains "discard", discard the message
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "doDiscard"));
actions.add(new ZDiscardAction());
rules.add(new ZFilterRule("testDiscard", true, false, conditions, actions));
// if subject contains "mountpointRoot", file into the mountpoint root folder
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "mountpointRoot"));
actions.add(new ZFileIntoAction("/" + MOUNTPOINT_FOLDER_NAME));
rules.add(new ZFilterRule("testMountpoint", true, false, conditions, actions));
// if subject contains "mountpointSub", file into the mountpoint subfolder
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "mountpointSub"));
actions.add(new ZFileIntoAction(MOUNTPOINT_SUBFOLDER_PATH));
rules.add(new ZFilterRule("testMountpointSubfolder", true, false, conditions, actions));
return new ZFilterRules(rules);
}
use of com.zimbra.client.ZFilterAction.ZFileIntoAction in project zm-mailbox by Zimbra.
the class TestFilter method getTestOutgoingRules.
private ZFilterRules getTestOutgoingRules() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// if subject contains "outgoing", file into folder1 and tag with tag1
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions;
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "outgoing"));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
actions.add(new ZTagAction(TAG1_NAME));
rules.add(new ZFilterRule("testOutgoingFilters1", true, false, conditions, actions));
return new ZFilterRules(rules);
}
use of com.zimbra.client.ZFilterAction.ZFileIntoAction in project zm-mailbox by Zimbra.
the class TestPop3Import method testFiltering.
/**
* Confirms that messages pulled from a POP3 account are affected by
* mail filtering (bug 13821).
*/
@Test
public void testFiltering() throws Exception {
String folderPath = "/" + NAME_PREFIX + "-testFiltering";
String filteredPath = "/" + NAME_PREFIX + "-testFiltering-filtered";
// Create remote account
prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
// Add message to remote mailbox
ZMailbox remoteMbox = TestUtil.getZMailbox(TEMP_USER_NAME);
TestUtil.addMessage(remoteMbox, NAME_PREFIX + " testFiltering");
// Create local folders
ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
localMbox.getFolderByPath("/Inbox");
ZFolder dsFolder = TestUtil.createFolder(localMbox, folderPath);
TestUtil.createFolder(localMbox, filteredPath);
// Create filter rule that files to the local folder
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, "testFiltering"));
actions.add(new ZFileIntoAction(filteredPath));
rules.add(new ZFilterRule("testFiltering", true, false, conditions, actions));
localMbox.saveIncomingFilterRules(new ZFilterRules(rules));
// Set up data source and run import
ZPop3DataSource ds = getZDataSource();
ds.setUsername(TEMP_USER_NAME);
ds.setFolderId(dsFolder.getId());
ds.setEnabled(true);
localMbox.modifyDataSource(ds);
// Import data and make sure the message was filed to the folder
TestUtil.importDataSource(ds, localMbox, remoteMbox);
List<ZMessage> messages = TestUtil.search(localMbox, "in:" + folderPath);
Assert.assertEquals("Found unexpected messages in " + folderPath, 0, messages.size());
messages = TestUtil.search(localMbox, "in:" + filteredPath);
Assert.assertEquals("Message not found in " + filteredPath, 1, messages.size());
}
use of com.zimbra.client.ZFilterAction.ZFileIntoAction in project zm-mailbox by Zimbra.
the class TestFilter method testQuoteEscape.
public void testQuoteEscape() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
String folderName = NAME_PREFIX + " testQuoteEscape";
TestUtil.createFolder(mMbox, folderName);
// if subject contains "a " b", file into folder
ZFilterCondition condition = new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a \" b");
ZFilterAction action = new ZFileIntoAction(folderName);
conditions.add(condition);
actions.add(action);
rules.add(new ZFilterRule(folderName, true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and confirm it gets filed into the correct folder
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " a \" b y z";
// Search barfs on unmatched quote
String searchSubject = NAME_PREFIX + " a b y z";
TestUtil.addMessageLmtp(subject, address, address);
TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + searchSubject + "\"");
}
Aggregations