Search in sources :

Example 1 with ZFilterRule

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

the class TestFilter method testMarkRead.

@Test
public void testMarkRead() throws Exception {
    String folderName = NAME_PREFIX + " testMarkRead";
    // if the subject contains "testMarkRead", file into a folder and mark read
    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, "testMarkRead"));
    actions.add(new ZFileIntoAction(folderName));
    actions.add(new ZMarkAction(MarkOp.READ));
    rules.add(new ZFilterRule("testMarkRead", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    // Deliver message.
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " testMarkRead";
    TestUtil.addMessageLmtp(subject, address, address);
    // Check folder and unread state.
    ZMessage msg = TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
    String flags = msg.getFlags();
    assertTrue("Unexpected flags: " + flags, flags == null || flags.indexOf(ZMessage.Flag.UNREAD.getFlagChar()) < 0);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFilterRule(com.zimbra.client.ZFilterRule) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 2 with ZFilterRule

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

the class TestFilter method testReplyAction.

@Test
public void testReplyAction() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZFilterCondition.ZTrueCondition());
    actions.add(new ZFilterAction.ZReplyAction("Hi ${FROM}, Your message was: '${BODY}'. Thanks!"));
    rules.add(new ZFilterRule("testReplyAction", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testReplyAction";
    String body = "Hi, How r u?";
    String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
    // send msg from user2 to user1
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
    // check msg got filed into user1's mailbox
    TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    // check auto reply from user1 in user2's mailbox
    ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"Re: " + subject + "\"");
    ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
    String bodyContent = mimeStructure.getContent();
    assertTrue("template vars should be replaced", !bodyContent.contains("${FROM}") && !bodyContent.contains("${BODY}"));
    assertTrue(bodyContent.contains(TestUtil.getAddress(REMOTE_USER_NAME)) && bodyContent.contains(body));
    // bug 65369
    assertTrue(!mimeStructure.getContentType().contains("charset") || mimeStructure.getContentType().contains(MimeConstants.P_CHARSET_ASCII));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFilterRule(com.zimbra.client.ZFilterRule) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 3 with ZFilterRule

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

the class TestFilter method testCaseSensitiveComparison.

public void testCaseSensitiveComparison() throws Exception {
    // Create case sensitive header and body filter rules
    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, true, "CHECK THIS"));
    conditions.add(new ZBodyCondition(BodyOp.CONTAINS, true, "CHECK THIS"));
    actions.add(new ZTagAction(mTag1.getName()));
    rules.add(new ZFilterRule("testCaseSensitiveComparison", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    // Deliver message having lower case subject substring and make sure that tag1 was not applied
    String subject = NAME_PREFIX + " testCaseSensitiveComparison1 check this";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("message should not have been tagged", msg.getTagIds() == null || msg.getTagIds().isEmpty());
    // Deliver message having upper case subject substring and make sure that tag1 was applied
    subject = NAME_PREFIX + " testCaseSensitiveComparison2 CHECK THIS";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertNotNull("message should have been tagged", msg.getTagIds());
    Set<String> tagIds = new HashSet<String>();
    tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
    assertTrue("message should have been tagged with tag1", tagIds.contains(mTag1.getId()));
    // Deliver message having lower case body content substring and make sure that tag1 was not applied
    subject = NAME_PREFIX + " testCaseSensitiveComparison3";
    String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi check this").create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("message should not have been tagged", msg.getTagIds() == null || msg.getTagIds().isEmpty());
    // Deliver message having upper case body content substring and make sure that tag1 was applied
    subject = NAME_PREFIX + " testCaseSensitiveComparison4";
    content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi CHECK THIS").create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertNotNull("message should have been tagged", msg.getTagIds());
    tagIds = new HashSet<String>();
    tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
    assertTrue("message should have been tagged with tag1", tagIds.contains(mTag1.getId()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFilterRule(com.zimbra.client.ZFilterRule) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZBodyCondition(com.zimbra.client.ZFilterCondition.ZBodyCondition) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules) HashSet(java.util.HashSet)

Example 4 with ZFilterRule

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

the class TestFilter method testToOrCc.

public void testToOrCc() throws Exception {
    // Create filter rules
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("to,cc", HeaderOp.CONTAINS, "checkthis.com"));
    actions.add(new ZTagAction(mTag1.getName()));
    rules.add(new ZFilterRule("testToOrCc", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    // Deliver message 1 and make sure that tag 1 was applied
    String subject = NAME_PREFIX + " testToOrCc 1";
    String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withCcRecipient("cc@checkthis.com").create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    Set<String> tagIds = new HashSet<String>();
    assertNotNull(msg.getTagIds());
    tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(mTag1.getId()));
    // Deliver message 2 and make sure that tag 1 was applied
    subject = NAME_PREFIX + " testToOrCc 2";
    content = new MessageBuilder().withSubject(subject).withToRecipient("to@checkthis.com").withCcRecipient(USER_NAME).create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    tagIds = new HashSet<String>();
    assertNotNull(msg.getTagIds());
    tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(mTag1.getId()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFilterRule(com.zimbra.client.ZFilterRule) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules) HashSet(java.util.HashSet)

Example 5 with ZFilterRule

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

the class TestFilter method testManyAsterisks.

/**
 * Make sure we disallow more than four asterisks in a :matches condition (bug 35983).
 */
@Test
public void testManyAsterisks() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    ZFilterCondition condition = new ZHeaderCondition("from", HeaderOp.MATCHES, "*****address@yahoo.com");
    ZFilterAction action = new ZKeepAction();
    conditions.add(condition);
    actions.add(action);
    rules.add(new ZFilterRule("test many asterisks", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    try {
        mMbox.saveIncomingFilterRules(zRules);
        fail("Saving filter rules with quotes should not have succeeded");
    } catch (SoapFaultException e) {
        assertTrue("Unexpected exception: " + e, e.getMessage().contains("four asterisks"));
    }
}
Also used : 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) ZKeepAction(com.zimbra.client.ZFilterAction.ZKeepAction) ZFilterRules(com.zimbra.client.ZFilterRules) SoapFaultException(com.zimbra.common.soap.SoapFaultException) 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