Search in sources :

Example 21 with ZFilterRules

use of com.zimbra.client.ZFilterRules 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) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 22 with ZFilterRules

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

the class TestFilter method testAttachment.

@Test
public void testAttachment() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // If attachment exists, set tag1.  If attachment doesn't exist, set tag2.
    ZTag tag1 = mMbox.createTag(NAME_PREFIX + " testAttachment1", null);
    ZTag tag2 = mMbox.createTag(NAME_PREFIX + " testAttachment2", null);
    conditions.add(new ZAttachmentExistsCondition(true));
    actions.add(new ZTagAction(tag1.getName()));
    rules.add(new ZFilterRule("testAttachment1", true, false, conditions, actions));
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZAttachmentExistsCondition(false));
    actions.add(new ZTagAction(tag2.getName()));
    rules.add(new ZFilterRule("testAttachment2", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message with an attachment.
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " testAttachment1";
    String msgContent = new MessageBuilder().withSubject(subject).withAttachment("attach this", "attach.txt", "text/plain").create();
    TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    // Check the tag states.
    Set<String> tagIds = getTagIds(msg);
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(tag1.getId()));
    // Add a message with no attachment.
    subject = NAME_PREFIX + " testAttachment2";
    msgContent = new MessageBuilder().withSubject(subject).create();
    TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    // Check the tag states.
    tagIds = getTagIds(msg);
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(tag2.getId()));
}
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) ZTag(com.zimbra.client.ZTag) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZAttachmentExistsCondition(com.zimbra.client.ZFilterCondition.ZAttachmentExistsCondition) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 23 with ZFilterRules

use of com.zimbra.client.ZFilterRules 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 + "\"");
}
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 24 with ZFilterRules

use of com.zimbra.client.ZFilterRules 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 25 with ZFilterRules

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

the class ZMailboxUtil method doDeleteIncomingFilterRule.

private void doDeleteIncomingFilterRule(String[] args) throws ServiceException {
    ZFilterRules rules = mMbox.getIncomingFilterRules(true);
    doDeleteFilterRule(args, rules);
    mMbox.saveIncomingFilterRules(rules);
}
Also used : ZFilterRules(com.zimbra.client.ZFilterRules)

Aggregations

ZFilterRules (com.zimbra.client.ZFilterRules)48 ZFilterAction (com.zimbra.client.ZFilterAction)37 ZFilterCondition (com.zimbra.client.ZFilterCondition)37 ZFilterRule (com.zimbra.client.ZFilterRule)37 ArrayList (java.util.ArrayList)35 ZMessage (com.zimbra.client.ZMessage)28 Test (org.junit.Test)23 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)20 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)13 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)10 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)9 ZMailbox (com.zimbra.client.ZMailbox)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 ZKeepAction (com.zimbra.client.ZFilterAction.ZKeepAction)2 ZRFCCompliantNotifyAction (com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)2 ZFolder (com.zimbra.client.ZFolder)2