Search in sources :

Example 16 with ZHeaderCondition

use of com.zimbra.client.ZFilterCondition.ZHeaderCondition 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);
}
Also used : ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 17 with ZHeaderCondition

use of com.zimbra.client.ZFilterCondition.ZHeaderCondition 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());
}
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) ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 18 with ZHeaderCondition

use of com.zimbra.client.ZFilterCondition.ZHeaderCondition 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 + "\"");
}
Also used : ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 19 with ZHeaderCondition

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

the class TestFilter method testRedirectMailLoop.

/**
     * Confirms that the message gets delivered even when a mail loop occurs.
     */
@Test
public void testRedirectMailLoop() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "testRedirectMailLoop", redirect to user1
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testRedirectMailLoop"));
    actions.add(new ZRedirectAction(TestUtil.getAddress(USER_NAME)));
    rules.add(new ZFilterRule("testRedirectMailLoop", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message.
    String subject = NAME_PREFIX + " testRedirectMailLoop";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    // Confirm that user1 received it.
    ZMessage msg = TestUtil.waitForMessage(mMbox, "subject:\"" + subject + "\"");
    byte[] content = TestUtil.getContent(mMbox, msg.getId()).getBytes();
    MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(content));
    assertEquals(user1.getName(), mimeMsg.getHeader(FilterUtil.HEADER_FORWARDED));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZRedirectAction(com.zimbra.client.ZFilterAction.ZRedirectAction) MimeMessage(com.zimbra.common.mime.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 20 with ZHeaderCondition

use of com.zimbra.client.ZFilterCondition.ZHeaderCondition 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)

Aggregations

ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)20 ZFilterAction (com.zimbra.client.ZFilterAction)19 ZFilterCondition (com.zimbra.client.ZFilterCondition)19 ZFilterRule (com.zimbra.client.ZFilterRule)19 ZFilterRules (com.zimbra.client.ZFilterRules)19 ArrayList (java.util.ArrayList)19 ZMessage (com.zimbra.client.ZMessage)11 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)10 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)8 Test (org.junit.Test)8 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)6 ZMailbox (com.zimbra.client.ZMailbox)5 ZRedirectAction (com.zimbra.client.ZFilterAction.ZRedirectAction)4 ZDiscardAction (com.zimbra.client.ZFilterAction.ZDiscardAction)3 ZKeepAction (com.zimbra.client.ZFilterAction.ZKeepAction)3 ZRFCCompliantNotifyAction (com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)2 ZBodyCondition (com.zimbra.client.ZFilterCondition.ZBodyCondition)2 ZFolder (com.zimbra.client.ZFolder)2 MimeMessage (com.zimbra.common.mime.MimeMessage)2 Config (com.zimbra.cs.account.Config)2