Search in sources :

Example 6 with ZMarkAction

use of com.zimbra.client.ZFilterAction.ZMarkAction in project zm-mailbox by Zimbra.

the class TestFilter method testSpecialCharInBody.

/**
     * Tests fix for bug 56019.
     */
@Test
public void testSpecialCharInBody() throws Exception {
    assertTrue("To run this test copy data/unittest/TestFilter-testSpecialCharInBody.msg to /opt/zimbra/unittest", Files.exists(Paths.get("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    conditions.add(new ZBodyCondition(BodyOp.CONTAINS, "André"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testSpecialCharInBody", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and test the flagged state.
    String address = TestUtil.getAddress(USER_NAME);
    // TestFilter-testSpecialCharInBody.msg's body contains base64 encoded content (containing "André")
    String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
    TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testSpecialCharInBody");
    assertTrue("Unexpected message flag state", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZBodyCondition(com.zimbra.client.ZFilterCondition.ZBodyCondition) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) File(java.io.File) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 7 with ZMarkAction

use of com.zimbra.client.ZFilterAction.ZMarkAction 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);
}
Also used : ZDiscardAction(com.zimbra.client.ZFilterAction.ZDiscardAction) 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) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 8 with ZMarkAction

use of com.zimbra.client.ZFilterAction.ZMarkAction in project zm-mailbox by Zimbra.

the class TestFilter method testHeaderFolding.

/**
     * Confirms that the header test works with headers that are folded.
     * See section 2.2.3 of RFC 2822 and bug 14942.
     */
@Test
public void testHeaderFolding() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "a b c", mark as flagged
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a b c"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testHeaderFolding", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and confirm it is flagged
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " a b\r\n c";
    TestUtil.addMessageLmtp(subject, address, address);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"a b c\"");
    assertTrue("Message was not flagged", msg.isFlagged());
}
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) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 9 with ZMarkAction

use of com.zimbra.client.ZFilterAction.ZMarkAction in project zm-mailbox by Zimbra.

the class TestFilter method testAddressTest.

@Test
public void testAddressTest() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    // first use header test for address matching
    conditions.add(new ZFilterCondition.ZHeaderCondition("From", HeaderOp.IS, "john.doe@example.com"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testAddressTest1", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testAddressTest1";
    String mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertFalse("Unexpected message flag state", msg.isFlagged());
    // now use the address test
    conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.all, HeaderOp.IS, false, "john.doe@example.com"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testAddressTest2", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    subject = NAME_PREFIX + " testAddressTest2";
    mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("Unexpected message flag state", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 10 with ZMarkAction

use of com.zimbra.client.ZFilterAction.ZMarkAction in project zm-mailbox by Zimbra.

the class TestFilter method testAddressTestPart.

@Test
public void testAddressTestPart() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    // use address test for address domain match
    conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.domain, HeaderOp.IS, false, "example.com"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testAddressTestPart1", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testAddressTestPart1";
    String mime = new MessageBuilder().withFrom("John Doe <JOHN.DOE@EXAMPLE.COM>").withSubject(subject).create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("Unexpected message flag state", msg.isFlagged());
    // use address test for address local-part match
    conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.localpart, HeaderOp.MATCHES, true, "j*doe"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testAddressTestPart2", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    subject = NAME_PREFIX + " testAddressTestPart2";
    mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("Unexpected message flag state", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Aggregations

ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)11 ArrayList (java.util.ArrayList)11 ZFilterAction (com.zimbra.client.ZFilterAction)10 ZFilterCondition (com.zimbra.client.ZFilterCondition)10 ZFilterRule (com.zimbra.client.ZFilterRule)10 ZFilterRules (com.zimbra.client.ZFilterRules)10 ZMessage (com.zimbra.client.ZMessage)8 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)7 Test (org.junit.Test)7 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)4 ZBodyCondition (com.zimbra.client.ZFilterCondition.ZBodyCondition)4 ZDiscardAction (com.zimbra.client.ZFilterAction.ZDiscardAction)3 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)3 ZKeepAction (com.zimbra.client.ZFilterAction.ZKeepAction)2 ZRedirectAction (com.zimbra.client.ZFilterAction.ZRedirectAction)2 File (java.io.File)2 ZNotifyAction (com.zimbra.client.ZFilterAction.ZNotifyAction)1 ZRFCCompliantNotifyAction (com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)1 ZReplyAction (com.zimbra.client.ZFilterAction.ZReplyAction)1 ZStopAction (com.zimbra.client.ZFilterAction.ZStopAction)1