Search in sources :

Example 41 with ZFilterRule

use of com.zimbra.client.ZFilterRule 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 42 with ZFilterRule

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

Example 43 with ZFilterRule

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

the class TestTagFilterRules method testDeleteTag.

/**
     * Verifies that filter rules are disabled when a tag is deleted.
     */
@Test
public void testDeleteTag() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    mbox.deleteTag(mTag.getId());
    // Deliver message that used to match the tag rule and make sure
    // that the message is not tagged.
    String subject = SUBJECT_PREFIX + " testDeleteTag";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    assertEquals(mTag2.getId(), msg.getTagIds());
    // Confirm that the first rule was disabled and the second was not.
    ZFilterRule rule1 = TestUtil.getFilterRule(mbox, TAG_NAME);
    assertFalse(rule1.isActive());
    ZFilterRule rule2 = TestUtil.getFilterRule(mbox, TAG2_NAME);
    assertTrue(rule2.isActive());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZFilterRule(com.zimbra.client.ZFilterRule) Test(org.junit.Test)

Aggregations

ZFilterRule (com.zimbra.client.ZFilterRule)43 ZFilterAction (com.zimbra.client.ZFilterAction)37 ZFilterCondition (com.zimbra.client.ZFilterCondition)37 ZFilterRules (com.zimbra.client.ZFilterRules)37 ArrayList (java.util.ArrayList)35 ZMessage (com.zimbra.client.ZMessage)29 Test (org.junit.Test)26 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)20 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)13 ZMailbox (com.zimbra.client.ZMailbox)12 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)10 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)9 HashSet (java.util.HashSet)5 ZBodyCondition (com.zimbra.client.ZFilterCondition.ZBodyCondition)4 ZTag (com.zimbra.client.ZTag)4 ZDiscardAction (com.zimbra.client.ZFilterAction.ZDiscardAction)3 ZRedirectAction (com.zimbra.client.ZFilterAction.ZRedirectAction)3 ZMountpoint (com.zimbra.client.ZMountpoint)3 ZKeepAction (com.zimbra.client.ZFilterAction.ZKeepAction)2 ZRFCCompliantNotifyAction (com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)2