Search in sources :

Example 26 with ZFilterAction

use of com.zimbra.client.ZFilterAction 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 27 with ZFilterAction

use of com.zimbra.client.ZFilterAction 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 28 with ZFilterAction

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

the class TestFilter method testNotifyActionCopyAllOrigHeaders.

@Test
public void testNotifyActionCopyAllOrigHeaders() throws Exception {
    if (mAvailableRFCCompliantNotify) {
        fail("Unable to test because 'zimbraSieveNotifyActionRFCCompliant' is set to TRUE");
        return;
    }
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZFilterCondition.ZTrueCondition());
    // add an action to notify user2
    // copy all headers (From,To,Cc,Subject) from the original message onto the notification message
    actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "*"));
    rules.add(new ZFilterRule("testNotifyActionCopyAllOrigHeaders", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testNotifyActionCopyAllOrigHeaders";
    String body = "Hi, How r u?";
    String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
    // send msg to user1
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
    // check notification msg from user1 in user2's mailbox
    ZMailbox zMailbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    ZMessage zMessage = TestUtil.waitForMessage(zMailbox, "in:inbox subject:\"" + subject + "\"");
    String content = TestUtil.getContent(zMailbox, zMessage.getId());
    assertTrue(content.contains("From: " + REMOTE_USER_NAME));
    assertTrue(content.contains("To: " + USER_NAME));
    assertTrue(content.contains("Cc: " + USER_NAME));
    assertTrue(content.contains("Subject: " + subject));
}
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) ZMailbox(com.zimbra.client.ZMailbox) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 29 with ZFilterAction

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

the class TestFilter method testInvite.

@Test
public void testInvite() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Create tags.
    String prefix = NAME_PREFIX + " testInvite ";
    ZTag tagNoMethod = mbox.createTag(prefix + "no method", null);
    ZTag tagAnyReply = mbox.createTag(prefix + "any reply", null);
    ZTag tagAnyRequest = mbox.createTag(prefix + "any request", null);
    ZTag tagRequestOrCancel = mbox.createTag(prefix + "request or cancel", null);
    ZTag tagReply = mbox.createTag(prefix + "reply", null);
    // Create filter rules that set tags based on conditions.
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    ZFilterCondition condition = new ZInviteCondition(true);
    ZFilterAction action = new ZTagAction(tagNoMethod.getName());
    rules.add(createRule("testInvite - no method", condition, action));
    condition = new ZInviteCondition(true, ZInviteCondition.METHOD_ANYREPLY);
    action = new ZTagAction(tagAnyReply.getName());
    rules.add(createRule("testInvite - any reply", condition, action));
    condition = new ZInviteCondition(true, ZInviteCondition.METHOD_ANYREQUEST);
    action = new ZTagAction(tagAnyRequest.getName());
    rules.add(createRule("testInvite - any request", condition, action));
    condition = new ZInviteCondition(true, Arrays.asList(ZInviteCondition.METHOD_REQUEST, ZInviteCondition.METHOD_CANCEL));
    action = new ZTagAction(tagRequestOrCancel.getName());
    rules.add(createRule("testInvite - request or cancel", condition, action));
    condition = new ZInviteCondition(true, ZInviteCondition.METHOD_REPLY);
    action = new ZTagAction(tagReply.getName());
    rules.add(createRule("testInvite - reply", condition, action));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Send an invite from user2 and check tags.
    ZMailbox organizer = TestUtil.getZMailbox(REMOTE_USER_NAME);
    String subject = NAME_PREFIX + " testInvite request 1";
    Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
    Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
    TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
    // Get message and check tags.
    ZMessage msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    Set<String> tagIds = getTagIds(msg);
    assertTrue(tagIds.contains(tagNoMethod.getId()));
    assertFalse(tagIds.contains(tagAnyReply.getId()));
    assertTrue(tagIds.contains(tagAnyRequest.getId()));
    assertTrue(tagIds.contains(tagRequestOrCancel.getId()));
    assertFalse(tagIds.contains(tagReply.getId()));
    // Now test filtering a reply to an invite.  Send an invite to user2,
    // and have user2 accept the appointment.
    organizer = TestUtil.getZMailbox(USER_NAME);
    mbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    subject = NAME_PREFIX + " testInvite request 2";
    startDate = new Date(startDate.getTime() + Constants.MILLIS_PER_DAY);
    endDate = new Date(endDate.getTime() + Constants.MILLIS_PER_DAY);
    TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
    // Receive the invite and accept the appointment.
    msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    subject = NAME_PREFIX + " testInvite reply";
    TestUtil.sendInviteReply(mbox, msg.getId(), organizer.getName(), subject, ZMailbox.ReplyVerb.ACCEPT);
    msg = TestUtil.waitForMessage(organizer, "in:inbox subject:\"" + subject + "\"");
    // Check tags on the invite reply.
    tagIds = getTagIds(msg);
    assertTrue(tagIds.contains(tagNoMethod.getId()));
    assertTrue(tagIds.contains(tagAnyReply.getId()));
    assertFalse(tagIds.contains(tagAnyRequest.getId()));
    assertFalse(tagIds.contains(tagRequestOrCancel.getId()));
    assertTrue(tagIds.contains(tagReply.getId()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZInviteCondition(com.zimbra.client.ZFilterCondition.ZInviteCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZTag(com.zimbra.client.ZTag) Date(java.util.Date) ZMailbox(com.zimbra.client.ZMailbox) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 30 with ZFilterAction

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

ZFilterAction (com.zimbra.client.ZFilterAction)37 ZFilterCondition (com.zimbra.client.ZFilterCondition)37 ZFilterRule (com.zimbra.client.ZFilterRule)37 ZFilterRules (com.zimbra.client.ZFilterRules)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